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()); }
public static Xyz ToXyz(this Lab lab) { double LabXyz(double d) { if (d > LabConstants.ECubedRoot) { return(d * d * d); } 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 * LabXyz(y); x = LabConstants.WhitePointX * LabXyz(x); z = LabConstants.WhitePointZ * LabXyz(z); return(new Xyz(x, y, z)); }
public static Color ToColor(this Lab lab) { var xyz = lab.ToXyz(); return(xyz.ToColor()); }