Closed kettle11 closed 3 years ago
Oh neat, thank you for this! Goes to show that we really need a proper test suite sooner rather than later..
Should we use cbrt for the similar operation in XYZ_to_CIELAB as well?
Should we use cbrt for the similar operation in XYZ_to_CIELAB as well?
That code looks like this:
if v > 0.008856 {
v.powf(1.0 / 3.0)
}
Since v
's definitely not negative then there's no risk of NaN
values there. cbrt
is probably faster though.
I stumbled across this issue today. It seems like a very easy error to make when implementing Oklab and took a bit of time to track down the fix.
Negative numbers can be produced for the
lms
components during conversion. Raising those to1. / 3.
withpowf
can produceNaN
values. Usingcbrt
instead avoids that and matches the expected values in the table "Table of example XYZ and Oklab pairs" on this page: https://bottosson.github.io/posts/oklab/