private AdvancedAdjustments()
 {
     saturationlow = saturationmid = saturationhigh = 1.0;
     contrastlow = contrastmid = contrasthigh = 0.0;
     offsetrange = 1.0;
     offsetlow = offsetmid = offsethigh = new DoubleRGB(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 DoubleRGB(0.0, 0.0, 0.0);
     ingammalow = ingammamid = ingammahigh = new DoubleRGB(1.0, 1.0, 1.0);
     outgammalow = outgammamid = outgammahigh = new DoubleRGB(1.0, 1.0, 1.0);
     
     tgainlow = tgainmid = tgainhigh = new DoubleRGB(1.0, 1.0, 1.0);
     gammalow = gammamid = gammahigh = new DoubleRGB(1.0, 1.0, 1.0);
 }
示例#2
0
        private AdvancedAdjustments()
        {
            saturationlow  = saturationmid = saturationhigh = 1.0;
            contrastlow    = contrastmid = contrasthigh = 0.0;
            offsetrange    = 1.0;
            offsetlow      = offsetmid = offsethigh = new DoubleRGB(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 DoubleRGB(0.0, 0.0, 0.0);
            ingammalow     = ingammamid = ingammahigh = new DoubleRGB(1.0, 1.0, 1.0);
            outgammalow    = outgammamid = outgammahigh = new DoubleRGB(1.0, 1.0, 1.0);

            tgainlow = tgainmid = tgainhigh = new DoubleRGB(1.0, 1.0, 1.0);
            gammalow = gammamid = gammahigh = new DoubleRGB(1.0, 1.0, 1.0);
        }
        private DoubleRGB PixelOperation(DoubleRGB col, double saturation, double contrast, DoubleRGB offset, DoubleRGB gain, DoubleRGB gamma)
        {
            double R = col.Red;
            double G = col.Green;
            double B = col.Blue;

            if (saturation < 1.0)
            {
                double hue, sat, lum;
                
                Utility.RGB2HSL((byte)R, (byte)G, (byte)B, out hue, out sat, out lum);

                Color aux = Utility.HSL2RGB(hue / 360.0, sat * saturation, lum);

                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;

            DoubleRGB retval;
            retval.Red = R;
            retval.Green = G;
            retval.Blue = B;

            return retval;
        }
 public void CalcGamma()
 {
     gammalow = new DoubleRGB(ingammalow.Red / outgammalow.Red, ingammalow.Green / outgammalow.Green, ingammalow.Blue / outgammalow.Blue);
     gammamid = new DoubleRGB(ingammamid.Red / outgammamid.Red, ingammamid.Green / outgammamid.Green, ingammamid.Blue / outgammamid.Blue);
     gammahigh = new DoubleRGB(ingammahigh.Red / outgammahigh.Red, ingammahigh.Green / outgammahigh.Green, ingammahigh.Blue / outgammahigh.Blue);
 }
示例#5
0
        private DoubleRGB PixelOperation(DoubleRGB col, double saturation, double contrast, DoubleRGB offset, DoubleRGB gain, DoubleRGB gamma)
        {
            double R = col.Red;
            double G = col.Green;
            double B = col.Blue;

            if (saturation < 1.0)
            {
                double hue, sat, lum;

                Utility.RGB2HSL((byte)R, (byte)G, (byte)B, out hue, out sat, out lum);

                Color aux = Utility.HSL2RGB(hue / 360.0, sat * saturation, lum);

                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;
            }

            DoubleRGB retval;

            retval.Red   = R;
            retval.Green = G;
            retval.Blue  = B;

            return(retval);
        }
示例#6
0
 public void CalcGamma()
 {
     gammalow  = new DoubleRGB(ingammalow.Red / outgammalow.Red, ingammalow.Green / outgammalow.Green, ingammalow.Blue / outgammalow.Blue);
     gammamid  = new DoubleRGB(ingammamid.Red / outgammamid.Red, ingammamid.Green / outgammamid.Green, ingammamid.Blue / outgammamid.Blue);
     gammahigh = new DoubleRGB(ingammahigh.Red / outgammahigh.Red, ingammahigh.Green / outgammahigh.Green, ingammahigh.Blue / outgammahigh.Blue);
 }
示例#7
0
        public BitmapSource Do(BitmapSource bitmap)
        {
            try
            {
                byte[] bytes = new byte[bitmap.PixelWidth * bitmap.PixelHeight * 4];

                bitmap.CopyPixels(bytes, bitmap.PixelWidth * 4, 0);
                int size = bitmap.PixelWidth * bitmap.PixelHeight * 4;

                for (int i = 0; i < size; i += 4)
                {
                    double R = bytes[i + 2];
                    double G = bytes[i + 1];
                    double B = bytes[i];
                    double L = 0.299 * R + 0.587 * G + 0.114 * B;

                    DoubleRGB col;
                    col.Red   = R;
                    col.Green = G;
                    col.Blue  = B;

                    double fact = L / 255.0;

                    if (fact < 0.5)
                    {
                        DoubleRGB Low = PixelOperation(col, saturationlow, contrastlow, offsetlow, tgainlow, gammalow);
                        DoubleRGB 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
                    {
                        DoubleRGB Mid  = PixelOperation(col, saturationmid, contrastmid, offsetmid, tgainmid, gammamid);
                        DoubleRGB 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;
                    }

                    bytes[i]     = (byte)B;
                    bytes[i + 1] = (byte)G;
                    bytes[i + 2] = (byte)R;
                }

                bitmap = BitmapSource.Create(bitmap.PixelWidth, bitmap.PixelHeight, 96, 96,
                                             PixelFormats.Bgra32, null, bytes, bitmap.PixelWidth * 4);
            }
            catch (Exception)
            {
            }

            return(bitmap);
        }