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

Overview

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();
You might also like...
An experimental gif encoder for Windows 10.
An experimental gif encoder for Windows 10.

giffun An experimental gif encoder for Windows 10. Resources Based on "Techniques for GPU-based Color Quantization" (2019) by Matthias Trapp, Sebastia

Rust library for fast image resizing with using of SIMD instructions.

fast_image_resize Rust library for fast image resizing with using of SIMD instructions. CHANGELOG Supported pixel formats and available optimisations:

Foxtrot is a fast viewer for STEP files, a standard interchange format for mechanical CAD
Foxtrot is a fast viewer for STEP files, a standard interchange format for mechanical CAD

Foxtrot is a fast viewer for STEP files, a standard interchange format for mechanical CAD. It is an experimental project built from the ground up, including new libraries for parsing and triangulation.

tai (Terminal Ascii Image) tool to convert images to ascii written in Rust
tai (Terminal Ascii Image) tool to convert images to ascii written in Rust

TAI Terminal Ascii Image A tool to convert images to ascii art written in Rust 🦀 Notes This tool is still in development stage. Contributions All Con

A simple image average color extractor written in 🦀 Rust

A simple image average color extractor written in 🦀 Rust

A simple command-line utility (and Rust crate!) for converting from a conventional image file (e.g. a PNG file) into a pixel-art version constructed with emoji
A simple command-line utility (and Rust crate!) for converting from a conventional image file (e.g. a PNG file) into a pixel-art version constructed with emoji

EmojiPix This is a simple command-line utility (and Rust crate!) for converting from a conventional image file (e.g. a PNG file) into a pixel-art vers

A Simple Image to Ascii converter in Rust
A Simple Image to Ascii converter in Rust

Image to Ascii A Simple Image to Ascii converter in Rust Brief 📖 In my way to learn Rust i decided to make this converter. Challenges 🐢 new to Rust

An advanced image processing library for Rust.

ImageProc Maintainers: @chyh1990 Note: this project is under active depvelopment, API may change! imageproc is a advanced image proccessing library fo

Image operation rust library

Image operation rust library

Comments
  • Use `io::Write::write_all` in `encode`

    Use `io::Write::write_all` in `encode`

    std::io::Write::write can fail to write all the bytes in the given buffer to the receiver but still succeed with an Ok.

    std::io::Write::write_all ensures the entire given buffer is written before it returns.

    Calls to the write closure return Result<usize, io::Error>. The usize in the Ok variant is how many of the given bytes have been written. Since this value is not used, I think the intent is for the entire write to always succeed when getting back Ok, which is what write_all guarantees.

    opened by lopopolo 1
  • Can't open QOI image

    Can't open QOI image

    I am very sorry if I just messed up during encoding, I am very new to rust, but I can't open my qoi Image in the gnome Viewer( Other qoi Images work, https://qoiformat.org/qoi_test_images.zip). I tested your example code and it does not work

    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();
    

    Gnome Image Viewer sadly has no verbose mode so I can't give you a clearer Error.

    opened by Bkeinn 2
Owner
Chevy Ray Johnston
I'm a video game programmer, designer, artist, and writer. Creator of Ikenfell: http://ikenfell.com
Chevy Ray Johnston
mico (minimalistic config file format) encoder and decoder

mico This library implements a parser and emitter for mico (minimalistic config file format). Format example: Name: mico Description: minimalistic con

null 1 Jan 30, 2022
Oxipng - a multithreaded lossless PNG compression optimizer

Oxipng Overview Oxipng is a multithreaded lossless PNG compression optimizer. It can be used via a command-line interface or as a library in other Rus

Josh Holmer 1.8k Dec 28, 2022
Image Compression Algorithm

Image Compression Algorithm ?? A new lossless image compression algorithm. In the newest version the algorithm performs rather good, but manages to su

Hannes 31 May 10, 2022
Automated image compression for efficiently distributing images on the web.

Imager Apparently this project made it into the GitHub Archive Program. About Imager is a tool for automated image compression, and can competitively

Imager IO 487 Dec 25, 2022
A quasi-lossless Balkanoidal meta-lingual compressor.

A quasi-lossless Balkanoidal meta-lingual compressor. Background It has long been accepted that Serbian is a compact variant of Russian, with less lib

Emil Koutanov 3 Aug 17, 2022
Rust Lean Image Viewer - Fast and configurable image viewer inspired by JPEGView by David Kleiner

Rust Lean Image Viewer - Fast and configurable image viewer inspired by JPEGView by David Kleiner

3top1a 4 Apr 9, 2022
Lust is a static image server designed to automatically convert uploaded image to several formats and preset sizes

What is Lust? Lust is a static image server designed to automatically convert uploaded image to several formats and preset sizes with scaling in mind.

Harrison Burt 242 Dec 22, 2022
Takes a folder of images (as a palette), and an image, and figures out how to tile the palette to resemble the image!

Takes a folder of images (as a palette), and an image, and figures out how to tile the palette to resemble the image!

Jacob 258 Dec 30, 2022
Rust port of the Quite Okay Image format

qoi_rs What is this? A pretty boring Rust translation of qoi. Status What's there Encode & Decode works Results agree with the C implementation for al

null 9 Dec 9, 2021
Rust library to get image size and format without loading/decoding

imageinfo-rs Rust library to get image size and format without loading/decoding. The imageinfo don't get image format by file ext name, but infer by f

xiaozhuai, Weihang Ding 47 Dec 30, 2022