diff options
author | gennyble <gen@nyble.dev> | 2024-01-14 07:33:52 -0600 |
---|---|---|
committer | gennyble <gen@nyble.dev> | 2024-01-14 07:33:52 -0600 |
commit | 88656a81d8e1480c3e37a3402901525aee1a596c (patch) | |
tree | 3263cc0726b8b05981c11083473e271a2f82d0c8 /squash/src/main.rs | |
parent | 2b3181f3c4675d744338f497564faa00bc5d76db (diff) | |
download | colorsquash-88656a81d8e1480c3e37a3402901525aee1a596c.tar.gz colorsquash-88656a81d8e1480c3e37a3402901525aee1a596c.zip |
allow choosing selection algorithm
Diffstat (limited to 'squash/src/main.rs')
-rw-r--r-- | squash/src/main.rs | 24 |
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); |