Every pixelcomes back.

Truepix is a lossless image codec for archives. On 24 photos it had never seen, JPEG XL at its top effort came out 3.62% larger, and Truepix won on all 24. Every pixel came back exact.

Decoding… Read the paper
Scroll: follow one pixel. Values are illustrative.

One pixel, five steps

1. Predict

Four least-squares predictors and eleven simple ones guess the next value from pixels already decoded. An adaptive blend combines them.

2. Correct

Bias cancelling tracks the errors made in similar places and removes the part that keeps repeating.

3. Model

21 contexts estimate each bit, including exact colour differences that can learn a colour grid with no formula. Seven logistic models add their own estimates.

4. Mix

50 inputs feed five small neural mixers. A final mixer weighs those, then two adaptive maps refine the probability.

5. Code

A 32-bit binary arithmetic coder narrows an interval with every decision and writes out bytes. The decoder repeats all of this to get the pixel back exactly.

Final test: 24 DIV2K photos kept back until the code was frozen

Smallest file on every photo

Bits per pixel across the whole set, so shorter wins. Every Truepix file decoded back exactly.

All 24 photos, against JPEG XL effort 10

Truepix saved from 0.44% to 7.52% of the JPEG XL file. No image lost.

Three separate tests agree

Test set, 24 photos eachJPEG XL e10 larger byTruepix wins
DIV2K 0801 to 08244.28%23 of 24
DIV2K 0841 to 08644.29%24 of 24
DIV2K 0865 to 0888, final build3.62%24 of 24

Only the last row used the final build. The first two ran on earlier versions.

What Kodak was hiding

A strange gap

A slow general compressor, paq8px, beat image codecs by a surprising margin on the famous Kodak test set. About 90% of that gap was colour.

Photo CD

Kodak's images came from Photo CD, so their RGB values sit on a stretched integer grid, recovered here from pixels alone.

The payoff

Only 12.8% of all RGB colours can occur on that grid, and they hold 87.3% of Kodak's pixels. Exact-difference contexts turned the finding into a gain on ordinary photos too. Truepix was tuned on Kodak, so its 5.723 bits per pixel there isn't a fair score.

Encoding race, photo by photo

3.5 times faster than JPEG XL's top effort

JPEG XL's highest effort took 42.0 seconds per photo. Truepix took 12.0, and its files were still smaller: JPEG XL's came out 3.71% larger on these five photos.

Truepix12.0 s
JPEG XL, effort 1042.0 s

Shown at 6× speed. The timers count real seconds.

Mean per image, 5 photosEncode (s)Total size
Truepix12.0smallest
JPEG XL, effort 1042.0+3.71%
JPEG XL, effort 91.8+6.17%
FLIF14.3+10.62%
WebP lossless10.0+20.27%

Ryzen 7 5800HS, 8 cores. Other work may have shared the machine during the rival timings, taken in an earlier run. Sizes are relative to Truepix on the same five photos.

Final test: 24 unseen photos at quality 85

JPEGs shrink too, and come back byte for byte

Truepix reads a JPEG's own data, compresses it further, and rebuilds the original file exactly. There is no new quality loss, and it takes about a second. Bars show size saved, so longer wins.

24 photos eachTruepix savedJPEG XL e9 savedTruepix winsRebuilt exactly
Quality 8521.84%16.40%24 of 2424 of 24
Quality 7522.60%16.54%24 of 2424 of 24
Quality 9522.54%18.51%24 of 2424 of 24
Quality 85, progressive17.06%11.31%24 of 2424 of 24

JPEGs made by Pillow from DIV2K 0865 to 0888. The JPEG model was frozen, then scored once. Files from other encoders may behave differently.

Runs on your device. Nothing is uploaded.

Try it on your own image

This is the real codec, compiled to WebAssembly, and it writes the same files as the desktop build. Drop an image to compress it and check the result, or drop a Truepix file to rebuild the original.

Drop an image or a .tpix file
PNG, JPEG, WebP or BMP, up to 16 megapixels. JPEGs come back byte for byte. Allow about 30 seconds per megapixel on an 8-core laptop, and less for JPEGs.
Reproducible floating point

245 checks. 245 exact.

Encoder and decoder must agree on every bit of floating-point maths. Each square is one build decoding another build's file. Files were byte-identical across all seven: GCC AVX2, GCC FMA, GCC SSE2, GCC -O0, Clang x64, Clang x86, WebAssembly.

Plain RGB
Photo CD
JPEG history
Greyscale
RGBA

What it doesn't do

Use it

Truepix is a C++ codec with a small Python command-line tool. The source is on GitHub.

g++ -std=c++17 -O3 -mavx2 -ffp-contract=off -static truepix-core.cpp -o truepix-core.exe

uv run truepix compress photo.png --verify   # writes photo.tpix
uv run truepix decompress photo.tpix         # writes photo.png
uv run truepix compress photo.jpg            # the JPEG comes back byte for byte
Read the paper (PDF)