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

ColorAccent() public method

Color accent filtration
public ColorAccent ( Bitmap OriginalImage, Double h, Double range ) : Bitmap
OriginalImage System.Drawing.Bitmap Original ARGB image
h Double Hue of accented color
range Double Range of acceptance
return System.Drawing.Bitmap
        public Bitmap ColorAccent(Bitmap OriginalImage, Double h, Double range)
        {
            FastPixel fpOriginal = new FastPixel(OriginalImage);
            Bitmap OutputImage = new System.Drawing.Bitmap(fpOriginal.Width, fpOriginal.Height);
            FastPixel fpOutput = new FastPixel(OutputImage);

            Double h1 = (h - range / 2 + 360) % 360;
            Double h2 = (h + range / 2 + 360) % 360;

            for (int x = 0; x < fpOriginal.Width; x++)
            {
                for (int y = 0; y < fpOriginal.Height; y++)
                {
                    Color pixel = fpOriginal.GetPixel(x, y);
                    Double[] hsv = this.rgb2hsv(pixel);
                    int red = 0, green = 0, blue = 0;

                    //if (hsv[0]

                    if (h1 <= h2)
                    {
                        if (hsv[0] <= h2 && hsv[0] >= h1)
                        {
                            red = pixel.R;
                            green = pixel.G;
                            blue = pixel.B;
                        }
                        else
                        {
                            int gs = (int)((pixel.R * 0.3) + (pixel.G * 0.59) + (pixel.B * 0.11));
                            red = gs;
                            green = gs;
                            blue = gs;
                        }
                    }
                    else
                    {
                        if (hsv[0] <= h2 || hsv[0] >= h1)
                        {
                            red = pixel.R;
                            green = pixel.G;
                            blue = pixel.B;
                        }
                        else
                        {
                            int gs = (int)((pixel.R * 0.3) + (pixel.G * 0.59) + (pixel.B * 0.11));
                            red = gs;
                            green = gs;
                            blue = gs;
                        }
                    }

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

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

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

                    Color newColor = Color.FromArgb(255, red, green, blue); ;

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

            fpOriginal.Unlock(false);
            fpOutput.Unlock(true);
            return OutputImage;
        }