Skip to content

Commit

Permalink
Tweak alpha factor in luma sort
Browse files Browse the repository at this point in the history
  • Loading branch information
andrews05 committed May 31, 2023
1 parent 2d3de7b commit 8ba2782
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/reduction/palette.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ pub fn sorted_palette(png: &PngImage) -> Option<PngImage> {
enumerated.sort_by(|a, b| {
// Sort by ascending alpha and descending luma
let color_val = |color: &RGBA8| {
((color.a as i32) << 18)
let a = i32::from(color.a);
// Use a high factor for alpha to ensure they get sorted first,
// but allow neighboring values to fall through to the luma sort
((a / 2) << 18) + a
// These are coefficients for standard sRGB to luma conversion
- i32::from(color.r) * 299
- i32::from(color.g) * 587
Expand Down

0 comments on commit 8ba2782

Please sign in to comment.