Each thumbnail is a separate stream. The headers below were read from 2,150 real thumbnail streams and hold in all of them. Nothing here is documented by Microsoft.
Stream names
With a Catalog, a thumbnail stream is
named by the digits of its entry’s identifier reversed: identifier 165 is the stream
561. Without one, each stream is named by a size and a hexadecimal hash,
such as 96_ followed by the hash; the file holds no picture names.
The header
The header comes first in every thumbnail stream. There are two forms.
| Offset | Size | 12-byte form | 24-byte form |
|---|---|---|---|
| 0 | 4 | 0x0C, the header size | 0x18, the header size |
| 4 | 4 | Type: 1 | Type: 3 |
| 8 | 4 | The size of the data after this header | The size of the data after this header |
| 12 | 12 | The picture starts here | Three more 32-bit words, not established here. The picture starts at 24. |
The 24-byte form belongs to the second, hashed-name form of the file; in the files checked, it holds a JPEG or a PNG. The 12-byte form holds a JPEG.
The picture
0Thumbnail header 12 bytes, or 2412 or 24…the picture: a JPEG or a PNG file, wholevaries
In the files checked, 1,360 streams held a complete JPEG, all starting with the usual
FF D8 FF E0, and 162 held a PNG, all in the 24-byte form.
Older thumbnails
Some thumbnails in Catalog files do not hold a complete JPEG. After the 12-byte header comes a second header:
| Offset | Size | Name | Description |
|---|---|---|---|
| 12 | 4 | Marker | 1. |
| 16 | 4 | Data size | The number of bytes after this header. |
| 20 | 4 | Width | In pixels. |
| 24 | 4 | Height | In pixels. |
After that is a JPEG start of image, a frame header and a scan, with no quantisation or Huffman tables and no JFIF header. This is a “frame and scan” the way a table-less JPEG is, not a file a decoder can open as it stands. Windows left the tables out because every such thumbnail uses the same ones.
The 28 bytes of headers and the frame header are the same in every stream; only the sizes and the scan data change. A whole stream of 149 bytes, 8 × 8 pixels:
0 0C 00 00 00 01 00 00 00 89 00 00 00 first header: size 12, type 1, 137 bytes follow
12 01 00 00 00 79 00 00 00 08 00 00 00 08 00 00 00 second header: 1, 121 bytes follow, width 8, height 8
28 FF D8 start of image
30 FF C0 00 14 08 00 08 00 08 04 frame: baseline, 20 bytes, 8 bits, 8 lines, 8 samples, 4 components
40 52 11 00 47 11 00 42 11 00 41 11 00 components 'R' 'G' 'B' 'A', each 1 × 1, quantisation table 0
52 FF DA 00 0E 04 52 00 47 00 42 00 41 00 00 3F 00 scan: four components, all Huffman table 0, spectral 0 to 63
66 ... entropy-coded data ... FF D9 and the end of image
The first header’s data size is the second header’s plus 16; both are exact in every stream. All 1,025 older streams in the files checked have this very frame and scan.
Rebuilding the picture
To decode one, put the missing tables in front of the frame, as Vinetto does:
- Start with
FF D8(the stream’s own start of image can be used). - Add a quantisation table definition:
FF DB 00 43 00and 64 values, table 0. The values are those of the JPEG standard’s luminance table scaled to quality 75, in zigzag order:08 06 06 07 06 05 08 07 07 07 09 09 08 0A 0C 14 0D 0C 0B 0B 0C 19 12 13 0F 14 1D 1A 1F 1E 1D 1A 1C 1C 20 24 2E 27 20 22 2C 23 1C 1C 28 37 29 2C 30 31 34 34 34 1F 27 39 3D 38 32 3C 2E 33 34 32. - Add the standard Huffman tables of the JPEG standard’s annex K for luminance:
the DC table (
FF C4 00 1F 00, then the code counts00 01 05 01 01 01 01 01 01 00 00 00 00 00 00 00and the symbols 0 to 11) and the AC table (FF C4 00 B5 10, the counts00 02 01 03 03 02 04 03 05 05 04 04 00 00 01 7Dand the 162 symbols that begin01 02 03 00 04 11 05 12 21 31 41 06 13 51 61 07 22 71 14 32 81 91 A1 08and endF9 FA). These are the tables most JPEG encoders start from. - Then the stream’s frame header (from
FF C0) and its scan and data to the end.
The result is a baseline JPEG with four components, which most decoders will read as CMYK. The four samples are not colours in that sense, though:
- The component named
Rholds blue,Gholds green,Bholds red. The names in the frame header are misleading; the order is that of a Windows bitmap’s pixels (blue, green, red). - The values are the colour as it is, not inverted: the usual CMYK reading (subtracting them from 255) gives a negative of the picture.
- The rows are stored bottom to top, as a Windows bitmap’s are, so the picture has to be turned over.
- The fourth component, named
A, is not applied. In the files checked it is the constant 1 in 466 of 569 distinct pictures, the constant 65 in 41, and a varying value from 0 to 255 in the other 62 (folder icons and other pictures with transparent parts, where it does not follow the pixels’ colour). Its meaning is not established; drawing the pictures without it gives the right colours in all the ones inspected.
That reading was settled by looking at pictures with known colours and orientation (a yellow folder icon, a blue maze) rather than from a document. The file explorer draws the older thumbnails this way.
In the 372 distinct Thumbs.db files checked, 96 files had streams of this kind, and every one of those streams decoded.
Thumbnails of deleted pictures
When a picture is deleted or replaced, its thumbnail stream is dropped from the directory
and its sectors are marked free in the FAT, but the bytes stay until something reuses
them (54 of the 469 files checked had free sectors). A stream that was kept in ordinary
sectors begins at the start of a sector with its own first header (0C 00 00 00 01 00 00 00
and the data size, or 18 00 00 00 03 00 00 00 and the size), followed by a JPEG, a PNG or an
older thumbnail’s second header. So a run of free sectors that starts with such a header, has as many free
sectors after it as the stated size needs, and holds a picture signature, is a recoverable thumbnail. The
file explorer finds them this way and shows them in a Recovered tab, without file names (the Catalog
entry went with the stream). A stream that was in the mini stream, or whose sectors were not in a row
when it was dropped, is not found. In the files checked this recovers 43 thumbnails, all of which decode.