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