onix 0.2.0

Decode image files using V4L2
Documentation
use onix::Onix;
use std::fs::File;
use std::io::Write;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    env_logger::init();

    let args: Vec<_> = std::env::args().collect();
    if args.len() != 3 {
        eprintln!("Usage: {} <image.webp> <output.nv12>", args[0]);
        std::process::exit(1);
    }

    // Find all decoder devices available on the system.
    let decoder = Onix::find_devices()
        .expect("Unable to find a V4L2 M2M decoder corresponding to our criteria");

    // Decode the image at the provided path.
    let (mut decoder, mut image) = decoder.open(&args[1]).expect("Error decoding image");

    // Dequeue them, at this point the decoding should be done!
    decoder
        .dequeue(&mut image)
        .expect("Error while dequeuing buffers");

    // Then write the contents of the capture buffer into our output file.
    {
        let buf = image.cap_mut();
        let map = decoder.mmap(buf, 0)?;
        let mut output = File::create(&args[2])?;
        let slice = &map.as_slice()[..buf.bytesused(0) as usize];
        output.write_all(slice)?;
    }

    decoder.stop().expect("Error while stopping the encoding");

    Ok(())
}