public GradientBevelFilter(float distance, float angle, uint[] colors, float[] alphas, byte[] ratios, float blurX, float blurY, float strength, int quality, BitmapFilterType type)
 {
 }
示例#2
0
 public BevelFilter(float distance, float angle, uint highlightColor, float highlightAlpha,
     uint shadowColor, float shadowAlpha, float blurX, float blurY, float strength,
     float quality, BitmapFilterType type)
 {
 }
 public GradientGlowFilter(float distance, float angle, uint[] colors, float[] alphas, byte[] ratios, float blurX, float blurY, float strength, int quality, BitmapFilterType type, bool knockout)
 {
 }
示例#4
0
        //***************************************************************************
        // Static Methods
        //
        private static Bitmap ProcessBitmap(Bitmap b, BitmapFilterType type, params object[] args)
        {
            if (b.PixelFormat != PixelFormat.Format24bppRgb)
            {
                b = b.Clone(new Rectangle(0, 0, b.Width, b.Height), PixelFormat.Format24bppRgb);
            }

            BitmapData bmpData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);

            unsafe
            {
                byte *p = (byte *)(void *)bmpData.Scan0;

                int nWidth  = b.Width * 3;
                int nOffset = bmpData.Stride - nWidth;

                switch (type)
                {
                case BitmapFilterType.Invert:
                    #region Invert Bitmap
                {
                    for (int y = 0; y < b.Height; ++y)
                    {
                        for (int x = 0; x < nWidth; ++x)
                        {
                            p[0] = (byte)(255 - p[0]);
                            ++p;
                        }
                        p += nOffset;
                    }
                    break;
                }

                    #endregion
                case BitmapFilterType.GrayScale:
                    #region GrayScape Bitmap
                {
                    byte blue, green, red;
                    for (int y = 0; y < b.Height; ++y)
                    {
                        for (int x = 0; x < b.Width; ++x)
                        {
                            blue  = p[0];
                            green = p[1];
                            red   = p[2];

                            p[0] = p[1] = p[2] = (byte)(.299 * red + .587 * green + .114 * blue);

                            p += 3;
                        }
                        p += nOffset;
                    }
                    break;
                }

                    #endregion
                case BitmapFilterType.Brightness:
                    #region Adjust Brightness
                {
                    int nBrightness = (int)args[0];
                    int nVal        = 0;
                    for (int y = 0; y < b.Height; ++y)
                    {
                        for (int x = 0; x < nWidth; ++x)
                        {
                            nVal = (int)(p[0] + nBrightness);

                            if (nVal < 0)
                            {
                                nVal = 0;
                            }
                            if (nVal > 255)
                            {
                                nVal = 255;
                            }

                            p[0] = (byte)nVal;
                            ++p;
                        }
                        p += nOffset;
                    }
                    break;
                }

                    #endregion
                case BitmapFilterType.Contrast:
                    #region Adjust Contrast
                {
                    sbyte  nContrast = (sbyte)args[0];
                    double pixel = 0, contrast = (100.0 + nContrast) / 100.0;
                    contrast *= contrast;
                    int red, green, blue;
                    for (int y = 0; y < b.Height; ++y)
                    {
                        for (int x = 0; x < b.Width; ++x)
                        {
                            blue  = p[0];
                            green = p[1];
                            red   = p[2];

                            pixel  = red / 255.0;
                            pixel -= 0.5;
                            pixel *= contrast;
                            pixel += 0.5;
                            pixel *= 255;
                            if (pixel < 0)
                            {
                                pixel = 0;
                            }
                            if (pixel > 255)
                            {
                                pixel = 255;
                            }
                            p[2] = (byte)pixel;

                            pixel  = green / 255.0;
                            pixel -= 0.5;
                            pixel *= contrast;
                            pixel += 0.5;
                            pixel *= 255;
                            if (pixel < 0)
                            {
                                pixel = 0;
                            }
                            if (pixel > 255)
                            {
                                pixel = 255;
                            }
                            p[1] = (byte)pixel;

                            pixel  = blue / 255.0;
                            pixel -= 0.5;
                            pixel *= contrast;
                            pixel += 0.5;
                            pixel *= 255;
                            if (pixel < 0)
                            {
                                pixel = 0;
                            }
                            if (pixel > 255)
                            {
                                pixel = 255;
                            }
                            p[0] = (byte)pixel;

                            p += 3;
                        }
                        p += nOffset;
                    }
                    break;
                }

                    #endregion
                case BitmapFilterType.Gamma:
                    #region Adjust Gamma
                {
                    double
                        red   = (double)args[0],
                        green = (double)args[1],
                        blue  = (double)args[2];

                    byte[] redGamma   = new byte[256];
                    byte[] greenGamma = new byte[256];
                    byte[] blueGamma  = new byte[256];

                    for (int i = 0; i < 256; ++i)
                    {
                        redGamma[i]   = (byte)System.Math.Min(255, (int)((255.0 * System.Math.Pow(i / 255.0, 1.0 / red)) + 0.5));
                        greenGamma[i] = (byte)System.Math.Min(255, (int)((255.0 * System.Math.Pow(i / 255.0, 1.0 / green)) + 0.5));
                        blueGamma[i]  = (byte)System.Math.Min(255, (int)((255.0 * System.Math.Pow(i / 255.0, 1.0 / blue)) + 0.5));
                    }

                    for (int y = 0; y < b.Height; ++y)
                    {
                        for (int x = 0; x < b.Width; ++x)
                        {
                            p[2] = redGamma[p[2]];
                            p[1] = greenGamma[p[1]];
                            p[0] = blueGamma[p[0]];

                            p += 3;
                        }
                        p += nOffset;
                    }
                    break;
                }

                    #endregion
                case BitmapFilterType.Color:
                    #region Adjust Color
                {
                    int
                        red   = (int)args[0],
                        green = (int)args[1],
                        blue  = (int)args[2];
                    int nPixel;

                    for (int y = 0; y < b.Height; ++y)
                    {
                        for (int x = 0; x < b.Width; ++x)
                        {
                            nPixel = p[2] + red;
                            nPixel = System.Math.Max(nPixel, 0);
                            p[2]   = (byte)System.Math.Min(255, nPixel);

                            nPixel = p[1] + green;
                            nPixel = System.Math.Max(nPixel, 0);
                            p[1]   = (byte)System.Math.Min(255, nPixel);

                            nPixel = p[0] + blue;
                            nPixel = System.Math.Max(nPixel, 0);
                            p[0]   = (byte)System.Math.Min(255, nPixel);

                            p += 3;
                        }
                        p += nOffset;
                    }
                    break;
                }
                    #endregion
                }
            }
            b.UnlockBits(bmpData);
            return(b);
        }
