Lossless Image Compression
Introduction
This research effort started with the release of the excellent QOI format. Its simplicity and execution speed piqued my curiosity and led me to explore two questions:
- can QOI’s compression ratio be significantly improved while maintaining very high performance?
- how do existing lossless formats compare on the trade-off between compression ratio and compute time?
Key Reference Formats
Reference Benchmark
Let’s take a classic image from the literature (from the Kodak corpus), kodim23:

Let’s compare the resulting file size and compression time using each codec’s default settings:
| Format | File size (bytes) | Compression time (s) |
|---|---|---|
| PPM (uncompressed) | 1 179 663 | 0 |
| QOI | 675 251 | 0.023 |
| PNG | 557 596 | 0.276 |
| WebP (lossless) | 426 464 | 0.324 |
| FLIF | 385 544 | 1.866 |
| JPEG XL (lossless) | 382 055 | 1.046 |
| PAQ (paq8px) | 244 703 | 200.000 |
These measurements illustrate the fundamental trade-off every compressor must make, depending on whether it aims to minimize:
- final file size (at the extreme: PAQ)
- compression time (at the extreme: QOI).
Explorations and Algorithmic Directions
While the initial goal was to improve on QOI, the temptation to measure up against the best compressors in the field quickly becomes hard to resist—and there is always something denser (at least until PAQ).
Over several years of experimentation, I’ve dug into the core building blocks of lossless compression:
- entropy coding, in particular Jarek Duda’s ANS (Asymmetric Numeral Systems)
- representing residuals and color channels (bit decomposition, logarithmic / prefix codes, inter-channel decorrelation) and their sometimes counter-intuitive effects on the downstream entropy encoder
- context modeling (how the nearby spatial neighborhood influences each pixel’s prediction and probability)
- applying machine learning to prediction, along with its actual cost on runtime performance.
This work focuses primarily on natural images (photographs, medical or satellite imagery). Synthetic images (icons, pictograms, screenshots) follow a very different physics—limited palettes, flat fills, repeated patterns—and call for distinct strategies.
Target Goal
The challenge I set for myself is to design an algorithm (and variants geared toward speed/parallelism or density) capable of:
- rivaling JPEG XL / FLIF / WebP on compression ratio
- remaining as fast as (or faster than) PNG at runtime.
The mechanisms explored and the results achieved will be detailed progressively in posts on this blog.