fix(slint): immersive spectrum colors use the album's real palette
spectrum_colors derived the secondary gradient colour as dom_hue + 55deg, which fabricated a hue the cover does not contain (a mono pink/magenta cover became pink->orange). Use real album colours: a second genuine hue cluster when the cover has one (>=45deg from the primary, >=35% of the peak mass), otherwise the same dominant hue deeper + more saturated. Mono-colour covers now read as a one-hue light->deep gradient. cc
This commit is contained in:
1 file changed
+39
-7
@@ -93,20 +93,52 @@ pub fn spectrum_colors(pixels: &[u8], width: u32, height: u32) -> (Color, Color)
|
||||
return default;
|
||||
}
|
||||
|
||||
// Most ABUNDANT hue cluster: the peak bin plus its circular neighbours.
|
||||
// Smoothed cluster score for a bin (peak + circular neighbours).
|
||||
let score_at = |i: usize| hist[i] + 0.5 * (hist[(i + BINS - 1) % BINS] + hist[(i + 1) % BINS]);
|
||||
|
||||
// PRIMARY = most abundant hue cluster.
|
||||
let mut best_i = 0usize;
|
||||
let mut best = -1.0f32;
|
||||
for i in 0..BINS {
|
||||
let score = hist[i] + 0.5 * (hist[(i + BINS - 1) % BINS] + hist[(i + 1) % BINS]);
|
||||
if score > best {
|
||||
best = score;
|
||||
let sc = score_at(i);
|
||||
if sc > best {
|
||||
best = sc;
|
||||
best_i = i;
|
||||
}
|
||||
}
|
||||
let dom_hue = (best_i as f32 + 0.5) * (360.0 / BINS as f32);
|
||||
let primary_hue = (best_i as f32 + 0.5) * (360.0 / BINS as f32);
|
||||
|
||||
let primary = hsl_to_rgb(dom_hue, 0.85, 0.56);
|
||||
let secondary = hsl_to_rgb((dom_hue + 55.0).rem_euclid(360.0), 0.92, 0.62);
|
||||
// SECONDARY = a SECOND genuine hue cluster, at least ~45° away from the
|
||||
// primary and carrying real mass (>= 35% of the peak). If the cover is
|
||||
// essentially one colour (e.g. the mono pink/magenta Caifanes cover) there
|
||||
// is NO honest second hue — derive the secondary from the SAME hue, just
|
||||
// deeper + more saturated, instead of fabricating a hue-rotated colour the
|
||||
// album doesn't contain (the old `+55°` turned a pink cover into pink→orange).
|
||||
let mut sec_i: Option<usize> = None;
|
||||
let mut sec_best = 0.0f32;
|
||||
for i in 0..BINS {
|
||||
let circ = (i as i32 - best_i as i32).rem_euclid(BINS as i32);
|
||||
let dist = circ.min(BINS as i32 - circ); // circular distance in bins
|
||||
if dist < 3 {
|
||||
continue; // keep >= ~45° away from the primary
|
||||
}
|
||||
let sc = score_at(i);
|
||||
if sc > sec_best {
|
||||
sec_best = sc;
|
||||
sec_i = Some(i);
|
||||
}
|
||||
}
|
||||
|
||||
let primary = hsl_to_rgb(primary_hue, 0.85, 0.58);
|
||||
let secondary = match sec_i.filter(|_| sec_best >= best * 0.35) {
|
||||
// Two genuinely different album colours → gradient between them.
|
||||
Some(si) => {
|
||||
let sec_hue = (si as f32 + 0.5) * (360.0 / BINS as f32);
|
||||
hsl_to_rgb(sec_hue, 0.88, 0.62)
|
||||
}
|
||||
// Single-colour cover → same hue, deeper (stays on-album).
|
||||
None => hsl_to_rgb(primary_hue, 0.95, 0.40),
|
||||
};
|
||||
(
|
||||
Color::from_rgb_u8(primary.0, primary.1, primary.2),
|
||||
Color::from_rgb_u8(secondary.0, secondary.1, secondary.2),
|
||||
|
||||
Reference in new issue
Block a user