示例#5
0
        //***************************************************************************
        // Static Methods
        // 
        private static Bitmap ProcessBitmap(Bitmap b, BitmapFilterType type, params object[] args)
        {
            if (b.PixelFormat != PixelFormat.Format24bppRgb)
                b = b.Clone(new Rectangle(0, 0, b.Width, b.Height), PixelFormat.Format24bppRgb);

            BitmapData bmpData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);

            unsafe
            {
                byte* p = (byte*)(void*)bmpData.Scan0;

                int nWidth = b.Width * 3;
                int nOffset = bmpData.Stride - nWidth;

                switch (type)
                {
                    case BitmapFilterType.Invert:
                        #region Invert Bitmap
                        {
                            for (int y = 0; y < b.Height; ++y)
                            {
                                for (int x = 0; x < nWidth; ++x)
                                {
                                    p[0] = (byte)(255 - p[0]);
                                    ++p;
                                }
                                p += nOffset;
                            }
                            break;
                        }
                        #endregion
                    case BitmapFilterType.GrayScale:
                        #region GrayScape Bitmap
                        {
                            byte blue, green, red;
                            for (int y = 0; y < b.Height; ++y)
                            {
                                for (int x = 0; x < b.Width; ++x)
                                {
                                    blue = p[0];
                                    green = p[1];
                                    red = p[2];

                                    p[0] = p[1] = p[2] = (byte)(.299 * red + .587 * green + .114 * blue);

                                    p += 3;
                                }
                                p += nOffset;
                            }
                            break;
                        }
                        #endregion
                    case BitmapFilterType.Brightness:
                        #region Adjust Brightness
                        {
                            int nBrightness = (int)args[0];
                            int nVal = 0;
                            for (int y = 0; y < b.Height; ++y)
                            {
                                for (int x = 0; x < nWidth; ++x)
                                {
                                    nVal = (int)(p[0] + nBrightness);

                                    if (nVal < 0) nVal = 0;
                                    if (nVal > 255) nVal = 255;

                                    p[0] = (byte)nVal;
                                    ++p;
                                }
                                p += nOffset;
                            }
                            break;
                        }
                        #endregion
                    case BitmapFilterType.Contrast:
                        #region Adjust Contrast
                        {
                            sbyte nContrast = (sbyte)args[0];
                            double pixel = 0, contrast = (100.0 + nContrast) / 100.0;
                            contrast *= contrast;
                            int red, green, blue;
                            for (int y = 0; y < b.Height; ++y)
                            {
                                for (int x = 0; x < b.Width; ++x)
                                {
                                    blue = p[0];
                                    green = p[1];
                                    red = p[2];

                                    pixel = red / 255.0;
                                    pixel -= 0.5;
                                    pixel *= contrast;
                                    pixel += 0.5;
                                    pixel *= 255;
                                    if (pixel < 0) pixel = 0;
                                    if (pixel > 255) pixel = 255;
                                    p[2] = (byte)pixel;

                                    pixel = green / 255.0;
                                    pixel -= 0.5;
                                    pixel *= contrast;
                                    pixel += 0.5;
                                    pixel *= 255;
                                    if (pixel < 0) pixel = 0;
                                    if (pixel > 255) pixel = 255;
                                    p[1] = (byte)pixel;

                                    pixel = blue / 255.0;
                                    pixel -= 0.5;
                                    pixel *= contrast;
                                    pixel += 0.5;
                                    pixel *= 255;
                                    if (pixel < 0) pixel = 0;
                                    if (pixel > 255) pixel = 255;
                                    p[0] = (byte)pixel;

                                    p += 3;
                                }
                                p += nOffset;
                            }
                            break;
                        }
                        #endregion
                    case BitmapFilterType.Gamma:
                        #region Adjust Gamma
                        {
                            double
                                red = (double)args[0],
                                green = (double)args[1],
                                blue = (double)args[2];

                            byte[] redGamma = new byte[256];
                            byte[] greenGamma = new byte[256];
                            byte[] blueGamma = new byte[256];

                            for (int i = 0; i < 256; ++i)
                            {
                                redGamma[i] = (byte)System.Math.Min(255, (int)((255.0 * System.Math.Pow(i / 255.0, 1.0 / red)) + 0.5));
                                greenGamma[i] = (byte)System.Math.Min(255, (int)((255.0 * System.Math.Pow(i / 255.0, 1.0 / green)) + 0.5));
                                blueGamma[i] = (byte)System.Math.Min(255, (int)((255.0 * System.Math.Pow(i / 255.0, 1.0 / blue)) + 0.5));
                            }

                            for (int y = 0; y < b.Height; ++y)
                            {
                                for (int x = 0; x < b.Width; ++x)
                                {
                                    p[2] = redGamma[p[2]];
                                    p[1] = greenGamma[p[1]];
                                    p[0] = blueGamma[p[0]];

                                    p += 3;
                                }
                                p += nOffset;
                            }
                            break;
                        }
                        #endregion
                    case BitmapFilterType.Color:
                        #region Adjust Color
                        {
                            int
                                red = (int)args[0],
                                green = (int)args[1],
                                blue = (int)args[2];
                            int nPixel;

                            for (int y = 0; y < b.Height; ++y)
                            {
                                for (int x = 0; x < b.Width; ++x)
                                {
                                    nPixel = p[2] + red;
                                    nPixel = System.Math.Max(nPixel, 0);
                                    p[2] = (byte)System.Math.Min(255, nPixel);

                                    nPixel = p[1] + green;
                                    nPixel = System.Math.Max(nPixel, 0);
                                    p[1] = (byte)System.Math.Min(255, nPixel);

                                    nPixel = p[0] + blue;
                                    nPixel = System.Math.Max(nPixel, 0);
                                    p[0] = (byte)System.Math.Min(255, nPixel);

                                    p += 3;
                                }
                                p += nOffset;
                            }
                            break;
                        }
                        #endregion
                }
            }
            b.UnlockBits(bmpData);
            return b;
        }