Re: [csswg-drafts] [css-color-4] Linear transformation matrices are very slightly inaccurate (#7675)

@nex3 Sure. The matrices found on that page are calculated from the RGB transforms from XYZ assuming some white point.  That whitepoint did not initially match what the CSS spec was using and caused conversions to not be as good. So, we recalculated, based on the author's guidance.

Now, if we are changing the RGB to XYZ transforms again, conversions will be off again as the Oklab matrices will transform the color from XYZ to sRGB Linear with a matrix than what was done to get the color from sRGB Linear. They must be in sync.

Ensuring rational numbers for sRGB and then calculating Oklab matrices, this is what I get:

sRGB

```
===== sRGB =====
--- rgb -> xyz ---
[[0.4123907992659595, 0.35758433938387796, 0.1804807884018343],
 [0.21263900587151036, 0.7151686787677559, 0.07219231536073371],
 [0.01933081871559185, 0.11919477979462599, 0.9505321522496606]]
--- xyz -> rgb ---
[[3.2409699419045213, -1.5373831775700935, -0.4986107602930033],
 [-0.9692436362808798, 1.8759675015077206, 0.04155505740717561],
 [0.05563007969699361, -0.20397695888897657, 1.0569715142428786]]
```

Oklab

```
===== sRGB Linear -> lms =====
[[0.412221469470763, 0.5363325372617348, 0.05144599326750221],
 [0.21190349581782522, 0.6806995506452342, 0.1073969535369405],
 [0.08830245919005643, 0.2817188391361215, 0.6299787016738221]]
===== lms -> sRGB Linear =====
[[4.076741636075958, -3.307711539258062, 0.23096990318210417],
 [-1.268437973285032, 2.609757349287689, -0.3413193760026571],
 [-0.0041960761386755155, -0.7034186179359364, 1.707614694074612]]
===== XYZ D65 Linear -> lms =====
[[0.819022437996703, 0.3619062600528904, -0.12887378152098788],
 [0.03298365393238847, 0.9292868615863433, 0.03614466635064236],
 [0.0481771893596242, 0.2642395317527308, 0.6335478284694308]]
===== lms -> XYZ D65 =====
[[1.2268798758459243, -0.5578149944602171, 0.2813910456659646],
 [-0.04057574521480084, 1.1122868032803173, -0.07171105806551635],
 [-0.07637293667466007, -0.42149333240224324, 1.5869240198367818]]
===== lms ** 1/3 -> Oklab =====
[[0.2104542553, 0.793617785, -0.0040720468],
 [1.9779984951, -2.428592205, 0.4505937099],
 [0.0259040371, 0.7827717662, -0.808675766]]
===== Oklab -> lms ** 1/3 =====
[[0.9999999984505198, 0.39633779217376786, 0.2158037580607588],
 [1.0000000088817609, -0.10556134232365635, -0.06385417477170591],
 [1.0000000546724108, -0.08948418209496575, -1.2914855378640917]]
```

-- 
GitHub Notification of comment by facelessuser
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/7675#issuecomment-1235961396 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Friday, 2 September 2022 22:58:08 UTC