diff options
Diffstat (limited to 'squash/src/main.rs')
-rw-r--r-- | squash/src/main.rs | 31 |
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()) + } +} |