feat(slint): album-complement accent for the immersive lyrics-focus line
The focus line used the cover's dominant hue (spectrum-primary), which matched the atmosphere (built from the same cover) and blended in. Derive a contrast accent instead: immersive::lyrics_accent_color takes the cover's coverage-dominant hue and rotates it to the complement (+180deg), vivid and mid-bright, with a teal fallback for B&W covers; exposed as ImmersiveState.lyrics-accent and set on every cover decode. cc
This commit is contained in:
4 files changed
+76
-8
No files matched your search
@@ -158,6 +158,58 @@ pub fn spectrum_colors(pixels: &[u8], width: u32, height: u32) -> (Color, Color)
|
||||
)
|
||||
}
|
||||
|
||||
/// Immersive lyrics-focus accent: a color DERIVED from the album art but
|
||||
/// chosen to CONTRAST with the atmosphere background (which is itself built
|
||||
/// from the same cover). Using the cover's dominant hue (e.g. `spectrum-primary`)
|
||||
/// fails on monochromatic covers — the text lands the same tone as its own
|
||||
/// background and disappears. So we take the cover's coverage-dominant hue and
|
||||
/// rotate it to its COMPLEMENT (+180°), forced vivid + mid-bright so the single
|
||||
/// focus line reads against the warm/dark atmosphere (owner-reported: a warm
|
||||
/// cover gave salmon-on-orange). A near-grey (B&W) cover has no usable hue, so
|
||||
/// it falls back to a fixed high-contrast teal.
|
||||
pub fn lyrics_accent_color(pixels: &[u8], width: u32, height: u32) -> Color {
|
||||
let default = Color::from_rgb_u8(0x3f, 0xd9, 0xc8); // bright teal
|
||||
let Some(src) = RgbaImage::from_raw(width, height, pixels.to_vec()) else {
|
||||
return default;
|
||||
};
|
||||
let tiny = imageops::resize(&src, 16, 16, imageops::FilterType::Triangle);
|
||||
|
||||
// Coverage-weighted dominant hue (same binning as spectrum_colors: one vote
|
||||
// per chromatic pixel, so the perceived dominant tone wins over a speck).
|
||||
const BINS: usize = 24;
|
||||
let mut hist = [0.0f32; BINS];
|
||||
let mut chromatic = 0u32;
|
||||
for px in tiny.pixels() {
|
||||
let (h, s, l) = rgb_to_hsl(px[0], px[1], px[2]);
|
||||
if !(0.10..=0.93).contains(&l) || s < 0.08 {
|
||||
continue;
|
||||
}
|
||||
let bin = ((h / 360.0 * BINS as f32) as usize).min(BINS - 1);
|
||||
hist[bin] += 1.0;
|
||||
chromatic += 1;
|
||||
}
|
||||
// Effectively B&W cover -> no honest album hue to complement.
|
||||
if chromatic < 4 {
|
||||
return default;
|
||||
}
|
||||
let score_at = |i: usize| hist[i] + 0.5 * (hist[(i + BINS - 1) % BINS] + hist[(i + 1) % BINS]);
|
||||
let mut best_i = 0usize;
|
||||
let mut best = -1.0f32;
|
||||
for i in 0..BINS {
|
||||
let sc = score_at(i);
|
||||
if sc > best {
|
||||
best = sc;
|
||||
best_i = i;
|
||||
}
|
||||
}
|
||||
let dominant_hue = (best_i as f32 + 0.5) * (360.0 / BINS as f32);
|
||||
// Complement = guaranteed contrast against the dominant tone the atmosphere
|
||||
// is built from. Vivid + mid-bright so it reads on the dark/warm field.
|
||||
let accent_hue = (dominant_hue + 180.0).rem_euclid(360.0);
|
||||
let (r, g, b) = hsl_to_rgb(accent_hue, 0.85, 0.62);
|
||||
Color::from_rgb_u8(r, g, b)
|
||||
}
|
||||
|
||||
/// Dominant swatch of a cover, for the single-cover playlist card letterbox.
|
||||
///
|
||||
/// Mirrors Tauri's `extractPalette().dominant`: the card uses `image-fit:
|
||||
|
||||
@@ -1228,6 +1228,7 @@ fn load_now_playing_artwork_large(weak: slint::Weak<AppWindow>, art: qbz_models:
|
||||
crate::immersive::spectrum_colors(&pixels, w, h);
|
||||
imm.set_spectrum_primary(spec_primary);
|
||||
imm.set_spectrum_secondary(spec_secondary);
|
||||
imm.set_lyrics_accent(crate::immersive::lyrics_accent_color(&pixels, w, h));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
// ROOT (corrupts absolute positioning — the dim/fade lives on the inner text);
|
||||
// no `changed x/y/width/height` watchers.
|
||||
|
||||
import { LyricsState } from "../state.slint";
|
||||
import { LyricsState, ImmersiveState } from "../state.slint";
|
||||
|
||||
export component ImmersiveLyricsFocusPanel inherits Rectangle {
|
||||
in property <length> viewport-width: 1280px;
|
||||
@@ -99,7 +99,12 @@ export component ImmersiveLyricsFocusPanel inherits Rectangle {
|
||||
// skipped per recon §3 Slint note). Centered in the wrapper.
|
||||
if root.has-current: Text {
|
||||
text: root.current-line;
|
||||
color: #ffffff;
|
||||
// The single highlighted line takes an ALBUM-ART accent that is
|
||||
// the COMPLEMENT of the cover's dominant hue, so it contrasts
|
||||
// with the atmosphere (built from the same cover) instead of
|
||||
// blending into it — NOT the UI lyrics color, NOT plain white
|
||||
// (owner request + owner-reported salmon-on-orange blend fix).
|
||||
color: ImmersiveState.lyrics-accent;
|
||||
font-size: root.line-size;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.2px;
|
||||
|
||||
@@ -3303,14 +3303,24 @@ export global ImmersiveState {
|
||||
// Defaults = the Svelte cyan -> purple until the art resolves.
|
||||
in property <color> spectrum-primary: #00dcc8;
|
||||
in property <color> spectrum-secondary: #9632ff;
|
||||
// Lyrics-focus single-line accent: derived from the album art but rotated
|
||||
// to the COMPLEMENT of the cover's dominant hue, so it contrasts with the
|
||||
// atmosphere (which is built from the same cover) instead of blending into
|
||||
// it. Default high-contrast teal until the art resolves / for B&W covers.
|
||||
in property <color> lyrics-accent: #3fd9c8;
|
||||
|
||||
// WGPU UNDERLAY SPIKE: a GPU fragment shader rendered into a wgpu texture by
|
||||
// GPU fragment-shader underlay: a WGSL shader rendered into a wgpu texture by
|
||||
// src/shader_underlay.rs and handed back here each drain tick. `shader-mode`
|
||||
// selects the scene: 0 = OFF (use the existing atmosphere + panels), >0 = a
|
||||
// shader scene (1 = plasma spike). When >0 the atmosphere + the mode panels
|
||||
// are hidden so the shader is the visible background; the auto-hide chrome
|
||||
// (mode picker + compact player) stays on top. Toggle in-view with the 'g'
|
||||
// key during the spike.
|
||||
// selects the scene:
|
||||
// 0 = OFF — use the existing atmosphere + visualizer panels.
|
||||
// 1 = Plasma — classic sin-field plasma (ui/shaders/plasma.wgsl).
|
||||
// 2 = Tunnel — neon polar-warped tunnel (ui/shaders/tunnel.wgsl).
|
||||
// 3 = Aurora — domain-warped aurora curtains (ui/shaders/aurora.wgsl).
|
||||
// Each scene maps to shader_underlay pipeline index (shader-mode - 1). When
|
||||
// shader-mode > 0 the atmosphere + the mode panels are hidden so the shader
|
||||
// is the visible background; the auto-hide chrome (scene picker + compact
|
||||
// player) stays on top. Pick a scene via the header shader picker, or cycle
|
||||
// 0->1->2->3->0 with the 'g' key.
|
||||
in property <image> shader-texture;
|
||||
in-out property <int> shader-mode: 0;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user