Exemplo n.º 1
0
        internal static RGB HslToRgb(HSL hsl)
        {
            double r, g, b;
            double lit = hsl.L / 100.0;

            if (hsl.S == 0)
            {
                r = g = b = lit;
            }
            else
            {
                double sat = hsl.S / 100.0;

                double d1 = hsl.H / 60.0;
                int    d2 = hsl.H / 60;                 // NOTE: Do not allow a hue of 360.
                double d  = d1 - d2;

                switch (d2)
                {
                case 0:
                    r = lit;
                    g = lit * (1 - sat * (1 - d));
                    b = lit * (1 - sat);
                    break;

                case 1:
                    r = lit * (1 - sat * d);
                    g = lit;
                    b = lit * (1 - sat);
                    break;

                case 2:
                    r = lit * (1 - sat);
                    g = lit;
                    b = lit * (1 - sat * (1 - d));
                    break;

                case 3:
                    r = lit * (1 - sat);
                    g = lit * (1 - sat * d);
                    b = lit;
                    break;

                case 4:
                    r = lit * (1 - sat * (1 - d));
                    g = lit * (1 - sat);
                    b = lit;
                    break;

                case 5:
                    r = lit;
                    g = lit * (1 - sat);
                    b = lit * (1 - sat * d);
                    break;

                default:
                    r = g = b = 0;
                    break;
                }
            }

            return(new RGB((int)Math.Round(r * 255, MidpointRounding.AwayFromZero),
                           (int)Math.Round(g * 255, MidpointRounding.AwayFromZero),
                           (int)Math.Round(b * 255, MidpointRounding.AwayFromZero)));
        }
Exemplo n.º 2
0
 internal ColorEventArgs(Color col, RGB rgb = null, HSL hsl = null)
 {
     Col = col;
     RGB = rgb;
     HSL = hsl;
 }
Exemplo n.º 3
0
 internal static Color HslToColor(HSL hsl)
 {
     return(RgbToCol(HslToRgb(hsl)));
 }