public static double diff(Color color1, Color color2)
        {
            LabColor lab1 = LabColorTransform.RgbToLab(color1);
            LabColor lab2 = LabColorTransform.RgbToLab(color2);

            return(Math.Sqrt((lab2.L - lab1.L) * (lab2.L - lab1.L) + (lab2.A - lab1.A) * (lab2.A - lab1.A) + (lab2.B - lab1.B) * (lab2.B - lab1.B)));
        }
        public static Color XyzToRgb(XyzColor xyz)
        {
            double var_X = xyz.X / 100;        //X from 0 to  95.047      (Observer = 2°, Illuminant = D65)
            double var_Y = xyz.Y / 100f;       //Y from 0 to 100.000
            double var_Z = xyz.Z / 100f;       //Z from 0 to 108.883

            double var_R = var_X * 3.2406f + var_Y * -1.5372f + var_Z * -0.4986f;
            double var_G = var_X * -0.9689f + var_Y * 1.8758f + var_Z * 0.0415f;
            double var_B = var_X * 0.0557f + var_Y * -0.2040f + var_Z * 1.0570f;

            if (var_R > 0.0031308f)
            {
                var_R = 1.055f * (Math.Pow(var_R, 1f / 2.4f)) - 0.055f;
            }
            else
            {
                var_R = 12.92f * var_R;
            }
            if (var_G > 0.0031308f)
            {
                var_G = 1.055f * (Math.Pow(var_G, 1f / 2.4f)) - 0.055f;
            }
            else
            {
                var_G = 12.92f * var_G;
            }
            if (var_B > 0.0031308f)
            {
                var_B = 1.055f * (Math.Pow(var_B, 1f / 2.4f)) - 0.055f;
            }
            else
            {
                var_B = 12.92f * var_B;
            }

            return(Color.FromArgb(
                       LabColorTransform.Range((int)Math.Round(var_R * 255f, 0f), 0, 0xff),
                       LabColorTransform.Range((int)Math.Round(var_G * 255f, 0f), 0, 0xff),
                       LabColorTransform.Range((int)Math.Round(var_B * 255f, 0f), 0, 0xff)));
        }
Example #3
0
 public static Color LabToRgb(LabColor lab)
 {
     return(LabColorTransform.LabToRgb(lab));
 }
Example #4
0
 public static LabColor RgbToLab(Color rgb)
 {
     return(LabColorTransform.RgbToLab(rgb));
 }
Example #5
0
 public static Color XyzToRgb(XyzColor xyz)
 {
     return(LabColorTransform.XyzToRgb(xyz));
 }
Example #6
0
 public static XyzColor LabToXyz(LabColor lab)
 {
     return(LabColorTransform.LabToXyz(lab));
 }
Example #7
0
 public static XyzColor RgbToXyz(Color rgb)
 {
     return(LabColorTransform.RgbToXyz(rgb));
 }