Keep source alpha and tolerate round-trip error when extrapolating a single colour [patch] - #127
Merged
Conversation
…single colour [patch] ExtrapolateColorToLightness rebuilt colours with Color.FromOklab and no alpha, so every single-colour meaning (every accent) came out opaque while interpolated neutral ramps kept theirs. Pass baseColor.A through. Its gamut test also bounded linear channels exactly at [0, 1]. An Oklab round trip leaves ~1e-7 of error, so colours on the gamut boundary such as #ff0000 were treated as out of gamut and had their chroma shaved (#ff0000 -> #ff0201). Move the check into IsInGamut with a 1e-6 tolerance and clamp the result, at both call sites. Fixes #111 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SerwFWrikSrdorQJydu9st
|
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 #111
What changed
Both defects are in
SemanticColorMapper.ExtrapolateColorToLightness, which handles single-colour meanings.Color.FromOklabcall there now passesbaseColor.A. Before this, accents always came out opaque, while interpolated neutral ramps kept their alpha.[0, 1]channel checks are replaced by oneIsInGamuthelper that allows ±1e-6 (GamutTolerance). Both return paths now finish withColor.Clamp(), so a colour accepted inside that tolerance still comes out in[0, 1]. As a result,#ff0000comes back as#ff0000instead of#ff0201.ExtrapolateColorToLightnessis nowinternalso it can be tested directly. The test project already hasInternalsVisibleTo.Tests
These are added to
SemanticColorMapperEdgeCaseTests:MapColors_WithSingleTranslucentSourceColor_KeepsItsAlphauses the issue's repro: Neutral#10101080/#f0f0f080and Primary#3366cc80. It asserts that every Primary priority keeps alpha 0.502.ExtrapolateColorToLightness_AtItsOwnLightness_ReturnsTheSameColorchecks that each of these comes back with exactly the same hex: the six sRGB primaries and secondaries, white, black, and a translucent colour.With the fix reverted, 5 tests fail: the alpha test and
#FF0000,#00FF00,#FFFF00,#3366CC80. With it applied, all 77 tests pass on net10.0.ThemeSnapshotTestsis unchanged, so none of the built-in theme palettes shift.🤖 Generated with Claude Code
https://claude.ai/code/session_01SerwFWrikSrdorQJydu9st
Generated by Claude Code