You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use exact values for some matrices in conversions.js
These color space conversion matrices have exact rational values that
can be computed from the numbers provided in the spec. Using exact
values is more succinct for most of these matrices, and also makes it a
nice reference implementation for other languages. This example code
already uses exact inline formulations for a number of other things,
like D50 and D65 definitions, so this is similar to that.
I only did the XYZ conversion matrices for srgb, display-p3, a98-rgb,
and rec2020.
- I don't have code to easily compute the D65/D50 conversions or
OKLab/OKLCH as I was only interested in the predefined color spaces.
- The rational forms of prophoto-rgb's matrices exceed the precision of
JavaScript math. I could include them as comments though.
Source to compute these: https://github.com/kainino0x/exact_css_xyz_matrices
using this Rust crate: https://crates.io/crates/rgb_derivation
as described for sRGB on this page: https://mina86.com/2019/srgb-xyz-matrix/
but using the numbers from this spec.
I used these in the WebGPU conformance test suite:
gpuweb/cts#1089
WebGPU needed only srgb and display-p3, but it was easy to extend to the
other predefined color spaces. (WebGPU may add some of those color
spaces eventually anyway.)
0 commit comments