Crates.io | qoiconv-rs |
lib.rs | qoiconv-rs |
version | 0.5.1 |
source | src |
created_at | 2023-03-14 20:07:51.09839 |
updated_at | 2023-03-14 20:07:51.09839 |
description | Convert between different image formats and qoi format. |
homepage | |
repository | https://github.com/lexeyOK/qoiconv-rs |
max_upload_size | |
id | 810112 |
size | 44,100 |
Cli to convert between image formats and qoi. Attempt to port qoi.h
to rust-lang.
$ 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
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();
}
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
.