Skip to content

Preserve brightest channel when clamping foreground chroma#16

Merged
rosslazer merged 1 commit intomainfrom
ross/fix-foreground-clamp-luminance
Apr 28, 2026
Merged

Preserve brightest channel when clamping foreground chroma#16
rosslazer merged 1 commit intomainfrom
ross/fix-foreground-clamp-luminance

Conversation

@rosslazer
Copy link
Copy Markdown
Contributor

Summary

  • Foreground chroma clamp added in Fix table rendering in plan view #13 (286ca56) was desaturating in HSL at constant lightness, which dims peak-channel colors. Cyberpunk Umbra's #00ff9c (perceived Y=0.84) collapsed to #5f9f86 (Y=0.54) — readable in isolation, but contrast against the theme's dark base01 was low enough that the chat input box became hard to read while typing.
  • Switch the rebuild path to HSV desaturation: pull each channel toward max(r,g,b) by maxChroma / chroma. V stays fixed, perceived luminance is preserved, and the result on dark themes is a pastel that contrasts cleanly with the background. #00ff9c now resolves to #bfffe6 (Y=0.91).
  • Built-in themes (Solarized, Tokyo Night, Gruvbox, Catppuccin, Nord) still hit the early-return path (chroma ≤ 0.25) and are unchanged.
  • Drops the now-unused hslToRGB / hueToRGB helpers.

Test plan

  • swift build clean
  • Cyberpunk Umbra base05 #00ff9c#bfffe6, base04 #7877b3 unchanged (already under cap)
  • All 6 built-in scheme base05 values produce identical output to pre-clamp
  • Run the app with Cyberpunk Umbra and confirm chat input + body text are clearly readable

`readableForeground` was desaturating high-chroma foregrounds in HSL at
constant lightness, which dims peak-channel colors. Cyberpunk Umbra's
#00ff9c (V=1, perceived Y=0.84) collapsed to #5f9f86 (Y=0.54) — readable
in isolation but with poor contrast against the theme's dark base01
background. The chat input box, which uses theme.text on inputBackground,
became hard to read while typing.

Switch the rebuild path to HSV desaturation: pull each channel toward
max(r,g,b) by the same factor we'd pull saturation. Keeps V fixed, so
perceived luminance is preserved and the result on dark themes is a
pastel that contrasts cleanly with the background. #00ff9c now becomes
#bfffe6 (Y=0.91). Built-in themes still hit the early-return path
(chroma ≤ 0.25), so they're untouched.

Drops the now-unused hslToRGB / hueToRGB helpers.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@rosslazer rosslazer merged commit 040ab54 into main Apr 28, 2026
1 check passed
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.

1 participant