HeadlinesBriefing favicon HeadlinesBriefing.com

Regressive JPEGs: Progressive Rendering Tricks

Hacker News •
×

JPEG files can store low‑frequency data first, so a partially downloaded image shows a low‑resolution preview instead of a cut‑off, because the data is split into several “scans,” each with its own header.

The first scan starts with marker FF DA, a 12‑byte length field, three color channels (Y Cb Cr), and a single DC‑only bin giving the luminance baseline. Y carries the high‑quality luminance, while Cb and Cr are halved in resolution.

The file then has eight more scans that add detail: scans 1–5 supply low‑precision data for Y, Cb, and Cr; scans 6–9 finish the image. Placing chroma scans first still renders correctly because chroma is stored at half resolution. Most decoders stop after around 90 frames to avoid “zip‑bomb” attacks, enough for simple animation tricks.

The trick is to concatenate multiple JPEGs of the same resolution, dropping start‑of‑image and start‑of‑frame markers, so a slow network swaps frames. Each scan’s spectral range lets later scans overwrite earlier data. Baseline JPEGs work best because they allow a DC‑only scan that still renders color, but the decoder processes only one scan. The image can host a tiny video, but practical use is limited by the lack of timing data.