Field notes/Mediarusty_jpegJPEGrusty_exr

A JPEG Decoder Swap in Two Rust Photo Apps, Losses Included

Freehold Photo and Freehold Light moved their JPEG decoding to rusty_jpeg. Thousands of real files were gated old against new. Here's what improved, what broke, and which fallbacks stayed.

Signed by M·
Painted stone watermill at dawn with one new wooden gear fitted among the old weathered ones
What happened when two Rust photo apps switched to rusty_jpeg?

Freehold Photo lost none of 3,145 test JPEGs and gained 35, keeping its old 8-bit decoder as a fallback for 5 bit-flipped files. Freehold Light now decodes whole-row-restart lossless JPEGs exactly, which its old decoder got wrong in all 165 cases, but 157 files truncated right after a scan header no longer open.

Ship it

3,145 JPEGs Gated, Fallback Kept

rusty_jpeg took over every 8-bit decode with 0 files lost and 35 gained, and the old decoder stays as a fallback for 5 bit-flipped files.

Open the Freehold Photo conversion pin →

Swapping the decoder under a photo app is a scary change. Users don't see a decoder. They see a picture that used to open and now doesn't. So when Freehold Photo and Freehold Light moved their JPEG decoding to rusty_jpeg 0.4.14, every row of the decoder swap was gated on real files, old build against new, and the losses went into the release notes next to the wins.

This note walks through the decoder swap in both apps. They took different paths, and that's the interesting part.

Freehold Photo: Gain Without Loss, Fallback Kept

Freehold Photo is a layered editor with masks. Its JPEG gate ran 3,145 files through Photo's own import code. After the last JPEG commit, 0 files were lost, 35 were gained, and nothing panicked.

Two decoders out, one in

rusty_jpeg replaced two decoders in Photo. The first handled 12-bit and arithmetic-coded JPEGs. Those still open as far as they did before: 12-bit samples land within 35 of 65,535 of the old decode, and 8-bit arithmetic within 2 levels. Lossless JPEG and 12-bit progressive Huffman stay marked unsupported, even though rusty_jpeg can read them. Opening them needs a gate of their own first.

The second was zune-jpeg, which did every 8-bit decode and the lossy DNG tiles. Against it, rusty_jpeg lost nothing across 3,145 JPEGs and 81 lossy DNGs made from public-domain photos. Intact files came out identical, apart from files missing only their end marker, which moved by 1 to 4 levels. RGB files marked with Adobe transform 0, which zune-jpeg couldn't open, now do.

Why the fallback stayed

Here's the honest part. Without a fallback, 5 bit-flipped files would have been lost. So zune-jpeg stays in Photo as the fallback for 8-bit files rusty_jpeg refuses. The damaged area of a recovered file is now filled grey, the same fill libjpeg-turbo uses.

That's the right call for an editor. A person opening a damaged photo wants whatever pixels can be saved, and two decoders with different failure modes save more than one.

Freehold Light: Exactness, and a Real Loss

Freehold Light is a photo library and RAW developer, and its JPEG traffic is different. Thumbnails, previews, the import probe, CMYK, high bit depth, lossless JPEG inside DNG files. Its gate ran 2,423 JPEGs, including CMYK, progressive, 12-bit and damaged copies, plus 660 lossless JPEGs from Light's own encoder and 145 DNGs Light wrote itself.

The jpeg-decoder paths

On the paths that used jpeg-decoder, nothing was lost and every clean JPEG came out byte-identical. 12-bit DCT JPEGs open now. The big win is lossless JPEG with whole-row restart intervals, which is how DNG files lay it out. jpeg-decoder decoded all 165 of those wrongly. rusty_jpeg decodes them exactly.

One case is still unsettled. Lossless files whose restart interval isn't a whole row, 37 samples in all, disagree with Light's own encoder in both decoders, and libjpeg-turbo refuses them outright. Arithmetic coding and two-component frames stay refused.

The zune-jpeg paths, and the 157

On full-size 8-bit decodes, the preview cache and lossy DNG tiles, clean JPEGs now sit within 3 levels of libjpeg-turbo. zune-jpeg had been up to 115 levels off on small files. Damaged files still recover.

The loss is real and it's in bold in the notes. 157 files cut right after a scan header no longer open. zune-jpeg showed a flat block of two or three colours for those, and libjpeg-turbo refuses them too, so no actual photo went missing. Two bit-flipped files with a bad spectral selection also fail now, even though libjpeg-turbo reads them. That damage was synthetic, so no fallback was kept. Lossy DNG tiles move by plus or minus one 8-bit code.

Beyond JPEG, and What to Take From It

Photo's round touched two more formats. Both show the same habit of keeping the old path where the new one isn't proven.

HEIC and EXR

The HEIC path through rusty_h265 was gated on all 256 HEIC and HEIF files on the build machine: 0 lost, 1 gained. Four iPhone photos differ by up to 15 levels, and rusty_h265 was measured bit-exact in YUV on one of them, so the old decoder is the likelier one off. But the apps were built without the heif feature, so neither decoder ships in this release. The rusty_h265 notes cover that decoder on its own.

EXR moved to rusty_exr 0.2.0. Flat parts decode bit-identical, and writes are byte-identical in all five of Photo's compressions. Multi-threaded decode took 0.46 to 0.99 times the previous crate's time on 9 real files, though three ZIP-compressed HDRIs ran 1.02 to 1.07 times slower single-threaded. The previous OpenEXR crate stays for headers, deep data, streaming and as the fallback.

The pattern worth copying

If you're planning a decoder swap of your own, a few habits carry over. Gate on your own app's decode calls, not the crate's test suite. Keep the old decoder where the new one refuses something a person would want back. And publish the losses with the same weight as the wins. The JPEG spec, ITU-T T.81, leaves plenty of room for decoders to disagree on broken files, so the only honest answer is a table.

The same rusty_jpeg 0.4.14 went into Freehold Docs and Freehold Grid too, gated on 2,394 JPEGs with nothing lost. Photo and Light are free downloads from mata.network/freehold, and the crate behind the swap has its own field note on rusty_jpeg.

FAQ

Quick answers for builders evaluating this technology.

Why keep the old decoder as a fallback in Freehold Photo?

Without it, 5 bit-flipped files in the gate would have been lost. rusty_jpeg refuses those, the old decoder recovers them, so Photo tries rusty_jpeg first and falls back only for 8-bit files it turns down.

Which files does Freehold Light lose after the swap?

157 files cut off right after a scan header. The old decoder showed a flat block of two or three colours for them, and libjpeg-turbo refuses them too. Two synthetic bit-flipped files with a bad spectral selection also fail now.

Does Freehold Photo open HEIC files?

Not in this release. A rusty_h265-based HEIC path was gated on 256 files with 0 lost and 1 gained, but the apps were built without the heif feature, so neither the new nor the old HEIC decoder is in the binaries.

How did rusty_exr do in Freehold Photo?

Flat EXR parts decode bit-identical and writes are byte-identical in all five of Photo's compressions. Multi-threaded decode took 0.46 to 0.99 times the previous crate's time on 9 real files. The previous crate stays for headers, deep data and streaming.

How many tests ran at each release tag?

Freehold Photo ran 18,686 passing tests with 91 failures: 62 carried over with recorded verdicts and 29 were memory pressure that passed alone. Freehold Light ran 6,303 passing with 3 failures, two from a GPU out-of-memory test.