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

I'm not sure if that test case was implying that the XYZ D50 value is meant to be the exact translation of  `#008000` or not. I also don't know if that test was generated with earlier matrices or not (the RGB matrices have changed at least once or twice).

One thing that can be noted is that the XYZ value is not off due to rounding errors as the non-rational matrices are no where near that lossy. They actually have pretty decent round tripping.

```python
>>> xyz = Color('#008000').convert('xyz-d50')
>>> xyz
color(xyz-d50 0.08314 0.15475 0.02096 / 1)
>>> xyz.convert('srgb').convert('xyz-d50')
color(xyz-d50 0.08314 0.15475 0.02096 / 1)
```

We can also see the test holds true as well since you have to round things off to get the hex values.

```python
>>> Color('color(xyz-d50 0.08312 0.154746 0.020961)').convert('srgb').to_string(hex=True)
#008000
```

---

On a side note. I did some experiments using rational numbers for the RGB matrices in my own library.

Using approximate values for the RGB matrices, I get some pretty clean conversions to lab:

```python
>>> Color('white').convert('lab-d65')[:]
[100.0, 0.0, 0.0, 1.0]
>>> Color('white').convert('lab')[:]
[100.0, 0.0, 0.0, 1.0]
```

But when I used rational matrices for the RGB matrices, I get:

```python
>>> Color('white').convert('lab-d65')[:]
[100.0, 0.0, 0.0, 1.0]
>>> Color('white').convert('lab')[:]
[100.0, 1.1102230246251565e-13, 0.0, 1.0]
```

Now, does that mean the rational-matrices aren't as good? No, they definitely ensure less error is introduced during the matrix calculation, they just don't prevent all the other errors introduced during the rest of the calculations.

Since most of these color spaces are designed using approximate values anyways, it's probably just dumb luck that the approximate matrices give me such nice values. Would I get even better values for the rational-matrix examples if I ensured the chromatic adaptation matricies also used rational numbers and ensured that all other calculations used rational numbers? Maybe, but it's not realistic to ensure the whole conversion path conforms to using rational numbers.

In general, I really didn't see significant improvements in overall calculations to warrant using rational numbers in my personal library. I also didn't see any significantly worse calculations to argue against using them either. Since the difference between the rational matrices and the approximate matrices is so slight, I guess this is to be expected.

If someone was building an application, I'd personally argue it probably isn't going to matter which is used.


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


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

Received on Thursday, 29 September 2022 01:50:37 UTC