Skip to content

Fix gamut mapping binary search - #1323

Open
dkryaklin wants to merge 1 commit into
parcel-bundler:masterfrom
dkryaklin:fix-gamut-mapping
Open

Fix gamut mapping binary search#1323
dkryaklin wants to merge 1 commit into
parcel-bundler:masterfrom
dkryaklin:fix-gamut-mapping

Conversation

@dkryaklin

@dkryaklin dkryaklin commented Sep 2, 2026

Copy link
Copy Markdown

Fixes #1298.

The gamut mapping binary search returned as soon as it found a chroma under the JND. The spec keeps searching upward from that point and returns the largest chroma still under the JND. Because of the early return, sRGB fallbacks for wide gamut colors came out less saturated than the spec and colorjs.io produce.

This change follows the spec pseudocode: it clips the origin color once before the loop, carries the min_inGamut flag, and returns the last clipped color. The epsilon now matches the spec value and the spec link points to the current anchor.

The same search is implemented in colordx, where it matches colorjs.io on a large set of out of gamut samples. The loop here mirrors that math.

Test expectations that depended on the old behavior are updated, and the cases from the issue are added. All new values match colorjs.io with method: "css".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gamut mapping returns at the first under-JND chroma, producing desaturated sRGB fallbacks

1 participant