forked from w3c/csswg-drafts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.)
- Loading branch information
Showing
1 changed file
with
24 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters