rgb2hsl static method
Implementation
static List<int> rgb2hsl(List<num> rgb) {
final num r = rgb[0] / 255.0;
final num g = rgb[1] / 255.0;
final num b = rgb[2] / 255.0;
final num minC = min(r, min(g, b));
final num maxC = max(r, max(g, b));
final num delta = maxC - minC;
num h = 0;
num s;
if (maxC == minC) {
h = 0;
} else if (r == maxC) {
h = (g - b) / delta;
} else if (g == maxC) {
h = 2 + (b - r) / delta;
} else if (b == maxC) {
h = 4 + (r - g) / delta;
}
h = min(h * 60, 360);
if (h < 0) {
h += 360;
}
final num l = (minC + maxC) / 2;
if (maxC == minC) {
s = 0;
} else if (l <= 0.5) {
s = delta / (maxC + minC);
} else {
s = delta / (2 - maxC - minC);
}
return [h.round(), (s * 100).round(), (l * 100).round()];
}