xyzToLab static method
Converts an XYZ color to a LAB color.
Implementation
static LabColor xyzToLab(XyzColor xyzColor) {
final xyz = xyzColor
.toFactoredList()
.map((xyzValue) => ((xyzValue > 0.008856)
? math.pow(xyzValue, 0.3334)
: (7.787 * xyzValue) + (16 / 116))
.toDouble())
.toList();
final x = xyz[0];
final y = xyz[1];
final z = xyz[2];
final lightness = ((116 * y) - 16).clamp(0.0, 100.0);
final a = ((x - y) * 500).clamp(-128.0, 127.0);
final b = ((y - z) * 200).clamp(-128.0, 127.0);
return LabColor(lightness, a, b, xyzColor.alpha);
}