Skip to content

Commit

Permalink
Color comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski committed Sep 10, 2019
1 parent 1b4dcad commit a1d05e6
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/reduction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,16 @@ pub fn reduced_palette(png: &PngImage) -> Option<PngImage> {
let mut used_enumerated : Vec<(usize, &bool)>= used.iter().enumerate().collect();
used_enumerated.sort_by(|a, b| {
//Sort by ascending alpha and descending luma.
let color_val = |palette : &Vec<rgb::RGBA<u8>>, i| {
let color = palette.get(i).cloned()
let color_val = |i| {
let color = palette.get(i).copied()
.unwrap_or_else(|| RGBA8::new(0, 0, 0, 255));
let mut result = (color.a as i32) << 18;
result -= (color.r as i32) * 299;
result -= (color.g as i32) * 587;
result -= (color.b as i32) * 114;
result
((color.a as i32) << 18)
// These are coefficients for standard sRGB to luma conversion
- (color.r as i32) * 299
- (color.g as i32) * 587
- (color.b as i32) * 114
};
color_val(palette, a.0).cmp(&color_val(palette, b.0))
color_val(a.0).cmp(&color_val(b.0))
});

let mut next_index = 0u16;
Expand Down

0 comments on commit a1d05e6

Please sign in to comment.