Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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])
// }))
}
}