Skip to content

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

@Jeremy-Knudsen

Description

@Jeremy-Knudsen

I store original source rgb colors in an array variable, which are taken from the Rgb color space. I then have a user interface that allows a user to manipulate these source colors in the Oklch color space, which then renders the user-manipulated colors back in the Rgb color space.

The problem is that the target never ends up equaling its source even when there is no manipulation of hue, chroma, or luminosity as shown here:

With using clampRgb:
`
culori.clampRgb(culori.rgb(culori.oklch({
"mode": "rgb",
"r": 1,
"g": 1,
"b": 1
})))

{mode: 'rgb', r: 0.9999999608276361, g: 1, b: 1} // Result: expected value of r = 1, but got a value < 1
`

Without using clampRgb:
`
culori.rgb(culori.oklch({
"mode": "rgb",
"r": 1,
"g": 1,
"b": 1
}))

{mode: 'rgb', r: 0.9999999608276361, g: 1.00000000005861, b: 1.0000001062495965} // Result: expected value of g < 1 and b < 1, but got g and b values > 1
`

Why does this matter? Because when a user increases the chroma of pure white, I would expect pure white to stay pure white since it is achromatic. But because of this issue, white can becomes a color (often magenta) when chroma is added.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions