LitDev.Engines.FIP.GammaCorrectionGS C# (CSharp) Method

GammaCorrectionGS() public method

Gamma correction
public GammaCorrectionGS ( Bitmap OriginalImage, Double Gamma ) : Bitmap
OriginalImage System.Drawing.Bitmap Original ARGB image
Gamma Double Gamma correction coefficient
return System.Drawing.Bitmap
        public Bitmap GammaCorrectionGS(Bitmap OriginalImage, Double Gamma)
        {
            Bitmap OutputImage = new System.Drawing.Bitmap(OriginalImage.Width, OriginalImage.Height);

            for (int x = 0; x < OriginalImage.Width; x++)
            {
                for (int y = 0; y < OriginalImage.Height; y++)
                {

                    Color pixel = OriginalImage.GetPixel(x, y);
                    int gs = (int)((pixel.R * 0.3) + (pixel.G * 0.59) + (pixel.B * 0.11));

                    gs = (int)(255 * Math.Pow(Convert.ToDouble(gs) / 255, Gamma));

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

                    Color newColor = Color.FromArgb(255, gs, gs, gs); ;

                    OutputImage.SetPixel(x, y, newColor);
                }
            }

            return OutputImage;
        }