Ask HN: Why are the calculations in latest WC3 CSS Color Module Level 4 wrong?
[1] - https://www.w3.org/TR/css-color-4/#rgb-to-hsl
[1] - https://www.w3.org/TR/css-color-4/#rgb-to-hsl
Only if the value of d is zero. That happens iff r == g == b, so for white, black and the gray values in between them.
That technically is right. https://en.wikipedia.org/wiki/HSL_and_HSV:
HSL and HSV are both cylindrical geometries (fig. 2), with hue, their angular dimension, starting at the red primary at 0°, passing through the green primary at 120° and the blue primary at 240°, and then wrapping back to red at 360°. In each geometry, the central vertical axis comprises the neutral, achromatic, or gray colors ranging, from top to bottom, white at lightness 1 (value 1) to black at lightness 0 (value 0).
So, for the colors on the central axis, the hue is undefined.
Picking any specific value for the hue would be an arbitrary choice.
As functions go, it is very neat and tidy. Some of the code I came across while searching for an RGB > HSL solution were ... not pleasant to read through.
> But the calculation for converting sRGB colors to HSL
I don’t know whether you’re aware, but RGB and sRGB are different things. sRGB is device-independent, RGB is device-dependent. Depending on what the values in the RGB you have mean, that may or may not involve ‘not pleasant’ code.
(Color is one of the items on the long list of things to try to avoid when programming. A few of the other items on that list are Unicode, dates and times, multi-threading and floating point. All have standards that aren’t pleasant, but also the most pleasant we have available)
Too late. I got annoyed by the lack of support for HWB, LCH and LAB in Chrome/Firefox. Safari now supports them for CSS, but has not yet made the effort to support them in the canvas element. I wanted users of my JS canvas library to be able to fill and stroke things using any valid CSS color string ... so I've been doing the work to make it happen over the holidays.
It's been worth the effort. Red > Blue gradients look so, so much better when using LAB color space values, compared to what you normally get using RGB.