about summary refs log tree commit diff
path: root/src/selection.rs
diff options
context:
space:
mode:
authorgennyble <gen@nyble.dev>2024-06-10 16:37:13 -0500
committergennyble <gen@nyble.dev>2024-06-10 16:37:13 -0500
commit67eefd43795320043915d3527fd2716986e049d7 (patch)
tree9b5519b43c887b8740d68963c83b48d9de0783a6 /src/selection.rs
parent8a131a03374f751e166c454d3d55c8aa88922702 (diff)
parent8ab1c9604a5d167d8746e7c641458c406135cb5c (diff)
downloadcolorsquash-67eefd43795320043915d3527fd2716986e049d7.tar.gz
colorsquash-67eefd43795320043915d3527fd2716986e049d7.zip
Merge branch 'feature/highest-bits-selector'
Diffstat (limited to 'src/selection.rs')
-rw-r--r--src/selection.rs24
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()
+	}
+}