private RGB GetRGBFromHSLWithChroma(HSL hsl)
        {
            decimal min, max, h;

            h = hsl.H / 360M;

            max = hsl.L < 0.5M ? hsl.L * (1 + hsl.S) : (hsl.L + hsl.S) - (hsl.L * hsl.S);
            min = (hsl.L * 2M) - max;

            RGB rgb = new RGB();

            rgb.R = ComponentFromHue(min, max, h + (1M / 3M));
            rgb.G = ComponentFromHue(min, max, h);
            rgb.B = ComponentFromHue(min, max, h - (1M / 3M));
            return(rgb);
        }
示例#2
0
        public HSL Convert(Color color)
        {
            HSL hsl = new HSL();
            RGB rgb = GetRGBFromColor(color);

            decimal max    = Math.Max(Math.Max(rgb.R, rgb.G), rgb.B);
            decimal min    = Math.Min(Math.Min(rgb.R, rgb.G), rgb.B);
            decimal chroma = max - min;

            hsl.L = GetL(max, min);

            if (chroma != 0)
            {
                hsl.H = GetH(rgb, max, chroma);
                hsl.S = GetS(hsl.L, chroma);
            }
            return(hsl);
        }