From 8ab1c9604a5d167d8746e7c641458c406135cb5c Mon Sep 17 00:00:00 2001 From: Devon Sawatsky Date: Wed, 24 Jan 2024 21:53:17 -0800 Subject: add HighestBits selector --- src/selection.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'src') 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 { + 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::>() + .into_iter() + .collect() + } +} -- cgit 1.4.1-3-g733a5