about summary refs log tree commit diff
path: root/squash/src/main.rs
diff options
context:
space:
mode:
authorgennyble <gen@nyble.dev>2024-01-12 12:08:19 -0600
committergennyble <gen@nyble.dev>2024-01-12 12:08:19 -0600
commit0ec3c8d1c51ea2286e7762f3a3d1cbebd7700f50 (patch)
treeb51a97b76457299c0647232893a99991a9d17a6d /squash/src/main.rs
parent093bb9d6889f6e026f14edc04e2f79bdea3c0b56 (diff)
downloadcolorsquash-0ec3c8d1c51ea2286e7762f3a3d1cbebd7700f50.tar.gz
colorsquash-0ec3c8d1c51ea2286e7762f3a3d1cbebd7700f50.zip
squash: fix tolerance and add algorithm selection
Diffstat (limited to 'squash/src/main.rs')
-rw-r--r--squash/src/main.rs15
1 files changed, 12 insertions, 3 deletions
diff --git a/squash/src/main.rs b/squash/src/main.rs
index 8b77b47..5437ea1 100644
--- a/squash/src/main.rs
+++ b/squash/src/main.rs
@@ -1,4 +1,5 @@
-use colorsquash::Squasher;
+use cli::DifferenceFn;
+use colorsquash::{Squasher, SquasherBuilder};
 
 use crate::cli::{InType, OutType};
 
@@ -7,6 +8,7 @@ mod image;
 
 fn main() -> Result<(), anyhow::Error> {
 	//gen: I should use clap or at least getopt, but this is fine.
+	//gen: I like experimenting with the cli :)
 	let cli = cli::build();
 
 	let mut image = match cli.in_type {
@@ -14,12 +16,19 @@ fn main() -> Result<(), anyhow::Error> {
 		InType::Jpeg => image::get_jpg(cli.input)?,
 	};
 
-	let mut squasher = Squasher::new(cli.color_count, &image.data);
+	let mut builder = SquasherBuilder::default().max_colors(cli.color_count);
 
 	if let Some(tol) = cli.tolerance {
-		squasher.set_tolerance(tol);
+		builder = builder.tolerance(tol);
 	}
 
+	builder = match cli.difference {
+		DifferenceFn::Rgb => builder.difference(&colorsquash::difference::rgb_difference),
+		DifferenceFn::Redmean => builder.difference(&colorsquash::difference::redmean_difference),
+	};
+
+	let mut squasher = builder.build(&image.data);
+
 	let size = squasher.map_over(&mut image.data);
 	image.data.resize(size, 0);