Skip to content

Target not equal to source when converting rgb(1,1,1) to oklch, and then back to rgb. #238

Answered by danburzo
Jeremy-Knudsen asked this question in Q&A
Discussion options

You must be logged in to vote

Hi Jeremy, thanks for the issue.

The results you’re seeing are caused by the fact that a roundtrip from sRGB to Oklch and back introduces subtle precision errors. They are, to some extent, unavoidable and unfortunately need to be actively managed depending on the usage.

I believe we are currently using the matrices from the original Oklab article, while the CSS Color Level 4 spec has updated them (see this discussion). It offers better roundtripping but does not completely eliminate these sort of small errors.

You may want to experiment with rounding these small values to a number of decimals that make practical sense for your use case. Culori has the culori.round() helper for that:

import {

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by danburzo
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #236 on May 12, 2024 08:47.