Example #1
0
        public static Color ShiftLightness(this Color color, int amount = 1)
        {
            var lab     = color.ToLab();
            var shifted = new Lab(lab.L - LabConstants.Kn * amount, lab.A, lab.B);

            return(shifted.ToColor());
        }
Example #2
0
        /// <summary>
        /// Calculates the CIE76 distance between two colors.
        /// </summary>
        /// <param name="color"></param>
        /// <param name="other"></param>
        /// <returns></returns>
        public static double Difference(this Color color, Color other)
        {
            Lab lab1 = color.ToLab();
            Lab lab2 = color.ToLab();

            return(Math.Sqrt(Math.Pow(lab2.L - lab1.L, 2) +
                             Math.Pow(lab2.A - lab1.A, 2) +
                             Math.Pow(lab2.B - lab1.B, 2)));
        }
Example #3
0
        public static Xyz ToXyz(this Lab lab)
        {
            double lab_xyz(double d)
            {
                if (d > LabConstants.eCubedRoot)
                {
                    return(d * d * d);
                }
                else
                {
                    return((116 * d - 16) / LabConstants.k);
                }
            }

            var y = (lab.L + 16.0) / 116.0;
            var x = double.IsNaN(lab.A) ? y : y + lab.A / 500.0;
            var z = double.IsNaN(lab.B) ? y : y - lab.B / 200.0;

            y = LabConstants.WhitePointY * lab_xyz(y);
            x = LabConstants.WhitePointX * lab_xyz(x);
            z = LabConstants.WhitePointZ * lab_xyz(z);

            return(new Xyz(x, y, z));
        }
Example #4
0
        public static Color ToColor(this Lab lab)
        {
            var xyz = lab.ToXyz();

            return(xyz.ToColor());
        }