Fix gamut mapping returning black/greenish for white pixels#13
Fix gamut mapping returning black/greenish for white pixels#13
Conversation
…nstead of zero-value check The binary search in gamutMapChromaScale used zero-initialized foundR/foundG/foundB to detect if any in-gamut result was found. When no iteration produced an in-gamut result (e.g., L=100 white with tiny floating-point overshoot), the (0,0,0) values passed the inGamut check, returning black instead of falling through to the clamp-based fallback path. Agent-Logs-Url: https://github.com/kovidgoyal/imaging/sessions/6d77cc7a-d602-4b36-ab87-49e86b6fee6f Co-authored-by: kovidgoyal <1308621+kovidgoyal@users.noreply.github.com>
|
@copilot the test still fails now with: and looking at the converted image we see the background pixels have a slight greenish hue rather than being pure white. |
…n Lab round-trip When the XYZtosRGB optimizer absorbs preceding matrices via AddPreviousMatrix, the input is no longer XYZ but Display P3 linear RGB. The Lab-based gamut mapping fallback calls XYZToLab on these non-XYZ values, producing wrong Lab colors and a visible greenish hue on white pixels. Add a "nearly in gamut" check (epsilon=0.002, ~0.5/255 in 8-bit) that clamps values marginally outside [0,1] instead of routing through the Lab path. This correctly handles floating-point precision artifacts from fused matrix operations. Agent-Logs-Url: https://github.com/kovidgoyal/imaging/sessions/b86b3a47-5553-4b44-b121-93a815e73a05 Co-authored-by: kovidgoyal <1308621+kovidgoyal@users.noreply.github.com>
Fixed in 3642314. The greenish hue was caused by the The fix adds a "nearly in gamut" epsilon check (0.002, ~0.5/255 in 8-bit) in |
…active The pipeline optimizer was fusing preceding matrices into XYZtosRGB via AddPreviousMatrix, which changes the input from XYZ to the upstream color space's linear RGB. This broke the gamut mapping fallback path which calls XYZToLab (requiring actual XYZ input), causing incorrect colors for out-of-gamut values (e.g., white pixels getting a greenish hue). Fix: track whether gamut mapping is enabled on XYZtosRGB and skip matrix absorption when it is, so the input remains actual XYZ values. Also reverts the epsilon-clamping workaround in XYZToSRGB which was masking this underlying issue. Agent-Logs-Url: https://github.com/kovidgoyal/imaging/sessions/83a3851a-10fe-4966-b543-f8f901ab567b Co-authored-by: kovidgoyal <1308621+kovidgoyal@users.noreply.github.com>
colorconv/colorconv.goXYZToSRGB (keep thefoundboolean fix in gamutMapChromaScale)XYZtosRGBinprism/meta/icc/pcs.goto track whether gamut mapping is activeprism/meta/icc/pipeline.goto skip matrix absorption when XYZtosRGB has gamut mapping enabled