qoiconv-rs

Crates.ioqoiconv-rs
lib.rsqoiconv-rs
version0.5.1
sourcesrc
created_at2023-03-14 20:07:51.09839
updated_at2023-03-14 20:07:51.09839
descriptionConvert between different image formats and qoi format.
homepage
repositoryhttps://github.com/lexeyOK/qoiconv-rs
max_upload_size
id810112
size44,100
lexx (lexeyOK)

documentation

README

qoiconv-rs

Cli to convert between image formats and qoi. Attempt to port qoi.h to rust-lang.

Usage of qoiconv-rs

$ cargo install qoiconv-rs
$ qoiconv-rs -i input.png -o output.qoi # convert form image to qoi
$ qoiconv-rs -i input.qoi -o output.png # convert from qoi to image 

Usage

Copy qoi.rs to your source file and add it as a mod.

Example of decoding pixels from .qoi file:

use std::fs::File;
use std::io::BufReader;
mod qoi;
use qoi::*;

fn main() {
    // load file and get bytes (use `BufReader` to speed up reads)
    let file = File::open("wikipedia_008.qoi").unwrap();
    let mut bytes = BufReader::new(file);

    // get pixels and descriptor
    let (data, desc) = qoi_decode(bytes, None).unwrap();
}

Example of encoding pixels into .qoi file:

use std::fs::File;
use std::io::Write;
mod qoi;
use qoi::*;
fn main() {
    // get pixels and make valid descriptor
    // pixels must be laid out in order RGB(A)
    let pixels = [255, 0, 0, 15, 1, 255, 255, 255, 191, 255, 0, 0, 15, 1, 74];
    let desc = QoiDescriptor {
        width: pixels.len() / 3,
        height: 1,
        channels: ChanelMode::Rgb,
        colorspace: Colorspace::Linear,
    };

    let bytes = qoi_encode(&pixels, &desc).unwrap();

    let mut f = File::create("example.qoi").unwrap();
    f.write_all(bytes.as_slice()).unwrap();
}

Testing, fuzzing, benches, profile

Use cargo to test and fuzz the program (you'll need to install cargo-fuzz):

cargo test
# install cargo-fuzz with `cargo install cargo-fuzz`
cargo fuzz run qoi-test-pixels

To run benches against c test program run:

TODO implement new benchmark to compare against c

This implementation is 2x slower then c implementation probably due to smaller buffer size of BufReader.

Commit count: 33

cargo fmt