Skip to content

A Rust encoder/decoder for Dominic Szablewski's QOI format for fast, lossless image compression.

License

Notifications You must be signed in to change notification settings

ChevyRay/qoi_rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

QOI - The “Quite OK Image” format

This is a Rust encoder and decoder for Dominic Szablewski's QOI format for fast, lossless image compression. See the QOI File Format Specification for more details.

This was ported from Dominic's original C code, but modified to be much more idiomatic in Rust.

QOI encodes and decodes images in a lossless format. An encoded QOI image is usually around 10-30% larger than a decently optimized PNG image.

QOI outperforms simpler PNG encoders in compression ratio and performance. QOI images are typically 20% smaller than PNGs written with stbi_image but 10% larger than with libpng. Encoding is 25-50x faster and decoding is 3-4x faster than stbi_image or libpng.

Usage

You can call encode() to encode an image. You supply it with an iterator of Pixel values, and a writer to output to.

use std::num::NonZeroUsize;
use qoi::Pixel;

// Create a 512x256 red image here to demonstrate
let width = 512;
let height = 256;
let mut pixels: Vec<Pixel> = Vec::new();
pixels.resize(width * height, Pixel::rgba(255, 0, 0, 255));

// Encode the image and write it to a file
let file = File::create("my_image.qoi").unwrap();
qoi::encode(
    NonZeroUsize::new(width).unwrap(),
    NonZeroUsize::new(height).unwrap(),
    pixels.into_iter(),
    BufWriter::new(file),
)
.unwrap();

There are several helpful decode functions, here's the inverse of the above:

use qoi::Pixel;

let mut pixels: Vec<Pixel> = Vec::new();
let (width, height) = 
    qoi::decode_file_into_vec("my_image.qoi", &mut pixels)
    .unwrap();

About

A Rust encoder/decoder for Dominic Szablewski's QOI format for fast, lossless image compression.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages