Skip to content
Snippets Groups Projects
Verified Commit 8b788538 authored by Louis's avatar Louis :fire:
Browse files

Stub out reduce operation

parent f5331ed7
No related branches found
No related tags found
No related merge requests found
...@@ -2,7 +2,7 @@ use clap::Parser; ...@@ -2,7 +2,7 @@ use clap::Parser;
use serde::{Deserialize, Serialize}; 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::{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; use crate::load_image;
...@@ -33,9 +33,12 @@ pub enum Args { ...@@ -33,9 +33,12 @@ pub enum Args {
#[clap(name = "remap")] #[clap(name = "remap")]
#[serde(alias = "remap")] #[serde(alias = "remap")]
Remap(Remap), Remap(Remap),
#[clap(name = "remap")] #[clap(name = "pipeline")]
#[serde(alias = "remap")] #[serde(alias = "pipeline")]
Pipeline(Pipeline), Pipeline(Pipeline),
#[clap(name = "reduce")]
#[serde(alias = "reduce")]
Reduce(Reduce),
} }
impl Args { impl Args {
...@@ -85,6 +88,15 @@ impl Args { ...@@ -85,6 +88,15 @@ impl Args {
output.save(&remap.output).map_err(anyhow::Error::from) 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(), Args::Pipeline(pipeline) => pipeline.execute(),
} }
} }
......
...@@ -5,6 +5,7 @@ mod pipeline; ...@@ -5,6 +5,7 @@ mod pipeline;
mod remap; mod remap;
mod rotate; mod rotate;
mod scale; mod scale;
mod reduce;
pub use extrude::Extrude; pub use extrude::Extrude;
pub use flip::Flip; pub use flip::Flip;
...@@ -13,3 +14,4 @@ pub use pipeline::Pipeline; ...@@ -13,3 +14,4 @@ pub use pipeline::Pipeline;
pub use remap::Remap; pub use remap::Remap;
pub use rotate::Rotate; pub use rotate::Rotate;
pub use scale::Scale; pub use scale::Scale;
pub use reduce::Reduce;
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])
// }))
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment