about summary refs log tree commit diff
path: root/squash/src/main.rs
diff options
context:
space:
mode:
authorgennyble <gen@nyble.dev>2024-01-16 16:41:12 -0600
committergennyble <gen@nyble.dev>2024-01-16 16:41:12 -0600
commit0ea17ff4a961b9a28a1d1263e6dc792aa3ae3f34 (patch)
tree4f6bf1d6bf3d6aa90b97afafa0a28a49c681ffb5 /squash/src/main.rs
parent9c58d09402d57ef8bf03c98c3d8dac88da4aebea (diff)
downloadcolorsquash-0ea17ff4a961b9a28a1d1263e6dc792aa3ae3f34.tar.gz
colorsquash-0ea17ff4a961b9a28a1d1263e6dc792aa3ae3f34.zip
squash: allow selecting scale and print verbose
Diffstat (limited to 'squash/src/main.rs')
-rw-r--r--squash/src/main.rs31
1 files changed, 28 insertions, 3 deletions
diff --git a/squash/src/main.rs b/squash/src/main.rs
index 24d557f..c0cea51 100644
--- a/squash/src/main.rs
+++ b/squash/src/main.rs
@@ -1,3 +1,5 @@
+use std::time::Duration;
+
 use colorsquash::{
 	selection::{Kmeans, SortSelect},
 	SquasherBuilder,
@@ -34,11 +36,24 @@ fn main() -> Result<(), anyhow::Error> {
 		cli::Selector::Kmeans => builder = builder.selector(Kmeans { max_iter: 10 }),
 	};
 
-	let start = std::time::Instant::now();
-	let mut squasher = builder.build(&image.data);
-	println!("{:.2}ms", start.elapsed().as_secs_f32());
+	let mut start = std::time::Instant::now();
+	let mut squasher = builder.scale(cli.scale).build(&image.data);
+
+	if cli.verbose {
+		println!(
+			"Palette is {} colors.\nSelection took {}",
+			squasher.palette().len(),
+			human_time(start.elapsed())
+		);
+	}
 
+	start = std::time::Instant::now();
 	let size = squasher.map_over(&mut image.data);
+
+	if cli.verbose {
+		println!("Mapping took {}", human_time(start.elapsed()));
+	}
+
 	image.data.resize(size, 0);
 
 	match cli.out_type {
@@ -46,3 +61,13 @@ fn main() -> Result<(), anyhow::Error> {
 		OutType::Gif => image::save_gif(image, squasher, cli.output),
 	}
 }
+
+fn human_time(duration: Duration) -> String {
+	if duration.as_secs() > 0 {
+		format!("{:.2}s", duration.as_secs_f32())
+	} else if duration.as_millis() >= 10 {
+		format!("{}ms", duration.as_millis())
+	} else {
+		format!("{}μs", duration.as_micros())
+	}
+}