Welcome to the Quite Okay Image (QOI) library! This is a simple and fast C implementation of the QOI image format — a cool lossless image compression format that’s easy to use and super quick to encode and decode.
This library was written by me as a fun challenge in around 4 hours -- Time well spent!
The magic happens in qoi.c and qoi.h. These files let you load and save QOI images with support for both RGB and RGBA pixel formats.
- Lossless image compression and decompression with the QOI format.
- Works with images that have 3 channels (RGB) or 4 channels (RGBA).
- Simple and straightforward API for loading and saving images.
- Minimal dependencies — just plain old C.
This header file defines the main data structures and functions:
QOI_EResult: Enum for error and status codes you might get back.QOI_ImageStruct: Holds your image data, dimensions, channels, and colorspace info.- Functions:
qoi_load_from_file(const char *path, QOI_ImageStruct *image): Loads a QOI image from a file.qoi_store_to_file(const char *path, QOI_ImageStruct *image): Saves your image data to a QOI file.qoi_image_free(QOI_ImageStruct image): Frees the memory used by the image pixels.
- Include
qoi.hin your project. - Call
qoi_load_from_fileto load a QOI image. - Work with the raw pixel data via the
pixelspointer inQOI_ImageStruct. - Modify or use the image data however you want.
- Save your changes with
qoi_store_to_file. - When you’re done, free the pixel data with
qoi_image_free.
#include "qoi.h"
#include <stdio.h>
int main() {
QOI_ImageStruct image;
if (qoi_load_from_file("input.qoi", &image) != QOI_OK) {
printf("Oops! Couldn’t load the image.\n");
return 1;
}
// Do your image magic here
if (qoi_store_to_file("output.qoi", &image) != QOI_OK) {
printf("Oops! Couldn’t save the image.\n");
}
qoi_image_free(image);
return 0;
}- Add load/store to memory functionality
- Add an ability to set custom callbacks for FS access
This project is under the MIT License. Software provided AS IS, without any warranties.
- Check out the QOI format spec here: https://qoiformat.org/