Skip to content

Precise chroma clamping in P3 color space #211

Closed
@antiflasher

Description

@antiflasher

It's a specifying of the issue #168.

I need to clamp chroma of an oklch color to a color space with saving it's original lightness and hue. Clamping to srgb works like a charm

let oklch = "oklch(70% 0.4 200)";
let oklchInSrgb = formatCss(clampChroma(oklch, "oklch"));
// oklch(0.7 0.118994140625 200)

Notice the lightness and the hue components being perfectly preserved.

But I couldn't find a way to achieve the same result in P3 color space.

let oklch = "oklch(70% 0.4 200)";
let colorInP3 = toGamut("p3", "oklch")(oklch);
// {"mode":"p3","r":-5.737632591262809e-15,"g":0.7258740626886799,"b":0.780719016756523}
let oklchInP3 = formatCss(converter("oklch")(colorInP3));
// oklch(0.7077162166817106 0.16120532620505068 201.07047721732414)

Notice the lightness and the hue components being mangled.

clampGamut(space) doesn't give the expected result as well:

let oklch = "oklch(70% 0.4 200)";
let colorInP3 = clampGamut("p3")(oklch);
// colorP3InP3: {"mode":"oklch","l":0.7775064298678066,"c":0.18210771244225787,"h":214.39043121337434}
let oklchInP3 = formatCss(colorInP3);
// oklch(0.7775064298678066 0.18210771244225787 214.39043121337434)

Can we have a clampChroma analog for P3 color space that works as perfect as the one for srgb?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions