Let AdjustForContrast darken on mid-tone backgrounds [patch] - #292
Merged
Merged
Conversation
AdjustForContrast chose its direction with a 0.5 luminance threshold, but white and black give equal contrast near luminance 0.179. On any background between those two it searched only the lightening direction, which cannot reach AA, and returned the failing colour unchanged. Search first toward the extreme with more contrast headroom, and fall back to the other direction before giving up. Fixes #279 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PKmokmgnpkeYgp439Qbthh
|
This was referenced Sep 28, 2026
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 #279
What was wrong
Color.AdjustForContrastpicked its search direction withbackground.RelativeLuminance < 0.5. White and black actually give equal contrast near luminance 0.179. On any background between 0.18 and 0.5, the method only searched toward white. That direction cannot reach AA there (or large-text AA above about 0.30), so the method returned the failing foreground unchanged.Change
1.05/(L+0.05) >= (L+0.05)/0.05).Search(goLighter)function.Tests
AdjustForContrast_DarkensOnMidToneBackgrounduses the issue's example: background sRGB 0.58 grey (L ≈ 0.296), AA.AdjustForContrast_ReachesLargeTextAAOnUpperMidToneBackground: background sRGB 0.7 grey (L ≈ 0.45), large-text AA.AdjustForContrast_LightensOnDarkBackgroundis a guard that dark backgrounds still lighten.The first two fail on
mainand pass with this change. The fullSemantics.Testsuite passes: 1336 passed, 8 skipped.🤖 Generated with Claude Code
https://claude.ai/code/session_01PKmokmgnpkeYgp439Qbthh
Generated by Claude Code