How to get Raw data from CR2 format. - Structure of CR2 format

since:Aug 31,2014
last update:Sep 6,2014
previous page : next page

top > photograph and camera > How to get Raw data from CR2 format. page1 > Structure of CR2 format

2. Summary

This document concretely describes the way to get raw data from CR2 format refering actual sample data.
This actual sample data is from EOS Kiss X5(Japanese Model name). In United States it called EOS REBEL T3i, in other country it called EOS 600D.

The sample data is as follows:

IMG_2026.zip (72,308Kbyte):This includes orginal CR2 file , uncompressed DNG file and Lossless Jpeg which is part of this CR2 file.
MD5 value:1962284f1c542111c71ba69b3231a948 (caution : This file is very large.)

This compressed file includes below files.
IMG_2026.CR2 : The original CR2 file.
IMG_2026_IFD3_JPEG.jpg : Lossless Jpeg included IFD3 of IMG_2026.CR2.
IMG_2026.dng : Uncompressed DNG file converted from IMG_2026.CR2.
IMG_2026_RAW_Data_from_DNG.bin : Raw data section from IMG_2026.dng.

This sample's image is below. (This image is resized.)

Sun
Vixen ED100Sf + ND400+ND16(49mm) + EOS Kiss X5 (600D/REBEL T3i) ISO100 1/4000sec

In this document the detail decoding way of TIFF is omitted.
Please note that I do not know you can get it in other camera model by this document's way.
This document does not contain the way for mRaw and sRaw.

3. Cnotent of CR2 format

3.1 Structure of CR2 format

The structure (encoding rule etc) of CR2 format is basically TIFF.
CR2 format consists the file header and 4 IFDs which has the pointer of EXIF and Raw data etc.
# IFD means"Image File Directory".
This summary is below table.

Structure
Content
File HeaderTiff File Header and Magic number
IFD0Information of Jpeg image data (full size)
IFD1Information of thumbnail Jpeg image data
IFD2Information of uncompressed small image data
IFD3Information of Raw data.

3.2 File Header

The first 16byte of CR2 file is the File Header.


Fig.1 Dump of File Header section (from 0x0000 0000 to 0x0000 000F)

The first 8 byte is same as TIFF.
The first 2 byte (address0x0000 0000-0x0000 0001) shows byte order.
The value of the sample is 0x49 0x49, this byte order is little endian.

The next 2 byte (address0x0000 0002-0x0000 0003) is TIFF Magic Number. The value of the sample is 0x002A (42).
The next 4 byte (address0x0000 0004-0x0000 0007) is the address of the first IFD (IFD0). This value of the sample is 0x0000 0010.


The next 8 byte of TIFF header is the original header of CR2 format.

The first 2 byte (address0x0000 0008-0x0000 0009) is magic number of Canon Raw format.
The value is 0x43 and 0x52 and these are "CR" in string expression.

The next 1 byte (address0x0000 000A) is major version. The value of the sample is 0x02.
The next 1 byte (address0x0000 000B) is minor version. The value of the sample is 0x00.

The next 4 byte (address0x0000 000C-0x0000 000F) is address pointer of IFD3.
IFD3 has raw data and we can get the raw data without tiff parsing.
The value of the sample is 0x0000 B6A6.


next page:IFD0 and Exif IFD

previous page [1] [2] [3] [4] [5] [6] [7] [8] [9] next page