diff options
Diffstat (limited to 'src')
-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() + } +} |