The half-grey JPEG

A photo opens, and the top of it is perfect. Then, part-way down, the picture stops and the rest of the frame is a flat grey, or a smear of the last row repeated to the bottom. It looks like damage. It is not: it is a file that ends early, and the grey is the decoder painting rows it was never given.

How a JPEG is laid out

A JPEG begins with headers: the start marker FF D8, the metadata, the quantisation and Huffman tables that say how to decode it, and the frame size. Then comes the compressed picture, written in blocks from the top of the image to the bottom, and finally the end marker FF D9. Cut the file anywhere in the picture data and everything above the cut is still a valid description of the top of the photograph.

headerspicture data that arrived (top rows)never writtenFF D9the cutrecovery: keep every byte before it, append FF D9

Ten cut points in one file

The table below is not an illustration. It is this site’s own truncation test file, an 800 × 600 JPEG of 134,871 bytes, cut at ten evenly spaced points through its picture data, recovered the way this site recovers a file, and decoded to count the rows that arrive.

Bytes kept and rows that decode, baseline JPEG, 600 rows in all
Cut at byteShare of the fileRows that decodeShare of the picture
12,8769.5%49 of 6008.2%
25,07618.6%113 of 60018.8%
37,27527.6%161 of 60026.8%
49,47536.7%225 of 60037.5%
61,67445.7%273 of 60045.5%
73,87454.8%337 of 60056.2%
86,07363.8%385 of 60064.2%
98,27372.9%449 of 60074.8%
110,47281.9%497 of 60082.8%
122,67291.0%545 of 60090.8%

Two things are visible in it. The rows that decode track the bytes that arrived almost one for one, because the picture is written top to bottom at a roughly even rate. And they come in steps of sixteen or so, because a JPEG is coded in blocks of eight or sixteen rows: a block that was only half written is not drawn at all.

Why the grey band cannot be repaired

Repairing damage means working out what a pixel should be from the picture around it. A scratch has picture on both sides; a missing row has picture only above it, and the whole of the band below has nothing. A fill or a model asked to close it would invent the bottom of the photograph. That is why, when a recovered file is opened on this site’s bench, the band is held out of the damage mask and the page says why.

  • Rows that were never written cannot be recovered from the file. The camera's embedded thumbnail, when there is one, is a small but complete copy of the whole frame.
  • A progressive JPEG is written in passes over the whole picture, so a cut leaves the whole frame at a lower quality rather than a grey band.
  • Keep the damaged original. A copy on another device, a cloud backup or the card itself may hold the complete file.

Where to go next

Photographic visual for The Half Grey Jpeg
The Half Grey Jpeg