Closed danburzo closed 6 years ago
Wow, CSS will include lab and lch color spaces! Nice of them to include detailed descriptions and reference implementations. Changing d3-color to match the specification would be great.
The current CSS specification for Lab / LCH leaves some legroom to the choice of matrices / precision when transforming sRGB to Lab, but the intent is to have the Lab be relative to the standard D50 white point. In the pull request above, I'm skipping some intermediary steps from the reference implementation and using a single matrix for linear RGB ↔ XYZD50 from the same web page they cite in their code.
The output closely matches Matlab's rgb2lab
and lab2rgb
fucntions, so I think this may be a wrap until the CSS Color Module Level 4 spec gets fleshed out :)
Fixed in #46.
While investigating why d3's
lab()
method gives subtly different results than, for example, Wolfram Alpha, I came to understand d3-color is missing a chromatic adaptation between the D65 (sRGB) and D50 (Lab) illuminants:The process should be: Lab ↔ XYZ (D50) ↔ XYZ(D65) ↔ RGB
I'm not sure how important this adaptation is to the purpose of the library, but it boils down to using the matrices from this page: