#[macro_use]
extern crate clap;
use clap::Arg;
use std::fs::File;
use std::io::Read;
fn main() {
let matches = command!()
.arg(
arg!(<ACTION>)
.help("compress/decompress")
.value_parser(["c", "d"]),
)
.arg(Arg::new("INPUTFILE").required(true))
.arg(Arg::new("OUTPUTFILE").required(true))
.get_matches();
let infile = matches.get_one::<String>("INPUTFILE").unwrap();
let outfile = matches.get_one::<String>("OUTPUTFILE").unwrap();
match matches.get_one::<String>("ACTION").unwrap().as_str() {
"c" => {
compress(infile, outfile);
}
"d" => {
decompress(infile, outfile);
}
_ => unreachable!(),
}
fn compress(ppm: &str, iz: &str) {
println!("compress {} to {}", ppm, iz);
let img = image::open(ppm).unwrap();
if img.color() != image::ColorType::Rgb8 {
println!("Wrong image format");
}
let rgb = img.into_rgb8();
let (_width, _height) = rgb.dimensions();
}
fn decompress(iz: &str, ppm: &str) {
println!("decompress {} to {}", iz, ppm);
let mut iz = File::open(iz).unwrap();
let mut buffer = Vec::new();
iz.read_to_end(&mut buffer).unwrap();
}
}