Example #1
0
 protected override Rgb ToRgb()
 {
     var hRad = H * System.Math.PI / 180.0;
     var lab = new Lab
     {
         L = L,
         A = System.Math.Cos(hRad) * C,
         B = System.Math.Sin(hRad) * C
     };
     return lab.ToColorSpace<Rgb>();
 }
Example #2
0
        protected override void FromRgb(Rgb color)
        {
            var lab = new Lab(color);
            var hDeg = System.Math.Atan2(lab.B, lab.A);

            if (hDeg > 0)
            {
                hDeg = hDeg / System.Math.PI * 180.0;
            }
            else
            {
                hDeg = 360.0 - System.Math.Abs(hDeg) / System.Math.PI * 180.0;
            }

            if (hDeg < 0)
                hDeg += 360.0;
            else if (hDeg >= 360)
                hDeg -= 360.0;

            L = lab.L;
            C = System.Math.Sqrt(lab.A * lab.A + lab.B * lab.B);
            H = hDeg;
        }