Fix gamut mapping binary search - #1323
Open
dkryaklin wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_inGamutflag, 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".