Home

Awesome

Quite OK Image format encoder and decoder in Racket

This repository contains a Racket implementation of an encoder and a decoder for the QOI image format.

At the moment, this implementation can only convert raw RGBA images to/from QOI. Other image formats can be handled by separate image manipulation tools or libraries.

Credits

Thanks to Matthias Felleisen for reviewing and improving the code.

Installation

Install Racket.

Run these commands to clone this repository and install the qoi library:

git clone https://github.com/aumouvantsillage/qoi-racket.git
cd qoi-racket/qoi
raco pkg install --auto

Examples

Install ImageMagick.

Run this script to get the official test image set and convert the PNG files to RGBA:

cd qoi-racket/qoi-test
./setup.sh

QOI encoding

Run this script to convert all test images qoi_test_images/*.rgba to qoi_test_images.out/*.qoi:

racket writer-tests.rkt

QOI decoding

Run this script to convert all test images qoi_test_images/*.qoi to qoi_test_images.out/*.rgba:

racket reader-tests.rkt

API

(struct image (width height channels colorspace pixels))

Structure type for images. Use make-image to create a new image instance.

(make-image width height channels colorspace)

Creates and returns a new instance of the image structure type.

(image-read-rgba width height channels colorspace [in (current-input-port)])

Creates and returns a new instance of the image structure type. Its pixels field is filled with RGBA data from the input port in.

(image-write-rgba img [out (current-output-port)])

Write the RGBA data of the image img to the output port out.

(image-read-qoi [in (current-input-port)])

Creates and returns a new instance of the image structure type. This function reads and decodes QOI data from the input port in and fills the pixels field of the image with the decoded RGBA data.

(image-write-qoi img [out (current-output-port)])

Encode the RGBA data of the image img to the QOI format and write the result to the output port out.