diff options
author | gennyble <gen@nyble.dev> | 2024-06-10 16:37:13 -0500 |
---|---|---|
committer | gennyble <gen@nyble.dev> | 2024-06-10 16:37:13 -0500 |
commit | 67eefd43795320043915d3527fd2716986e049d7 (patch) | |
tree | 9b5519b43c887b8740d68963c83b48d9de0783a6 | |
parent | 8a131a03374f751e166c454d3d55c8aa88922702 (diff) | |
parent | 8ab1c9604a5d167d8746e7c641458c406135cb5c (diff) | |
download | colorsquash-67eefd43795320043915d3527fd2716986e049d7.tar.gz colorsquash-67eefd43795320043915d3527fd2716986e049d7.zip |
Merge branch 'feature/highest-bits-selector'
-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() + } +} |