culori icon indicating copy to clipboard operation
culori copied to clipboard

clampChroma in sRGB: pure blue gives unexpected results

Open StephenHaney opened this issue 11 months ago • 0 comments

We're seeing very unexpected results when using clampChroma with an RGB value like 0, 0, 1.

Quick example:

const pureRGBBlue = rgbToOklch({ mode: 'rgb', r: 0, g: 0, b: 1 });
// {mode: 'oklch', l: 0.4520137183853429, c: 0.31321437166460125, h: 264.052020638055, alpha: undefined}
// this is expected

const clampedBlue = clampChroma(pureRGBBlue, 'oklch', 'rgb');
// {mode: 'oklch', l: 0.4520137183853429, c: 0.2655745880837794, h: 264.052020638055}
// ^^^ unexpected, chroma clamped 0.05 lower (the input value was already valid RGB chroma)

const backToRgb = oklchToRgb(clampedBlue);
// {mode: 'rgb', r: 0, g: 0.19215686274509805, b: 0.9019607843137255, alpha: undefined}
// expected would be 0 0 1

Apologies if I'm not understanding something correctly, which is very possible!

Is this related to #33? Is there anything we can do to improve our results?

StephenHaney avatar Jan 16 '25 20:01 StephenHaney