public override Color BlendColor(Color l, Color r)
        {
            bool ctrlIng     = (Control.ModifierKeys & Keys.Shift) != 0;
            bool switchTools = (!Editor.MainForm.DarkenLightenOptions.Inverted && ctrlIng) ||
                               (Editor.MainForm.DarkenLightenOptions.Inverted && !ctrlIng);
            HSL   hsl = ColorSpaceHelper.RGBtoHSL(r);
            float mod = l.A / 255.0f;

            if (switchTools)
            {
                hsl.Luminance -= (GlobalSettings.DarkenLightenExposure * mod) / 5.0f;
            }
            else
            {
                hsl.Luminance += (GlobalSettings.DarkenLightenExposure * mod) / 5.0f;
            }

            if (hsl.Luminance < 0)
            {
                hsl.Luminance = 0;
            }
            if (hsl.Luminance > 1)
            {
                hsl.Luminance = 1;
            }

            return(Color.FromArgb(r.A, ColorSpaceHelper.HSLtoColor(hsl)));
        }
Exemple #2
0
        public static Bitmap GenerateColorSquare(int width, int height)
        {
            var colorSquare = new Bitmap(width, height);
            // START HUE DRAW
            Graphics g = Graphics.FromImage(colorSquare);

            //Set the hue shades with the correct saturation and luminance
            System.Drawing.Color[] theColors =
            {
                ColorSpaceHelper.HSLtoColor(new HSL(0,   1, 0.5f)),
                ColorSpaceHelper.HSLtoColor(new HSL(60,  1, 0.5f)),
                ColorSpaceHelper.HSLtoColor(new HSL(120, 1, 0.5f)),
                ColorSpaceHelper.HSLtoColor(new HSL(180, 1, 0.5f)),
                ColorSpaceHelper.HSLtoColor(new HSL(240, 1, 0.5f)),
                ColorSpaceHelper.HSLtoColor(new HSL(300, 1, 0.5f)),
                ColorSpaceHelper.HSLtoColor(new HSL(360, 1, 0.5f))
            };
            //Calculate positions
            float percent = 1.0f / 6;

            float[] thePositions = { 0.0f, percent, percent * 2, percent * 3, percent * 4, percent * 5, 1.0f };
            //Set blend
            var theBlend = new ColorBlend();

            theBlend.Colors    = theColors;
            theBlend.Positions = thePositions;
            //Get rectangle
            var colorRect = new Rectangle(0, 0, width, height);
            //Make the linear brush and assign the custom blend to it
            var theBrush = new LinearGradientBrush(colorRect,
                                                   System.Drawing.Color.Red,
                                                   System.Drawing.Color.Red, 0, false);

            theBrush.InterpolationColors = theBlend;
            //Draw rectangle
            g.FillRectangle(theBrush, colorRect);
            //END HUE
            //START SATURATION
            //--- 0% sat 50% lum = 128 r, g and b
            System.Drawing.Color halfSatColor        = System.Drawing.Color.FromArgb(128, 128, 128);
            System.Drawing.Color halfSatColorNoAlpha = System.Drawing.Color.FromArgb(0, 128, 128, 128);

            g.FillRectangle(new LinearGradientBrush(colorRect, halfSatColorNoAlpha, halfSatColor, 90, false), colorRect);
            //END SATURATION

            return(colorSquare);
        }