The mdat box holds the data of every track, found through each track’s
co64 offset and stsz size (see
boxes). As with the rest of CR3, this is
known only from reverse engineering, mainly Laurent Clévy’s canon_cr3 notes
and the decoders in LibRaw and other open source converters.
Order
- The full size JPEG (track 1).
- The small CRX raw image (track 2).
- The full size CRX raw image (track 3).
- The CTMD records (track 4).
- The second dual pixel CRX image (track 5), if any.
CRX image headers
A CRX image starts with a block of headers (its size is in CMP1) that
divides it into tiles, each tile into planes (one per colour of the filter pattern:
R, G1, G2, B), and each plane into subbands. All are big-endian.
| Header | Marker | Size | Fields |
|---|---|---|---|
| Tile | FF01 | 8 | Marker; header size 8 (short); bytes of tile data (long); tile counter (4 bits) |
| Plane | FF02 | 8 | Marker; size 8; bytes of plane data (long); plane counter 0 to 3 (4 bits); supports-partial flag (1 bit); rounded bits (2 bits) |
| Subband | FF03 | 8 | Marker; size 8; bytes of subband data (long); subband counter (4 bits); supports-partial flag (1 bit); quantisation value (8 bits); a 19-bit value subtracted from the data size to give the exact length in bits |
The second codec version (CanonCR3_002, from the 1D X Mark III) uses
markers FF11, FF12 and FF13 with 16-byte
headers. A full size image is usually two tiles, the left and right halves of the
sensor.
Coding
- Lossless raw (wavelet levels 0): each plane is one subband, coded line by line with adaptive Golomb-Rice codes, a run mode and median edge prediction, in the manner of JPEG-LS.
- C-RAW (wavelet levels 3): each plane is transformed with a three-level LeGall 5/3 integer wavelet, quantised, and coded with the same adaptive Rice and run-length scheme. The ten subbands of a plane are LL3, HL3, LH3, HH3, HL2, LH2, HH2, HL1, LH1, HH1.
The planes are then interleaved back into the colour filter pattern given by the CFA
layout in CMP1. Black and white levels and the colour data are in the
Canon maker note in CMT3.
CTMD records
Timed metadata records are little-endian, unlike the rest of the file.
| Offset | Size | Field |
|---|---|---|
| 0 | 4 | Record size N |
| 4 | 2 | Record type |
| 6 | 1 | 1 when the payload is TIFF data |
| 7 | 1 | The same |
| 8 | 2 | 1 |
| 10 | 2 | 0 for types 1 and 3, −1 for the others |
| 12 | N − 12 | Payload |
| Type | Payload |
|---|---|
| 1 | Time stamp: an unknown short, year (short), month, day, hour, minute, second and hundredths (bytes), 2 unknown bytes |
| 3 | An unknown long |
| 4 | Focal length as numerator and denominator (shorts), then 8 unknown bytes |
| 5 | Exposure: f-number and exposure time, each as numerator and denominator (shorts), ISO (long), then 16 unknown bytes |
| 7, 8, 9 | Exif blocks: entries of size (long), tag (0x8769 Exif IFD or 0x927C maker note), then a TIFF structure |