diff --git a/src/cli_args.rs b/src/cli_args.rs index 717b77ccafea07f0f8338543e498594e0ec64b7d..2d8923f2853acde71095b88031407327fc7c2725 100644 --- a/src/cli_args.rs +++ b/src/cli_args.rs @@ -2,7 +2,7 @@ use clap::Parser; use serde::{Deserialize, Serialize}; // use crate::commands::{calculate_mapping, execute_pipeline, extrude, flip, palette, remap_image, rescale, rotate, write_palette, FlipDirection, RotateDegree, Rotate}; -use crate::commands::{Extrude, Flip, Palette, Pipeline, Remap, Rotate, Scale}; +use crate::commands::{Extrude, Flip, Palette, Pipeline, Reduce, Remap, Rotate, Scale}; use crate::load_image; @@ -33,9 +33,12 @@ pub enum Args { #[clap(name = "remap")] #[serde(alias = "remap")] Remap(Remap), - #[clap(name = "remap")] - #[serde(alias = "remap")] + #[clap(name = "pipeline")] + #[serde(alias = "pipeline")] Pipeline(Pipeline), + #[clap(name = "reduce")] + #[serde(alias = "reduce")] + Reduce(Reduce), } impl Args { @@ -85,6 +88,15 @@ impl Args { output.save(&remap.output).map_err(anyhow::Error::from) } + Args::Reduce(reduce) => { + if let Some(amount) = reduce.colours { + log::info!("Num cols {}", amount); + } else { + log::info!("No Limit"); + } + + Ok(()) + } Args::Pipeline(pipeline) => pipeline.execute(), } } diff --git a/src/commands/mod.rs b/src/commands/mod.rs index f54759816d033750adb8144beb52bbb147f72e7c..b9cf99709e2b19afb44a6198c3793d44e51acaf5 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -5,6 +5,7 @@ mod pipeline; mod remap; mod rotate; mod scale; +mod reduce; pub use extrude::Extrude; pub use flip::Flip; @@ -13,3 +14,4 @@ pub use pipeline::Pipeline; pub use remap::Remap; pub use rotate::Rotate; pub use scale::Scale; +pub use reduce::Reduce; diff --git a/src/commands/reduce.rs b/src/commands/reduce.rs new file mode 100644 index 0000000000000000000000000000000000000000..44f739df725729ccf1a8641dfdbfe0722b14e1b7 --- /dev/null +++ b/src/commands/reduce.rs @@ -0,0 +1,47 @@ +use crate::commands::palette::ColourMapping; +use crate::commands::Palette; +use crate::utils::{RgbaOutputFormat, TypedOutputFormat}; +use anyhow::Error; +use clap::Parser; +use image::{GenericImage, ImageBuffer, Rgba, RgbaImage}; +use serde::{Deserialize, Serialize}; +use std::collections::HashMap; + +/// Limit the number of colours by quantity or threshold +#[derive(Debug, Clone, Parser, Serialize, Deserialize)] +#[clap(author, version = "0.3.0")] +pub struct Reduce { + /// The path to the image file + #[serde(default)] + pub input: String, + /// The path to write the recoloured image + #[serde(default)] + pub output: String, + + /// The number of colours to use for quantizing + #[clap(short, long)] + pub colours: Option<u32>, + /// The colour difference threshold to limit colour reduction + #[clap(short, long)] + pub threshold: Option<f32>, +} + +impl Reduce { + pub fn run<T: GenericImage>(&self, mut image: &T) -> anyhow::Result<RgbaOutputFormat> { + Err(Error::msg("Reduce is not implemented")) + + // TODO: Reduce impl + // let mut palette = Palette::extract_from(image)?; + // + // let similarity = HashMap::with_capacity(palette.len()); + // let mapping: ColourMapping = ColourMapping::new(); + // + // while !palette.is_empty() { + // let next = palette.pop(); + // } + // + // Ok(RgbaImage::from_fn(image.width(), image.height(), |x, y| { + // Rgba::from([0, 0, 0, 0]) + // })) + } +}