예제 #1
0
 public Filter()
 {
     saturationlow = saturationmid = saturationhigh = 1.0;
     contrastlow = contrastmid = contrasthigh = 0.0;
     offsetrange = 1.0;
     offsetlow = offsetmid = offsethigh = new RGB(0.0, 0.0, 0.0);
     gainrange = 2.0;
     temperaturelow = temperaturemid = temperaturehigh = 0.0;
     magentalow = magentamid = magentahigh = 0.0;
     overalllow = overallmid = overallhigh = 0.0;
     gainlow = gainmid = gainhigh = new RGB(0.0, 0.0, 0.0);
     ingammalow = ingammamid = ingammahigh = new RGB(1.0, 1.0, 1.0);
     outgammalow = outgammamid = outgammahigh = new RGB(1.0, 1.0, 1.0);
     
     tgainlow = tgainmid = tgainhigh = new RGB(1.0, 1.0, 1.0);
     gammalow = gammamid = gammahigh = new RGB(1.0, 1.0, 1.0);
 }
예제 #2
0
        private RGB PixelOperation(Color col, double saturation, double contrast, RGB offset, RGB gain, RGB gamma)
        {
            double R = col.R;
            double G = col.G;
            double B = col.B;

            if (saturation < 1.0)
            {
                Color aux = Program.HSL2RGB(col.GetHue() / 360.0, col.GetSaturation() * saturation, col.GetBrightness());

                R = aux.R;
                G = aux.G;
                B = aux.B;
            }

            if (contrast != 0.0)
            {
                double rc;
                if (contrast < -100)
                    rc = 0.0;
                else if (contrast > 100)
                    rc = 2.0;
                else
                    rc = (100.0 + contrast) / 100.0;

                rc *= rc;

                double red = R / 255.0;
                red -= 0.5;
                red *= rc;
                red += 0.5;
                R = red * 255.0;

                double gc;
                if (contrast < -100)
                    gc = 0.0;
                else if (contrast > 100)
                    gc = 2.0;
                else
                    gc = (100.0 + contrast) / 100.0;

                gc *= gc;

                double green = G / 255.0;
                green -= 0.5;
                green *= gc;
                green += 0.5;
                G = green * 255.0;

                double bc;
                if (contrast < -100)
                    bc = 0.0;
                else if (contrast > 100)
                    bc = 2.0;
                else
                    bc = (100.0 + contrast) / 100.0;

                bc *= bc;

                double blue = B / 255.0;
                blue -= 0.5;
                blue *= bc;
                blue += 0.5;
                B = blue * 255.0;
            }

            if (gamma.Red == 1.0)
                R = (R + offset.Red) * gain.Red;
            else
                R = Math.Pow(((R + offset.Red) * gain.Red) / 255.0, gamma.Red) * 255.0;

            if (gamma.Green == 1.0)
                G = (G + offset.Green) * gain.Green;
            else
                G = Math.Pow(((G + offset.Green) * gain.Green) / 255.0, gamma.Green) * 255.0;

            if (gamma.Blue == 1.0)
                B = (B + offset.Blue) * gain.Blue;
            else
                B = Math.Pow(((B + offset.Blue) * gain.Blue) / 255.0, gamma.Blue) * 255.0;

            return new RGB(R, G, B);
        }
예제 #3
0
 public void CalcGamma()
 {
     gammalow = new RGB(ingammalow.Red / outgammalow.Red, ingammalow.Green / outgammalow.Green, ingammalow.Blue / outgammalow.Blue);
     gammamid = new RGB(ingammamid.Red / outgammamid.Red, ingammamid.Green / outgammamid.Green, ingammamid.Blue / outgammamid.Blue);
     gammahigh = new RGB(ingammahigh.Red / outgammahigh.Red, ingammahigh.Green / outgammahigh.Green, ingammahigh.Blue / outgammahigh.Blue);
 }
