Skip to content

clampChroma in sRGB: pure blue gives unexpected results #253

Open
@StephenHaney

Description

@StephenHaney

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?

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