The Canon RAW (CRW) File Format

This is a description of the Canon CRW file format.

After writing this document, I finally found an old copy of Canon's own file format specification. The format is called CIFF, and the original Canon documentation can be downloaded from http://xyrion.org/ciff/.

Comments about the CRW Format

The Canon CRW file format is a joy to work with. It has a structure that is fundamentally similar to TIFF, with directories that point to data within the file. But a major improvement over TIFF is that the offsets are not absolute, they are relative to the start of the data block for each directory. This allows subdirectories within a file to be moved or copied to another file without having to adjust the offsets, which is fantastic because it means that rewriter software doesn't have to understand the complete format in order to be able to successfully rewrite the file.

Also, the data comes before the directories in the file, which is the natural way to write information and minimizes the amount memory needed to buffer the data (unlike the EXIF standard which is the reverse).

A short rant about TIFF inadequacies:
TIFF format on the other hand, really sucks in comparison. (This includes JPEG too, since JPEG uses TIFF format to store the EXIF information. In fact, EXIF is worse because it specifies that the value data comes AFTER the directory information, which by design requires all offsets to be fixed up after the length of the directory is known... grrr.) So re-writing a TIFF file is a major pain in the butt -- all offsets require adjusting whenever anything is moved in the file, and to do this properly the software must understand the format of ALL contained data structures to be able to adjust embedded offsets. This presents a near impossible situation because of structures like the maker notes where the format is undocumented and varies for different camera models. This is why most of the software out there that can rewrite a TIFF or JPEG file will scramble the maker notes!
The bottom line is that rewriting a Canon CRW file is about 20 times easier, and much less prone to errors than rewriting a TIFF or JPEG.

CRW Format Specification

File Header

A Canon CRW file starts with the following byte sequence:
Offset Number
of bytes
ValueNameDescription
02"II"ByteOrder "II" means Intel (little-endian) order, which is the only order I've seen since Canon is using x86 processors in its current cameras, but presumably this could be "MM" for future models.
440x0000001aBlockStart 32-bit integer giving the offset from the start of the file to the start of the root directory block. This value may change for future camera models.
88"HEAPCCDR"Signature This series of characters identifies the file as a Canon CRW file.

Directory Block Structure

The root directory block begins at the offset specified in the file header, and ends at the end of the file. The structure of the block is as follows:
Offset
within block
Number
of bytes
Value NameDescription
0S-
-
-
-
-
ValueData The value data referenced by offsets in the directory
S2NDirCount 16-bit integer giving the number of directory entries
S + 2N * 10-
-
-
DirEntries The CRW directory entries
BlockSize - 44SDirStart 32-bit integer giving the size of the ValueData
To parse a CRW directory block, first read the 4 bytes at the end of the block to get the location of DirCount. Next read DirCount to determine the number of entries in the directory, then read the directory entries.

The ValueData may contain complete subdirectory blocks, each of which has the same format as specified above (and these subdirectories may themselves contain sub-subdirectories...).

CRW Directory Entry Format

The CRW directory consists of N 10-byte entries. The format of each entry is as follows:
Offset
within entry
Number
of bytes
NameDescription
02Tag 16-bit integer identifying the type of data
24Size 32-bit integer giving the number of bytes in the value data
64Offset 32-bit integer offset that gives the number of bytes from the start of the ValueData block to the start of the value data for this directory entry
Data values with lengths shorter than 8 bytes may be stored in the directory Size and Offset fields. For these values the DataLocation bits in the Tag are set to 0x4000 (see DataLocation table below).

Data stored in the ValueData block must be aligned on even 2-byte boundaries, yielding Offsets which are divisible by 2. To achieve this, records with an odd number of bytes must be padded with a zero byte.

Tag Bits

The 16-bit Tag value is composed of 3 bit fields, as follows:
BitsMaskNameDescription
14-150xc000DataLocation Specifies the location of the data
11-130x3800DataFormat Identifies the information format
0-100x07ffTagIndex Index to identify the specific type of information

DataLocation

Value data may either be stored in the ValueData block, or within the Size and Offset fields of the directory entry if it is less than 8 bytes long. The DataLocation bits specify where the value is stored:
DataLocationWhereDescription
0x0000ValueData Values are stored in the ValueData block, at the specified Offset and Size
0x4000Directory Values are stored in the Size and Offset fields of the directory entry. Values stored here are limited to a maximum size of 8 bytes.
0x8000
0xc000
?-

DataFormat

Three Tag bits are used to specify the data format:
DataFormatAlignmentDescription
0x00001-Byte A series of bytes
0x08001-Byte A null-terminated ASCII string
0x10002-Byte A series of 16-bit integers
0x18004-Byte A series of 32-bit integers or floats
0x20001-Byte A structure which is a mixture of formats
0x2800
0x3000
1-Byte A subdirectory block
0x3800? -

TagID = DataFormat + TagIndex

