Re: [csswg-drafts] [css-color] Add OKLab, OKLCH (#6642)

Yeah, exactly. 

Definitely makes sense that that solution works, although would be good to define the matrix in a way that is independent of sRGB.

I think a good way to define M1 would be along these lines (here in python and numpy, but it is just matrix operations):
```
# The rows have been scaled to sum to 1, and contains no whitepoint information.
M0 = np.array([
  [  0.77849780,  0.34399940,  -0.12249720],
  [  0.03303601,  0.93076195,   0.03620204],
  [  0.05092917,  0.27933344,   0.66973739]
])

d65_xyz = np.array([0.3127, 0.3290, 1-0.3127-0.3290])
d65_XYZ = d65_xyz/d65_xyz[1]

# Calculate M1 by scaling scale each row if M0 so that d65_XYZ transforms exactly to 1,1,1
M1 = M0 / np.outer(M0.dot(d65_XYZ), np.ones(3)) 
```

This way the accuracy of white mapping to zero chroma is only dependent on the accuracy of the computations, not the rounding of the matrices.

**Regarding the scaling of a&b:** 

Yes, this would certainly be a breaking change, so I am a bit hesitant about it as well. On the other hand the potential improvement is pretty large. 

I unfortunately didn't spend that much time calculating and validating that scaling factor when I first derived Oklab since I was mostly focused on the orthogonality between L, C and h (and I didn't expect it to become so widespread so quickly), and it seems like it is off by quite a bit.

I've recently done some tests with color distance datasets as implemented in [Colorio ](https://github.com/nschloe/colorio)
and on both the [Combvd dataset](https://www.osapublishing.org/josaa/abstract.cfm?uri=josaa-25-7-1828) and the [OSA-UCS dataset](https://www.osapublishing.org/josa/abstract.cfm?uri=josa-64-12-1691) a scale factor of slightly more than 2 for a and b would give the best results (2.016 works best for Combvd and 2.045 for the OSA-UCS dataset). 


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


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

Received on Monday, 18 October 2021 12:28:50 UTC