예제 #1
0
        public IMagickImage Execute(IMagickImage image, ValueItemCollection values)
        {
            Variables = values;
            if (Normalize)
            {
                image.Normalize();
            }
            if (AutoGamma)
            {
                image.AutoGamma();
            }

            if (Brightness != 0 || ContrastValue != 0)
            {
                image.BrightnessContrast(new Percentage(Brightness), new Percentage(ContrastValue));
            }
            if (Saturation != 0 || Hue != 0)
            {
                image.Modulate(new Percentage(100), new Percentage(Saturation + 100), new Percentage(Hue + 100));
            }
            if (AutoLevel)
            {
                image.AutoLevel(Channels.All);
            }
            else
            {
                if (BlackPoint != 0 || WhitePoint != 100 || MidPoint != 0)
                {
                    var midpoint = 1.0;
                    if (MidPoint < 0)
                    {
                        midpoint = -MidPoint / 10.0;
                        midpoint++;
                    }
                    if (MidPoint > 0)
                    {
                        midpoint = (100 - MidPoint) / 100.0;
                    }
                    image.Level(new Percentage(BlackPoint), new Percentage(WhitePoint), midpoint);
                }
            }
            return(image);
        }