Skip to main content

QOI

QOI (Quite OK Image Format) is an image compression format that aims to provide a simple, fast, and efficient way to compress and decompress images losslessly. It was designed to be easy to implement while offering better compression ratios than the widely used but more complex PNG format while achieving much faster encoding & decoding speeds.

Performance Checklist​

Lossless? Yes

Lossy? No

Supported Bit Depths: 8 BPC

HDR/Wide Gamut? No

Animation? No

Transparency? Yes

Progressive Decode? No

Royalty Free? Yes

Format Breakdown​

QOI compression is based on a simple and fast algorithm that exploits spatial redundancy in images. The algorithm uses a combination of run-length encoding (RLE), a small lookup table, delta encoding, and full-color pixel storage to achieve efficient compression. Depending on the algorithm's decision, a chunk (pixel) can take up one to five bytes.

The QOI format supports images with 3 or 4 channels (RGB or RGBA) and 8 bits per channel. The format supports two colorspaces: Linear RGB & sRGB with linear alpha. These do not affect the way pixels are encoded.

Here is a breakdown of the various chunk types in QOI:

  1. QOI_OP_RGB: Full RGB pixel value using 8 bits (1 byte) for each of the red, green, and blue channels. The alpha channel is 255 in RGB images, and always remains unchanged.

  2. QOI_OP_RGBA: Full RGBA pixel value using 8 bits for each of the red, green, blue, & alpha channels.

  3. QOI_OP_DIFF: The difference between the current pixel and the previous pixel for the red, green, and blue channels are stored using 2 bits for each channel. The differences are stored with a bias of 2 and wrap (so 1 minus 2 would be 255). The alpha channel remains unchanged.

  4. QOI_OP_LUMA: These pixels encode the green channel difference from the previous pixel using 6 bits, and then encode the red and blue channel differences relative to the green channel difference using 4 bits each. This allows for more efficient encoding of small color changes. The alpha channel remains unchanged.

  5. QOI_OP_RUN: These are the simplest, encoding a run-length of pixels that are identical to the previous pixel. The run length is stored using 6 bits with a bias of -1, allowing for runs of 1 to 62 pixels.

  6. QOI_OP_INDEX: These are stored by referencing a previously seen pixel value from a rolling array of 64 recent pixel values by using a simple hash on each pixel as it is identified. If another pixel matches a previously seen hash value in the array, the index of the referenced pixel is stored.

The QOI format also includes a simple 14-byte header that stores the image dimensions, color space, and channel depth information. The end of file is signaled by an 8-byte end marker.

Benchmarks​

The creater of QOI benchmarked the format against libpng & stbi_image_write using the C implementation in QOI via qoibench.c on a collection of 2,879 screenshots, icons, photos, & textures (source). The results are as follows:

LibraryDecode (ms)Encode (ms)Decode MP/sEncode MP/sSize (kb)Compression Rate
libpng7.083.866.565.5439824.2%
stbi7.060.566.637.6756134.2%
qoi2.12.9226.03161.9946328.2%

The results show that QOI is significantly faster than libpng and stb_image_write, and it also achieves better compression ratios than libpng on average.

Advantages​

Some of the key advantages of QOI include:

  • Super simple: the spec is only one page
  • Extremely fast encoding & decoding speeds
  • Data chunks are byte-aligned, so data can be streamed to a decoder one byte at a time
  • Better compression ratios compared to PNG for many types of images
  • Supports transparency
  • Royalty-free, open-source (CC0), & easy to integrate into any application

Limitations​

  • Limited to 8 bits per channel (no support for higher bit depths)
  • Not suitable for images with high-frequency noise or very little spatial redundancy
  • Lacks advanced features like progressive loading, interlacing, or custom metadata

Despite its limitations, QOI provides a compelling alternative to PNG for many use cases where simplicity, speed, and good compression ratios are desired. QOI is not especially well supported at present, but adoption is rapidly growing as developers can easily integrate support into their applications due to the format's simplicity.