use clap::Parser;
use image::{ImageBuffer, Rgb};
use palette_bin::args::{Cli, Commands};
use palette_bin::palette::apply_palette;
use palette_bin::resize::resize_image;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let args = Cli::parse();
let img = image::open(&args.input)?.to_rgb8();
match args.command {
Commands::Resize {
ratio_mode,
width,
height,
} => {
let resized_img = resize_image(img, ratio_mode, width, height);
resized_img.save(&args.output)?;
}
Commands::Palette { palette } => {
let paletted_img = apply_palette(img, &palette)?;
paletted_img.save(&args.output)?;
}
Commands::Test {} => {
let mut img = ImageBuffer::new(2, 2);
for (x, y, pixel) in img.enumerate_pixels_mut() {
let r = (x * 255 / 1) as u8;
let g = (y * 255 / 1) as u8;
let b = ((x + y) * 255 / (1 + 1)) as u8;
*pixel = Rgb([r, g, b]);
}
img.save(&args.output)?;
}
}
Ok(())
}