public static void Noise(FastBitmap bmp, Rectangle rect,
                                 FastColour col, int variation)
        {
            int x, y, width, height;

            if (!Drawer2DExt.ClampCoords(bmp, rect, out x, out y,
                                         out width, out height))
            {
                return;
            }

            const int alpha = 255 << 24;

            for (int yy = 0; yy < height; yy++)
            {
                int *row = bmp.GetRowPtr(y + yy);
                for (int xx = 0; xx < width; xx++)
                {
                    int n = (x + xx) + (y + yy) * 57;
                    n = (n << 13) ^ n;
                    float noise = 1f - ((n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824f;

                    int r = col.R + (int)(noise * variation);
                    r = r < 0 ? 0 : (r > 255 ? 255 : r);
                    int g = col.G + (int)(noise * variation);
                    g = g < 0 ? 0 : (g > 255 ? 255 : g);
                    int b = col.B + (int)(noise * variation);
                    b           = b < 0 ? 0 : (b > 255 ? 255 : b);
                    row[x + xx] = alpha | (r << 16) | (g << 8) | b;
                }
            }
        }
        public static void Vertical(FastBitmap bmp, Rectangle rect,
                                    FastColour a, FastColour b)
        {
            int x, y, width, height;

            if (!Drawer2DExt.ClampCoords(bmp, rect, out x, out y,
                                         out width, out height))
            {
                return;
            }
            FastColour c = a;

            for (int yy = 0; yy < height; yy++)
            {
                int * row = bmp.GetRowPtr(y + yy);
                float t   = (float)yy / (height - 1);               // so last row has b as its colour

                c.R = (byte)Utils.Lerp(a.R, b.R, t);
                c.G = (byte)Utils.Lerp(a.G, b.G, t);
                c.B = (byte)Utils.Lerp(a.B, b.B, t);
                int pixel = c.ToArgb();

                for (int xx = 0; xx < width; xx++)
                {
                    row[x + xx] = pixel;
                }
            }
        }
        public static void Blend(FastBitmap bmp, Rectangle rect,
                                 FastColour col, int blend)
        {
            int x, y, width, height;

            if (!Drawer2DExt.ClampCoords(bmp, rect, out x, out y,
                                         out width, out height))
            {
                return;
            }

            // Pre compute the alpha blended source colour
            col.R = (byte)(col.R * blend / 255);
            col.G = (byte)(col.G * blend / 255);
            col.B = (byte)(col.B * blend / 255);
            blend = 255 - blend;             // inverse for existing pixels
            int t = 0;

            for (int yy = 0; yy < height; yy++)
            {
                int *row = bmp.GetRowPtr(y + yy);
                for (int xx = 0; xx < width; xx++)
                {
                    int cur = row[x + xx], pixel = 0;

                    // Blend B
                    t      = col.B + ((cur & 0xFF) * blend) / 255;
                    t      = t < 0 ? 0 : t; t = t > 255 ? 255 : t;
                    pixel |= t;
                    // Blend G
                    t      = col.G + (((cur >> 8) & 0xFF) * blend) / 255;
                    t      = t < 0 ? 0 : t; t = t > 255 ? 255 : t;
                    pixel |= (t << 8);
                    // Blend R
                    t      = col.R + (((cur >> 16) & 0xFF) * blend) / 255;
                    t      = t < 0 ? 0 : t; t = t > 255 ? 255 : t;
                    pixel |= (t << 16);

                    // Output pixel
                    const int alphaMask = 255 << 24;
                    pixel      |= alphaMask;
                    row[x + xx] = pixel;
                }
            }
        }
Esempio n. 4
0
        public static void Draw(FastBitmap src, FastBitmap dst, Rectangle dstRect)
        {
            int x, y, width, height;

            if (!Drawer2DExt.ClampCoords(dst, dstRect, out x, out y, out width, out height))
            {
                return;
            }

            for (int yy = 0; yy < height; yy++)
            {
                int *srcRow = src.GetRowPtr(yy);
                int *dstRow = dst.GetRowPtr(y + yy);

                for (int xx = 0; xx < width; xx++)
                {
                    dstRow[x + xx] = srcRow[xx];
                }
            }
        }
Esempio n. 5
0
        public static void DrawTiled(FastBitmap src, FastBitmap dst,
                                     Rectangle srcRect, Rectangle dstRect)
        {
            int srcX = srcRect.X, srcWidth = srcRect.Width, srcHeight = srcRect.Height;
            int x, y, width, height;

            if (!Drawer2DExt.ClampCoords(dst, dstRect, out x, out y, out width, out height))
            {
                return;
            }

            for (int yy = 0; yy < height; yy++)
            {
                // srcY is always 0 so we don't need to add
                int *srcRow = src.GetRowPtr(((yy + y) % srcHeight));
                int *dstRow = dst.GetRowPtr(y + yy);

                for (int xx = 0; xx < width; xx++)
                {
                    dstRow[x + xx] = srcRow[srcX + ((xx + x) % srcWidth)];
                }
            }
        }