imagezero 0.0.1

Pure Rust implementation of the imagezero (losless image compression algorithm) used i.e. in robotics.
Documentation
// ------------------------------------------------------------------------------
// Copyright 2023 Uwe Arzt, mail@uwe-arzt.de
// SPDX-License-Identifier: Apache-2.0
// ------------------------------------------------------------------------------

#[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);

        // input image
        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);

        // input image
        let mut iz = File::open(iz).unwrap();
        let mut buffer = Vec::new();
        iz.read_to_end(&mut buffer).unwrap();
    }
}