fix(color): only colour 7 swaps with the background; true colours draw as authored

Every near-white colour turned black on a light background (and near-black
white on a dark one), including true colours. A 255,255,255 solid used as a
white mask became a black block. Now only colour 7 swaps: true colours and
ACI 255 resolve a hair off pure white/black and keep their value on screen
and in plots.

Discussion #1500

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Hakan SevenandClaude Opus 5.5 committed 2026-09-29 06:16:18 +03:00
1 parent ac2a1e1166
commit 60f35e2b1d
7 files changed
+83 -30

No files matched your search

+5 -2
View File
@@ -3774,8 +3774,11 @@ pub(crate) fn render_style_for_block_sub_viewport(
/// backgrounds become white. All other colors pass through unchanged.
pub(crate) fn adapt_to_bg(color: [f32; 4], bg: [f32; 4]) -> [f32; 4] {
let lum = 0.299 * bg[0] + 0.587 * bg[1] + 0.114 * bg[2];
let is_white = color[0] > 0.95 && color[1] > 0.95 && color[2] > 0.95;
let is_black = color[0] < 0.05 && color[1] < 0.05 && color[2] < 0.05;
// Only exact white / black swap: that is colour 7 (and interface colours).
// Authored colours reach here nudged off both, so they stay as drawn —
// a true-colour white mask on a light sheet remains white. (#1500)
let is_white = color[..3] == [1.0; 3];
let is_black = color[..3] == [0.0; 3];
if is_white && lum > 0.5 {
[0.0, 0.0, 0.0, color[3]]
} else if is_black && lum <= 0.5 {