Canon has not published CR2. Its layout is known from independent work, chiefly Laurent Clévy’s CR2 notes, the libopenraw documentation, dcraw and ExifTool. A CR2 file is a valid little-endian TIFF file with an extra 8-byte header and a fixed set of four image file directories (IFDs).
Headers
| Offset | Size | Field | Value |
|---|---|---|---|
| 0 | 2 | Byte order | II (49 49), little-endian |
| 2 | 2 | TIFF magic | 42 (2A 00) |
| 4 | 4 | Offset of IFD 0 | Usually 16 (10 00 00 00) |
| 8 | 2 | CR2 signature | CR (43 52) |
| 10 | 1 | Major version | 2 |
| 11 | 1 | Minor version | 0 |
| 12 | 4 | Offset of IFD 3 | Where the raw data directory is, so a reader can go straight to it |
The extra header sits between the TIFF header and IFD 0, where TIFF allows anything,
so ordinary TIFF readers still open the file. The first 12 bytes are therefore always
49 49 2A 00 10 00 00 00 43 52 02 00.
The four IFDs
Each IFD links to the next through the usual TIFF next-IFD offset.
| IFD | Image | Main tags |
|---|---|---|
| 0 | Full size JPEG preview | ImageWidth, ImageLength, BitsPerSample, Compression 6, Make, Model, StripOffsets and StripByteCounts (the JPEG), Orientation, resolution, DateTime, the Exif IFD pointer (0x8769) and, on GPS cameras, the GPS IFD pointer. The Exif IFD holds the Canon maker note (0x927C). |
| 1 | Small JPEG thumbnail, usually 160 × 120 | Compression 6, JPEGInterchangeFormat (0x0201) and JPEGInterchangeFormatLength (0x0202). |
| 2 | Reduced size uncompressed RGB image | ImageWidth, ImageLength, BitsPerSample 16, 16, 16, Compression 1, PhotometricInterpretation 2, SamplesPerPixel 3, StripOffsets, RowsPerStrip, StripByteCounts, PlanarConfiguration 1, and Canon’s tags 0xC5D9 and 0xC6DC (meaning unknown). |
| 3 | Raw sensor data | Compression 6, StripOffsets and StripByteCounts (one lossless JPEG stream), Canon’s tags 0xC5D8 and 0xC5E0 (meaning unknown), 0xC640 (slices, see raw data) and, for sRAW and mRAW, 0xC6C5. |
IFD 3 has no image size tags: the size comes from the JPEG frame header and the sensor information in the maker note. Compression 6 is TIFF’s old-style JPEG code; Canon uses it both for the baseline JPEG previews and for the lossless JPEG raw data.
Finding the parts
- Check for
CRat offset 8 and version 2.0. - Read the IFD 3 offset at 12 and its StripOffsets and StripByteCounts for the raw data.
- Read IFD 0 for the preview and follow its Exif IFD to the maker note, which holds the sensor borders, black levels and white balance (see maker note).
libopenraw states the layout as: the TIFF header (8 bytes), the characters
CR at 8, the major version 2 at 10, the minor version 0 at 11 and the
offset of IFD 3 at 12, stored in the file’s byte order. Exif metadata hangs off the Exif
IFD of IFD 0 and the raw (CFA) data is in IFD 3. The extra header sits before IFD 0,
which TIFF allows. Canon’s own software rewrites CR2 files in a way that some
third-party programs cannot open.
The meaning of the Canon tags 0xC5D8, 0xC5D9,
0xC5E0 and 0xC6DC is given by none of the sources read here,
and the IFD 2 BitsPerSample of 16, 16, 16 is stated from the earlier reading of Clévy’s
notes, which could not be reached again; treat that value as unconfirmed.
Sources
- libopenraw: CR2 – the 16-byte header, IFD layout and IFD 3
- Laurent Clévy’s CR2 notes at lclevy.free.fr/cr2/ could not be reached from here (connection refused)