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

inGamut wrong result for white in OKLCH #249

Open
ai opened this issue Nov 22, 2024 · 3 comments
Open

inGamut wrong result for white in OKLCH #249

ai opened this issue Nov 22, 2024 · 3 comments

Comments

@ai
Copy link

ai commented Nov 22, 2024

const inRGB = inGamut('rgb')

inRGB({ mode: 'oklch', l: 1, c: 0, h: 0 }) // => false
// white is in sRGB and return should be true

We found this issue in OKLCH color picker.

I can’t remember this issue previously. It could be related to some recent changes, but it is hard to say when exactly (we are using culori version 4.0.1).

@danburzo
Copy link
Collaborator

oklch(100% 0 0) is ever so slightly out of gamut in sRGB:

culori.rgb({ mode: 'oklch', l: 1, c: 0, h: 0 })
Object { mode: "rgb", r: 0.9999999694343974, g: 1.000000008665371, b: 1.0000001148563589 }

This may be due to the matrices we’re using for the conversion. There’s an open issue about updating the matrices to match the latest CSS 4 spec (#237), but if I remember correctly color.js uses the new matrices and the color is still, technically, very slightly out of gamut:

new Color('oklch(100% 0 0)').to('srgb').coords
Array(3) [ 1.0000000000000007, 0.9999999999999994, 0.9999999999999999 ]

To address these, maybe it would be a good idea to round the coordinates to fewer decimal places?

@danburzo
Copy link
Collaborator

A similar issue is discussed here.

@ai
Copy link
Author

ai commented Nov 27, 2024

To address these, maybe it would be a good idea to round the coordinates to fewer decimal places?

It will be great.

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

No branches or pull requests

2 participants