Gamut mapping

The rule for pulling impossible colors into a target gamut while preserving the qualities that matter more than raw channel values.

make p3 colors work in srgbkeep bright colors from clippingpull impossible colors into rangecolor conversion that keeps the lookwhy does my neon look normal again after savinggammit mappingstop my blue turning purple when I convert itfit colors to a printer gamut

See it

Live demo coming soon

What it is

Gamut mapping is the rule used to move colors a target cannot reproduce back inside its range. Unlike channel clipping, a map can trade away chroma gradually while protecting hue, lightness, and the differences between nearby colors. There is no universal nearest color because different jobs value those qualities differently.

For web palettes, a practical method is to convert the color to OKLCH and reduce C until the result fits sRGB, keeping L and h steady where possible; the CSS Color 4 specification defines its own gamut mapping algorithm along exactly those lines. Print workflows expose broader choices through ICC rendering intents: relative colorimetric preserves in-gamut colors, while perceptual mapping may move the whole set to preserve its relationships.

Gotcha: a gamut boundary is lumpy, not a fixed saturation ceiling. One hue may fit at high chroma while its neighbor clips much earlier, and the limit changes again with lightness. Test each color independently, then inspect gradients and image regions together so the mapping does not create bands or erase useful differences.

Ask AI for it

Implement an sRGB gamut mapper for these OKLCH colors. Convert each color to sRGB and, when any channel falls outside 0 to 1, use binary search on OKLCH chroma C until every channel fits within a tolerance of 0.0001. Hold L and h constant throughout the search, then apply a final per-channel clip to absorb any residual rounding, and report each color's chroma reduction and CIEDE2000 Delta E from the source. Output CSS oklch() source values, mapped hex fallbacks, iteration counts, and a comparison against simple RGB channel clipping.

You might have meant

oklchcolor scalechroma vs saturationvalue contrastrgb