Together, the DataFormat and TagIndex fields form a TagID which can be used to identify tags within the CRW file. The following is a list of known TagID values and their corresponding tag numbers in the EXIF maker notes when found in a JPEG or TIFF image. Also listed is the TagID of the SubDirectory where the information is found.
TagIDEXIFSubDirNameDescription
1-Byte Alignment
0x0000-AnyNullRecord This is a null directory entry
0x0001-AnyFreeBytes Unused bytes in the ValueData
0x0032-?CanonColorInfo1 Block of color information (format unknown)
ASCII Strings
0x08050x0d0x2804CanonFileDescription An ASCII description of the file format ie) "EOS DIGITAL REBEL CMOS RAW"
0x0805-0x300aUserComment An ASCII user comment
0x080a-0x2807CanonRawMakeModel Two end-to-end null-terminated ASCII strings giving the camera make and model ie) "Canon","Canon EOS DIGITAL REBEL"
0x080b0x070x3004CanonFirmwareVersion Firmware version. ie) "Firmware Version 1.1.1"
0x080c-?ComponentVersion-
0x080d-0x3004ROMOperationMode ie) The string "USA" for 300D's sold in North America
0x08100x090x2807OwnerName Owner's name. ie) "Phil Harvey"
0x08150x060x2804CanonImageType Type of file. ie) "CRW:EOS DIGITAL REBEL CMOS RAW"
0x0816-0x300aOriginalFileName Original file name. ie) "CRW_1834.CRW"
0x0817-0x300aThumbnailFileName Thumbnail file name. ie) "CRW_1834.THM"
2-Byte Alignment
0x100a-0x300aTargetImageType-
0x1010-0x3002ShutterReleaseMethod 0=single shot, 1=continuous shooting
0x1011-0x3002ShutterReleaseTiming 0=priority on shutter, 1=priority on focus
0x1016-0x3002ReleaseSetting-
0x101c-0x3004BaseISO The camera body's base ISO sensitivity
0x10280x03??-
0x10290x020x300bFocalLength Four 16 bit integers: 0) unknown, 1) focal length in mm, 2-3) sensor width and height in units of 1/1000 inch
0x102a0x040x300bCanonShotInfo Data block giving shot information (see note)
0x102c-?CanonColorInfo2 Data block of color information (format unknown)
0x102d0x010x300bCanonCameraSettings Data block giving camera settings (see note)
0x1031-0x300bSensorInfo Sensor size and resolution information (see note)
0x10330x0f0x300bCanonCustomFunctions Data block giving Canon custom settings (see note)
0x10380x120x300bCanonPictureInfo Data block giving picture-specific information (see note)
0x10390x130x300b?-
0x10930x930x300b?-
0x10a80xa80x300b?-
0x10a90xa90x300bWhiteBalanceTable Table of red/blue balance levels for all WhiteBalance menu entries, as a series of 16-bit integers which are combined in pairs to form rational values
0x10aa0xaa0x300b?-
0x10ae0xae0x300b?-
0x10b40xb40x300bColorSpace A 2-byte integer specifying the color space (1=sRGB, 2=Adobe RGB, 0xffff=uncalibrated)
0x10b50xb50x300b?-
0x10c00xc00x300b?-
0x10c10xc10x300b?-
4-Byte Alignment
0x1803-0x300aImageFormat 32-bit integer specifying image format (0x20001 for CRW), followed by 32-bit float giving target compression ratio
0x1804-0x300aRecordID The number of pictures taken since the camera was manufactured
0x1806-0x3002SelfTimerTime 32-bit integer giving self-timer time in milliseconds
0x1807-0x3002TargetDistanceSetting 32-bit float giving target distance in mm
0x180b0x0c0x2807SerialNumber The camera body number. ie) 00560012345
0x180e-0x300aTimeStamp 32-bit integer giving the time in seconds when the picture was taken, followed by a 32-bit timezone in seconds
0x1810-0x300aImageInfo Data block containing image information, including rotation (see note)
0x1813-0x3002FlashInfo Two 32-bit floats: The flash guide number and the flash threshold
0x1814-0x3003MeasuredEV A 32-bit floats giving the measured EV
0x18170x080x300aFileNumber An integer giving the number of this file. ie) 1181834
0x1818-0x3002ExposureInfo Three 32-bit floats: Exposure compensation, Tv, Av
0x18340x10??-
0x1835-0x300bDecoderTable RAW decoder table
0x183b0x150x300b?-
Mixed Data Records
0x2005-RootRawData The raw data itself (the bulk of the CRW file)
0x2007-RootJpgFromRaw The embedded JPEG image (2048x1360 pixels for the 300D with Canon firmware)
0x2008-Root?-
SubDirectory Blocks
0x2804-0x300aImageDescription The image description subdirectory
0x2807-0x300aCameraObject The camera object subdirectory
0x3002-0x300aShootingRecord The shooting record subdirectory
0x3003-0x300aMeasuredInfo The measured information subdirectory
0x3004-0x2807CameraSpecification The camera specification subdirectory
0x300a-RootImageProps The main subdirectory containing all meta information
0x300b-0x300aExifInformation The subdirectory containing most of the JPEG/TIFF EXIF information
Note: The formats of these data blocks are known, however a description of these formats is outside the scope of this document. These data blocks are the same format as within the maker notes section in the EXIF information of Canon JPEG and TIFF files. Detailed information about these formats is contained within the Image::ExifTool::Canon.pm and Image::ExifTool::CanonRaw.pm modules.


Please e-mail me if you find any errors or omissions in this document. My address is phil at owl.phy.queensu.ca - Thanks!

P. Harvey - Last revised Feb. 8, 2005