diff options
author | Devon Sawatsky <novedevo@gmail.com> | 2024-01-24 21:53:17 -0800 |
---|---|---|
committer | Devon Sawatsky <novedevo@gmail.com> | 2024-01-24 21:53:17 -0800 |
commit | 8ab1c9604a5d167d8746e7c641458c406135cb5c (patch) | |
tree | 0bdbac2a3c5af6f1545f453865acee7ffa1ec939 /src/selection.rs | |
parent | 17af2884f76fb0de1d9ea27ffb2ee966730cb986 (diff) | |
download | colorsquash-8ab1c9604a5d167d8746e7c641458c406135cb5c.tar.gz colorsquash-8ab1c9604a5d167d8746e7c641458c406135cb5c.zip |
add HighestBits selector
Diffstat (limited to 'src/selection.rs')
-rw-r--r-- | src/selection.rs | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/selection.rs b/src/selection.rs index c4a0285..41e0254 100644 --- a/src/selection.rs +++ b/src/selection.rs @@ -1,4 +1,4 @@ -use std::collections::HashMap; +use std::collections::{HashMap, HashSet}; #[cfg(not(feature = "simd-kmeans"))] use crate::nih_kmeans::KMeans; @@ -332,3 +332,25 @@ impl Default for HeuristicSorsel { } } } + +pub struct HighestBits {} + +impl Selector for HighestBits { + fn select(&mut self, max_colors: usize, image: ImageData) -> Vec<RGB8> { + let max_bits = max_colors.next_power_of_two().ilog2() / 3; + let shift = 8 - max_bits; + image + .0 + .iter() + .map(|color| { + RGB8::new( + color.r >> shift << shift, + color.g >> shift << shift, + color.b >> shift << shift, + ) + }) + .collect::<HashSet<_>>() + .into_iter() + .collect() + } +} |