getHSL method
Implementation
Map<String, dynamic> getHSL(Map<String, dynamic> target, [String colorSpace = LinearSRGBColorSpace]) {
// h,s,l ranges are in 0.0 - 1.0
ColorManagement.fromWorkingColorSpace( toComponents( this, _rgb ), colorSpace );
var r = _rgb["r"], g = _rgb["g"], b = _rgb["b"];
var max = Math.max3(r!, g!, b!);
var min = Math.min3(r, g, b);
var hue, saturation;
var lightness = (min + max) / 2.0;
if (min == max) {
hue = 0;
saturation = 0;
} else {
var delta = max - min;
saturation =
lightness <= 0.5 ? delta / (max + min) : delta / (2 - max - min);
if (max == r) {
hue = (g - b) / delta + (g < b ? 6 : 0);
} else if (max == g) {
hue = (b - r) / delta + 2;
} else if (max == b) {
hue = (r - g) / delta + 4;
}
hue /= 6;
}
target["h"] = hue;
target["s"] = saturation;
target["l"] = lightness;
return target;
}