Example #1
0
        public static HSL HSBToHSL(HSB hsb)
        {
            HSL    hsl = new HSL();
            double ld;

            // Convert B to L
            ld = Math.Exp((hsb.B - 257.7) / 149.9);

            //{ ColorHLSToRGB requires H, L and S to be in 0..1 range. }
            hsl.H = (hsb.H) / 255.0;
            hsl.S = (hsb.S) / 255.0;
            hsl.L = ld;
            return(hsl);
        }
Example #2
0
        public static HSB HSLToHSB(HSL hsl)
        {
            HSB hsb = new HSB();

            hsb.H = (byte)Math.Round(255.0 * hsl.H);
            hsb.S = (byte)Math.Round(255.0 * hsl.S);
            if (hsl.L < 0.1793)
            {
                hsb.B = 0;
            }
            else if (hsl.L > 0.9821)
            {
                hsb.B = 0xff;
            }
            else
            {
                hsb.B = (byte)Math.Round(257.7 + 149.9 * Math.Log(hsl.L));
            }

            return(hsb);
        }
Example #3
0
 public static uint HSBToUInt32(HSB hsb)
 {
     return((uint)(hsb.H | (hsb.S << 8) | (hsb.B << 16)));
 }