Beispiel #1
0
        internal static void ToColorSpace(IRgb color, ILch item)
        {
            var lab = color.To <Lab>();
            var h   = Math.Atan2(lab.B, lab.A);

            // convert from radians to degrees
            if (h > 0)
            {
                h = (h / Math.PI) * 180.0;
            }
            else
            {
                h = 360 - (Math.Abs(h) / Math.PI) * 180.0;
            }

            if (h < 0)
            {
                h += 360.0;
            }
            else if (h >= 360)
            {
                h -= 360.0;
            }

            item.L = lab.L;
            item.C = Math.Sqrt(lab.A * lab.A + lab.B * lab.B);
            item.H = h;
        }
Beispiel #2
0
        internal static void ToColorSpace(IRgb color, ILch item)
        {
            var lab = color.To<Lab>();
            var h = Math.Atan2(lab.B, lab.A);

            // convert from radians to degrees
            if (h > 0)
            {
                h = (h / Math.PI) * 180.0;
            }
            else
            {
                h = 360 - (Math.Abs(h) / Math.PI) * 180.0;
            }

            if (h < 0)
            {
                h += 360.0;
            }
            else if (h >= 360)
            {
                h -= 360.0;
            }

            item.L = lab.L;
            item.C = Math.Sqrt(lab.A * lab.A + lab.B * lab.B);
            item.H = h;
        }
        protected static void ExpectedValuesForKnownColor(IColorSpace knownColor, ILch expectedColor)
        {
            var target = knownColor.To <Lch>();

            Assert.IsTrue(CloseEnough(expectedColor.L, target.L), "(L)" + expectedColor.L + " != " + target.L);
            Assert.IsTrue(CloseEnough(expectedColor.C, target.C), "(C)" + expectedColor.C + " != " + target.C);
            Assert.IsTrue(CloseEnough(expectedColor.H, target.H), "(H)" + expectedColor.H + " != " + target.H);
        }
Beispiel #4
0
        protected static void ExpectedValuesForKnownColor(IColorSpace knownColor, ILch expectedColor)
        {
            var target = knownColor.To<Lch>();

            Assert.IsTrue(CloseEnough(expectedColor.L,target.L),"(L)" + expectedColor.L + " != " + target.L);
            Assert.IsTrue(CloseEnough(expectedColor.C,target.C),"(C)" + expectedColor.C + " != " + target.C);
            Assert.IsTrue(CloseEnough(expectedColor.H,target.H),"(H)" + expectedColor.H + " != " + target.H);
        }
        protected static void ExpectedValuesForKnownColor(IColorSpace knownColor, ILch expectedColor)
        {
            var target = knownColor.To <Lch>();

            Assert.AreEqual(expectedColor.L, target.L, 0.5, "(L)" + expectedColor.L + " != " + target.L);
            Assert.AreEqual(expectedColor.C, target.C, 0.5, "(C)" + expectedColor.C + " != " + target.C);
            Assert.AreEqual(expectedColor.H, target.H, 1.8, "(H)" + expectedColor.H + " != " + target.H);
        }
Beispiel #6
0
 internal static IRgb ToColor(ILch item)
 {
     var hRadians = item.H * Math.PI / 180.0;
     var lab = new Lab
         {
             L = item.L,
             A = Math.Cos(hRadians) * item.C,
             B = Math.Sin(hRadians) * item.C
         };
     return lab.To<Rgb>();
 }
Beispiel #7
0
        internal static IRgb ToColor(ILch item)
        {
            var hRadians = item.H * Math.PI / 180.0;
            var lab      = new Lab
            {
                L = item.L,
                A = Math.Cos(hRadians) * item.C,
                B = Math.Sin(hRadians) * item.C
            };

            return(lab.To <Rgb>());
        }
Beispiel #8
0
        internal static IRgb ToColor(ILch item)
        {
            var hRadians = MathUtils.DegToRad(item.H);
            var lab      = new Lab
            {
                L = item.L,
                A = Math.Cos(hRadians) * item.C,
                B = Math.Sin(hRadians) * item.C
            };

            return(lab.To <Rgb>());
        }
Beispiel #9
0
        internal static void ToColorSpace(IRgb color, ILch item)
        {
            var lab = color.To <Lab>();
            var h   = MathUtils.RadToDeg(Math.Atan2(lab.B, lab.A));

            if (h < 0)
            {
                h += 360.0;
            }
            else if (h >= 360)
            {
                h -= 360.0;
            }

            item.L = lab.L;
            item.C = Math.Sqrt(lab.A * lab.A + lab.B * lab.B);
            item.H = h;
        }
Beispiel #10
0
        // http://www.brucelindbloom.com/index.html?Eqn_Lab_to_LCH.html
        // http://www.easyrgb.com/index.php?X=MATH&H=09#text9
        // http://www.colourphil.co.uk/lab_lch_colour_space.html

        internal static void ToColorSpace(IRgb color, ILch item)
        {
            var lab = color.To <Lab>();
            var h   = Math.Atan2(lab.B, lab.A);

            // convert from radians to degrees
            if (h > 0)
            {
                h = (h / Math.PI) * 180;
            }
            else
            {
                h = 360 - (Math.Abs(h) / Math.PI) * 180;
            }

            item.L = lab.L;
            item.C = Math.Sqrt(Math.Pow(lab.A, 2) + Math.Pow(lab.B, 2));
            item.H = h % 360;
        }
Beispiel #11
0
        // http://www.brucelindbloom.com/index.html?Eqn_Lab_to_LCH.html
        // http://www.easyrgb.com/index.php?X=MATH&H=09#text9
        // http://www.colourphil.co.uk/lab_lch_colour_space.html
        internal static void ToColorSpace(IRgb color, ILch item)
        {
            var lab = color.To<Lab>();
            var h = Math.Atan2(lab.B, lab.A);

            // convert from radians to degrees
            if (h > 0)
            {
                h = (h/Math.PI)*180;
            }
            else
            {
                h = 360 - (Math.Abs(h)/Math.PI)*180;
            }

            item.L = lab.L;
            item.C = Math.Sqrt(Math.Pow(lab.A,2) + Math.Pow(lab.B,2));
            item.H = h % 360;
        }
Beispiel #12
0
 public CmyColor(ILch lch)
 {
     Initialize(lch.ToRgb());
 }
Beispiel #13
0
 public LchColor(ILch lch)
 {
     Ordinals = lch.Ordinals;
 }
Beispiel #14
0
 public HunterLabColor(ILch lch)
 {
     Initialize(lch.ToRgb());
 }