예제 #4
0
        private RGB PixelOperation(Color col, double saturation, double contrast, RGB offset, RGB gain, RGB gamma)
        {
            double R = col.R;
            double G = col.G;
            double B = col.B;

            if (saturation < 1.0)
            {
                Color aux = Program.HSL2RGB(col.GetHue() / 360.0, col.GetSaturation() * saturation, col.GetBrightness());

                R = aux.R;
                G = aux.G;
                B = aux.B;
            }

            if (contrast != 0.0)
            {
                double rc;
                if (contrast < -100)
                {
                    rc = 0.0;
                }
                else if (contrast > 100)
                {
                    rc = 2.0;
                }
                else
                {
                    rc = (100.0 + contrast) / 100.0;
                }

                rc *= rc;

                double red = R / 255.0;
                red -= 0.5;
                red *= rc;
                red += 0.5;
                R    = red * 255.0;

                double gc;
                if (contrast < -100)
                {
                    gc = 0.0;
                }
                else if (contrast > 100)
                {
                    gc = 2.0;
                }
                else
                {
                    gc = (100.0 + contrast) / 100.0;
                }

                gc *= gc;

                double green = G / 255.0;
                green -= 0.5;
                green *= gc;
                green += 0.5;
                G      = green * 255.0;

                double bc;
                if (contrast < -100)
                {
                    bc = 0.0;
                }
                else if (contrast > 100)
                {
                    bc = 2.0;
                }
                else
                {
                    bc = (100.0 + contrast) / 100.0;
                }

                bc *= bc;

                double blue = B / 255.0;
                blue -= 0.5;
                blue *= bc;
                blue += 0.5;
                B     = blue * 255.0;
            }

            if (gamma.Red == 1.0)
            {
                R = (R + offset.Red) * gain.Red;
            }
            else
            {
                R = Math.Pow(((R + offset.Red) * gain.Red) / 255.0, gamma.Red) * 255.0;
            }

            if (gamma.Green == 1.0)
            {
                G = (G + offset.Green) * gain.Green;
            }
            else
            {
                G = Math.Pow(((G + offset.Green) * gain.Green) / 255.0, gamma.Green) * 255.0;
            }

            if (gamma.Blue == 1.0)
            {
                B = (B + offset.Blue) * gain.Blue;
            }
            else
            {
                B = Math.Pow(((B + offset.Blue) * gain.Blue) / 255.0, gamma.Blue) * 255.0;
            }

            return(new RGB(R, G, B));
        }
예제 #5
0
 public void CalcGamma()
 {
     gammalow  = new RGB(ingammalow.Red / outgammalow.Red, ingammalow.Green / outgammalow.Green, ingammalow.Blue / outgammalow.Blue);
     gammamid  = new RGB(ingammamid.Red / outgammamid.Red, ingammamid.Green / outgammamid.Green, ingammamid.Blue / outgammamid.Blue);
     gammahigh = new RGB(ingammahigh.Red / outgammahigh.Red, ingammahigh.Green / outgammahigh.Green, ingammahigh.Blue / outgammahigh.Blue);
 }
예제 #6
0
        public void Do(Bitmap bitmap)
        {
            try
            {
                BitmapData data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);

                unsafe
                {
                    int  size   = bitmap.Width * bitmap.Height;
                    int *pixels = (int *)data.Scan0;

                    for (int i = 0; i < size; i++)
                    {
                        //System.Windows.Forms.Application.DoEvents();
                        Color  col = Color.FromArgb(pixels[i]);
                        double R   = col.R;
                        double G   = col.G;
                        double B   = col.B;
                        double L   = 0.299 * R + 0.587 * G + 0.114 * B;

                        double fact = L / 255.0;

                        if (fact < 0.5)
                        {
                            RGB Low = PixelOperation(col, saturationlow, contrastlow, offsetlow, tgainlow, gammalow);
                            RGB Mid = PixelOperation(col, saturationmid, contrastmid, offsetmid, tgainmid, gammamid);

                            R = LinearInterpolation(Low.Red, Mid.Red, fact * 2.0);
                            G = LinearInterpolation(Low.Green, Mid.Green, fact * 2.0);
                            B = LinearInterpolation(Low.Blue, Mid.Blue, fact * 2.0);
                        }
                        else
                        {
                            RGB Mid  = PixelOperation(col, saturationmid, contrastmid, offsetmid, tgainmid, gammamid);
                            RGB High = PixelOperation(col, saturationhigh, contrasthigh, offsethigh, tgainhigh, gammahigh);

                            R = LinearInterpolation(Mid.Red, High.Red, (fact - 0.5) * 2.0);
                            G = LinearInterpolation(Mid.Green, High.Green, (fact - 0.5) * 2.0);
                            B = LinearInterpolation(Mid.Blue, High.Blue, (fact - 0.5) * 2.0);
                        }

                        if (R > 255.0)
                        {
                            R = 255.0;
                        }
                        else if (R < 0.0)
                        {
                            R = 0.0;
                        }

                        if (G > 255.0)
                        {
                            G = 255.0;
                        }
                        else if (G < 0.0)
                        {
                            G = 0.0;
                        }

                        if (B > 255.0)
                        {
                            B = 255.0;
                        }
                        else if (B < 0.0)
                        {
                            B = 0.0;
                        }

                        pixels[i] = Color.FromArgb((int)R, (int)G, (int)B).ToArgb();
                    }
                }

                try
                {
                    bitmap.UnlockBits(data);
                }catch { }

                this.Image = new Bitmap(bitmap, new Size(48, 32));
            }
            catch (Exception)
            {
            }
        }