about summary refs log tree commit diff
path: root/squash/src/main.rs
diff options
context:
space:
mode:
authorgennyble <gen@nyble.dev>2024-01-14 07:33:52 -0600
committergennyble <gen@nyble.dev>2024-01-14 07:33:52 -0600
commit88656a81d8e1480c3e37a3402901525aee1a596c (patch)
tree3263cc0726b8b05981c11083473e271a2f82d0c8 /squash/src/main.rs
parent2b3181f3c4675d744338f497564faa00bc5d76db (diff)
downloadcolorsquash-88656a81d8e1480c3e37a3402901525aee1a596c.tar.gz
colorsquash-88656a81d8e1480c3e37a3402901525aee1a596c.zip
allow choosing selection algorithm
Diffstat (limited to 'squash/src/main.rs')
-rw-r--r--squash/src/main.rs24
1 files changed, 16 insertions, 8 deletions
diff --git a/squash/src/main.rs b/squash/src/main.rs
index 8e3a79b..b443f57 100644
--- a/squash/src/main.rs
+++ b/squash/src/main.rs
@@ -1,5 +1,8 @@
 use cli::DifferenceFn;
-use colorsquash::SquasherBuilder;
+use colorsquash::{
+	selection::{Kmeans, Selector, SortSelect},
+	SquasherBuilder,
+};
 
 use crate::cli::{InType, OutType};
 
@@ -16,15 +19,20 @@ fn main() -> Result<(), anyhow::Error> {
 		InType::Jpeg => image::get_jpg(cli.input)?,
 	};
 
-	let mut builder = SquasherBuilder::default().max_colors(cli.color_count);
+	let mut builder = SquasherBuilder::new()
+		.max_colors(cli.color_count)
+		.mapper_difference(cli.difference);
 
-	if let Some(tol) = cli.tolerance {
-		builder = builder.tolerance(tol);
-	}
+	match cli.selector {
+		cli::Selector::SortSelect => {
+			let mut sorsel = SortSelect::default().difference(cli.difference);
+			if let Some(tol) = cli.tolerance {
+				sorsel = sorsel.tolerance(tol)
+			}
 
-	builder = match cli.difference {
-		DifferenceFn::Rgb => builder.difference(&colorsquash::difference::rgb),
-		DifferenceFn::Redmean => builder.difference(&colorsquash::difference::redmean),
+			builder = builder.selector(sorsel);
+		}
+		cli::Selector::Kmeans => builder = builder.selector(Kmeans),
 	};
 
 	let mut squasher = builder.build(&image.data);