public static XYZColor lab2xyz(LabColor lab) { const double REF_X = 95.047; // Observer= 2°, Illuminant= D65 const double REF_Y = 100.000; const double REF_Z = 108.883; double y = (lab.l + 16.0) / 116.0; double x = lab.a / 500.0 + y; double z = y - lab.b / 200.0; if (Math.Pow(y, 3) > 0.008856) { y = Math.Pow(y, 3); } else { y = (y - 16.0 / 116.0) / 7.787; } if (Math.Pow(x, 3) > 0.008856) { x = Math.Pow(x, 3); } else { x = (x - 16.0 / 116.0) / 7.787; } if (Math.Pow(z, 3) > 0.008856) { z = Math.Pow(z, 3); } else { z = (z - 16.0 / 116.0) / 7.787; } XYZColor xyz = new XYZColor(0, 0, 0); xyz.x = REF_X * x; xyz.y = REF_Y * y; xyz.z = REF_Z * z; return(xyz); }
public static LabColor xyz2lab(XYZColor xyz) { const double REF_X = 95.047; // Observer= 2°, Illuminant= D65 const double REF_Y = 100.000; const double REF_Z = 108.883; double x = xyz.x / REF_X; double y = xyz.y / REF_Y; double z = xyz.z / REF_Z; if (x > 0.008856) { x = Math.Pow(x, 1.0 / 3.0); } else { x = (7.787 * x) + (16.0 / 116.0); } if (y > 0.008856) { y = Math.Pow(y, 1.0 / 3.0); } else { y = (7.787 * y) + (16.0 / 116.0); } if (z > 0.008856) { z = Math.Pow(z, 1.0 / 3.0); } else { z = (7.787 * z) + (16.0 / 116.0); } LabColor lab = new LabColor(0, 0, 0); lab.l = (int)(116 * y) - 16; lab.a = (int)(500 * (x - y)); lab.b = (int)(200 * (y - z)); return(lab); }
public static RGBColor lab2rgb(LabColor lab) { XYZColor xyz = ColorConversor.lab2xyz(lab); return(ColorConversor.xyz2rgb(xyz)); }
public static int toRGB(LabColor c) { return(0); }