Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken Oklab color space matrices and conversions. #129

Conversation

patternspandemic
Copy link
Contributor

Hello.

This PR resolves what seems to be a big of mix up with the Oklab color space functions, naming, and its use of the srgb <--> (linear)rgb conversion functions.

I think transformation functionality was misnamed and/or put into the wrong files in the two different conversion scenarios: oklab2(s)rgb and (s)rgb2oklab. This problem was then exacerbated by using the wrong order of linear (rgb) and non-linear (srgb) transformations, probably due to the naming and placement of functionality.
For example,

  • the current oklab2srgb file actually converts oklab to (linear)rgb, but is named as converting to sRGB.
  • the current oklab2rgb file uses the incorrectly named oklab2srgb to perform a correct transform of oklab->linear, but then incorrectly uses srgb2rgb (a double transform to linear).
  • the current rgb2oklab converts (linear)rgb to sRGB (even though its already linear) probably because the actual transform functionality was put into srgb2okab.
  • the current srgb2oklab actually converts (linear)rgb to oklab, but is named as converting from sRGB.

For testing, I used this pinkish color and the srgb and oklab derived values provided by the color picker functionality. I could not achieve results that were expected with any combination of current functions. These incorrect results can be seen by using this Oklab tester shader which I creatred to confirm this fix. With existing code, the color turned out on the lime green side of things rather than pinkish. With this fix, the expected results are a 2x2 grid of the same pinkish color.

I think there may have been one or two errors in the transform matrices involved. I have replaced them with the current ones found at the resource here, which I utilized to perform this fix:
Converting from linear sRGB to Oklab
Use a linear version of sRGB

I can only confirm the glsl functionality works as I expect, and was unable to test the updated hlsh/wgsl code.

Cheers, Brad

@patriciogonzalezvivo
Copy link
Owner

Thank you so much!

@patriciogonzalezvivo patriciogonzalezvivo merged commit 188790b into patriciogonzalezvivo:main Mar 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants