From 0a2f02a0a4cf9d3466e269d8914ac4fa45c4121c Mon Sep 17 00:00:00 2001 From: "R.Eugenio" Date: Tue, 30 Dec 2025 21:29:01 +0100 Subject: [PATCH] fix(colors): Correct perceptual correction threshold MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changed threshold from 0.45 to 0.15 so that: - Blue (~0.07 luminance) gets boost to avoid "goes to black" effect - Red (~0.21 luminance) is NOT affected (already darkens nicely) This fixes the issue where red panels became too saturated. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- src/core/style.zig | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/core/style.zig b/src/core/style.zig index edef985..490e949 100644 --- a/src/core/style.zig +++ b/src/core/style.zig @@ -42,9 +42,10 @@ pub fn isFancy() bool { // ============================================================================= /// Enable perceptual correction for panel colors. -/// NOTE: Desactivado por defecto - la lógica actual boostea el rojo cuando -/// debería compensar el azul. Requiere revisión del algoritmo. -var perceptual_correction_enabled: bool = false; +/// When enabled, colors with VERY low perceived luminance (e.g., blue ~0.07) +/// get a boost to avoid going to black when darkened. +/// Colors like red (~0.21) are NOT affected as they darken well naturally. +var perceptual_correction_enabled: bool = true; /// Get whether perceptual correction is enabled pub fn isPerceptualCorrectionEnabled() bool { @@ -1076,15 +1077,15 @@ fn deriveDarkPalette(base: Color) PanelColorScheme { const gray = Color.rgb(128, 128, 128); const dark_border = Color.rgb(60, 60, 65); - // Perceptual correction: boost low-luminance colors to match visual contrast - // Reference: laravel_blue has luminance ~0.48, we use 0.45 as target + // Perceptual correction: only for colors with VERY low luminance (like pure blue ~0.07) + // Red (~0.21) is above threshold and won't be affected const base_lum = base.perceptualLuminance(); - const target_lum: f32 = 0.45; // Reference luminance (approximately blue) + const threshold: f32 = 0.15; // Only affect colors below this (blue=0.07, red=0.21) - // Calculate correction factor: if luminance is lower than target, reduce blend % - // This makes more of the base color visible, compensating for lower brightness - const correction: f32 = if (perceptual_correction_enabled and base_lum < target_lum) - @max(0.7, base_lum / target_lum) // Cap at 0.7 to avoid excessive boost + // Calculate correction factor: if luminance is VERY low, reduce blend % + // This makes more of the base color visible, preventing "goes to black" effect + const correction: f32 = if (perceptual_correction_enabled and base_lum < threshold) + @max(0.75, base_lum / threshold) // Subtle boost for very dark colors else 1.0; @@ -1130,13 +1131,13 @@ fn deriveLightPalette(base: Color) PanelColorScheme { const gray = Color.rgb(128, 128, 128); const light_border = Color.rgb(220, 220, 225); - // Perceptual correction: boost low-luminance colors to match visual contrast - // In light mode, lower blend % means more base color visible + // Perceptual correction: only for colors with VERY low luminance (like pure blue ~0.07) + // Red (~0.21) is above threshold and won't be affected const base_lum = base.perceptualLuminance(); - const target_lum: f32 = 0.45; + const threshold: f32 = 0.15; // Only affect colors below this (blue=0.07, red=0.21) - const correction: f32 = if (perceptual_correction_enabled and base_lum < target_lum) - @max(0.7, base_lum / target_lum) + const correction: f32 = if (perceptual_correction_enabled and base_lum < threshold) + @max(0.75, base_lum / threshold) // Subtle boost for very dark colors else 1.0;