hexToLab function
Implementation
LAB hexToLab(String hex) {
RGB rgbColor = hexToRgb(hex);
double r = rgbColor.r / 255,
g = rgbColor.g / 255,
b = rgbColor.b / 255,
x,
y,
z;
r = (r > 0.04045) ? pow((r + 0.055) / 1.055, 2.4) as double : r / 12.92;
g = (g > 0.04045) ? pow((g + 0.055) / 1.055, 2.4) as double : g / 12.92;
b = (b > 0.04045) ? pow((b + 0.055) / 1.055, 2.4) as double : b / 12.92;
x = (r * 0.4124 + g * 0.3576 + b * 0.1805) / 0.95047;
y = (r * 0.2126 + g * 0.7152 + b * 0.0722) / 1.00000;
z = (r * 0.0193 + g * 0.1192 + b * 0.9505) / 1.08883;
x = (x > 0.008856) ? pow(x, 1 / 3) as double : (7.787 * x) + 16 / 116;
y = (y > 0.008856) ? pow(y, 1 / 3) as double : (7.787 * y) + 16 / 116;
z = (z > 0.008856) ? pow(z, 1 / 3) as double : (7.787 * z) + 16 / 116;
return LAB(
l: ((116 * y - 16) * 10).roundToDouble() / 10,
a: (500 * (x - y) * 10).roundToDouble() / 10,
b: (200 * (y - z) * 10).roundToDouble() / 10,
);
}