The Canon RAW (CRW) File Format

This is a description of the Canon CRW file format. CRW files are written in Camera Image File Format (CIFF). The original Canon CIFF specification can be downloaded from http://xyrion.org/ciff/ (which I finally discovered after writing this document!). Note that Canon has three different RAW formats, with newer models producing a TIFF-based CR2 or QuickTime-based CR3 as opposed to the CIFF-based CRW format documented here.

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 EXIF, which is typically 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). The main problems are the use of absolute offsets and the ambiguity between integers and pointers (such as those used for custom IFD's). Because absolute offsets require adjusting whenever anything is moved in the file, the format of ALL contained data structures must be understood to properly edit the file. This results in an impossible situation when presented with undocumented custom structures like those used in the maker notes written by modern digital cameras. This is why it is so common for image editors to either scramble the maker notes or discard them completely. The official TIFF recommendation is to discard unknown information when rewriting the image (as Photoshop does), but for many, including myself, this option is simply unacceptable.

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 (CIFF) 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.
240x0000001aHeaderLength 32-bit integer giving the length of the CRW file header. For current camera models the header is 26 bytes long.
68"HEAPCCDR"Signature This series of characters identifies the file as a Canon CRW file. The signature is "HEAPJPGM" for CIFF information in APP0 of JPEG images.
1440x00010002CRWVersion 32-bit integer giving the major (high 16 bits) and minor (low 16 bits) CRW file version numbers. The version is 1.2 for current cameras.
1880Reserved Two 32-bit integers, currently set to zero.

Directory Block Structure

The root directory block begins immediately after the file header (at the position specified by HeaderLength), and ends at the end of the file. The structure of this 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
S + 2 + N*10any-OtherData (be aware there may be other data hiding here)
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 (S) of DirCount. Next read DirCount to determine the number of entries (N) 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...). For these subdirectories, BlockSize is given by the Size specified in the corresponding directory entry. For the root directory, BlockSize is the length of the file.

The OtherData normally does not exist (eg. the DirEntries usually end at the DirStart pointer), but this is not always the case: Canon Digital Photo Professional uses this area in the root directory block to store VRD data in edited CRW images. (Note that VRD supports embedded XMP, which provides a technique to store modern metadata in CRW images!)

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. The Size listed below is an observed size of the value data, and is not necessarily expected to remain constant for all camera models.

TagIDEXIFSubDirNameSizeDescription
1-Byte Alignment
0x0000-anyNullRecord0 This is a null directory entry
0x0001-anyFreeBytesvaries Unused bytes in the ValueData
0x0006-0x300b-8-
0x0032-0x300bCanonColorInfo1768 or 2048 Block of color information (format unknown)
0x0036-0x300b?varies-
0x003f-0x300b?5120-
0x0040-0x300b?256-
0x0041-0x300b?256-
ASCII Strings
0x0805-0x2804CanonFileDescription32 Description of the file format. eg) "EOS DIGITAL REBEL CMOS RAW"
0x0805-0x300aUserComment256 User comment (usually blank)
0x080a-0x2807CanonRawMakeModel32 Two end-to-end null-terminated ASCII strings giving the camera make and model. eg) "Canon","Canon EOS DIGITAL REBEL"
0x080b0x070x3004CanonFirmwareVersion32 Firmware version. eg) "Firmware Version 1.1.1"
0x080c-?ComponentVersion?-
0x080d-0x3004ROMOperationMode4 eg) The string "USA" for 300D's sold in North America
0x08100x090x2807OwnerName32 Owner's name. eg) "Phil Harvey"
0x08150x060x2804CanonImageType32 Type of file. eg) "CRW:EOS DIGITAL REBEL CMOS RAW"
0x0816-0x300aOriginalFileName32 Original file name. eg) "CRW_1834.CRW"
0x0817-0x300aThumbnailFileName32 Thumbnail file name. eg) "CRW_1834.THM"
2-Byte Alignment
0x100a-0x300aTargetImageType2 0=real-world subject, 1=written document
0x1010-0x3002ShutterReleaseMethod2 0=single shot, 1=continuous shooting
0x1011-0x3002ShutterReleaseTiming2 0=priority on shutter, 1=priority on focus
0x1014-0x3002-8-
0x1016-0x3002ReleaseSetting2-
0x101c-0x3004BaseISO2 The camera body's base ISO sensitivity
0x1026-0x300a-6-
0x10280x030x300bCanonFlashInfo?8Unknown information, flash related
0x10290x020x300bFocalLength8 Four 16 bit integers: 0) unknown, 1) focal length in mm, 2-3) sensor width and height in units of 1/1000 inch
0x102a0x040x300bCanonShotInfovaries Data block giving shot information
0x102c-0x300bCanonColorInfo2256 Data block of color information (format unknown)
0x102d0x010x300bCanonCameraSettingsvaries Data block giving camera settings
0x1030-0x300bWhiteSample102 or 118 White sample information with encrypted 8x8 sample data
0x1031-0x300bSensorInfo34 Sensor size and resolution information
0x10330x0f0x300bCanonCustomFunctionsvaries Data block giving Canon custom settings
0x10380x120x300bCanonAFInfovaries Data block giving AF-specific information
0x10390x130x300b?8-
0x103c-0x300b?156-
0x107f-0x300b-varies-
0x10930x930x300bCanonFileInfo18 Data block giving file-specific information
0x10a80xa80x300b?20-
0x10a90xa90x300bColorBalance82 Table of 16-bit integers. The first integer (like many other data blocks) is the number of bytes in the record. This is followed by red, green1, green2 and blue levels for WhiteBalance settings: auto, daylight, shade, cloudy, tungsten, fluorescent, flash, custom and kelvin. The final 4 entries appear to be some sort of baseline red, green1, green2 and blue levels.
0x10aa0xaa0x300b?10-
0x10ad-0x300b?62-
0x10ae0xae0x300bColorTemperature2 16-bit integer giving the color temperature
0x10af-0x300b?2-
0x10b40xb40x300bColorSpace2 16-bit integer specifying the color space (1=sRGB, 2=Adobe RGB, 0xffff=uncalibrated)
0x10b50xb50x300bRawJpgInfo10 Data block giving embedded JPG information
0x10c00xc00x300b?26-
0x10c10xc10x300b?26-
0x10c2-0x300b?884-
4-Byte Alignment
0x1803-0x300aImageFormat8 32-bit integer specifying image format (0x20001 for CRW), followed by 32-bit float giving target compression ratio
0x1804-0x300aRecordID4 The number of pictures taken since the camera was manufactured
0x1805-0x3002-8-
0x1806-0x3002SelfTimerTime4 32-bit integer giving self-timer time in milliseconds
0x1807-0x3002TargetDistanceSetting4 32-bit float giving target distance in mm
0x180b0x0c0x3004SerialNumber4 The camera body number for EOS models. eg) 00560012345
0x180e-0x300aTimeStamp12 32-bit integer giving the time in seconds when the picture was taken, followed by a 32-bit timezone in seconds
0x1810-0x300aImageInfo28 Data block containing image information, including rotation
0x1812-0x3004-40-
0x1813-0x3002FlashInfo8 Two 32-bit floats: The flash guide number and the flash threshold
0x1814-0x3003MeasuredEV4 32-bit float giving the measured EV
0x18170x080x300aFileNumber4 32-bit integer giving the number of this file. eg) 1181834
0x1818-0x3002ExposureInfo12 Three 32-bit floats: Exposure compensation, Tv, Av
0x1819-0x300b-64-
0x18340x100x300bCanonModelID4 Unsigned 32-bit integer giving unique model ID
0x1835-0x300bDecoderTable16 RAW decoder table information
0x183b0x150x300bSerialNumberFormat4 32-bit integer (0x90000000=format 1, 0xa0000000=format 2)
Mixed Data Records
0x2005-rootRawDatavaries The raw data itself (the bulk of the CRW file)
0x2007-rootJpgFromRawvaries The embedded JPEG image (2048x1360 pixels for the 300D with Canon firmware)
0x2008-rootThumbnailImagevaries Thumbnail image (JPEG, 160x120 pixels)
SubDirectory Blocks
0x2804-0x300aImageDescriptionvaries The image description subdirectory
0x2807-0x300aCameraObjectvaries The camera object subdirectory
0x3002-0x300aShootingRecordvaries The shooting record subdirectory
0x3003-0x300aMeasuredInfovaries The measured information subdirectory
0x3004-0x2807CameraSpecificationvaries The camera specification subdirectory
0x300a-rootImagePropsvaries The main subdirectory containing all meta information
0x300b-0x300aExifInformationvaries The subdirectory containing most of the JPEG/TIFF EXIF information

Revisions

Mar. 21, 2018 - Added mention of the CR3 file format

Sep. 20, 2010 - Added note about XMP support in the VRD data

Feb. 12, 2009 - Moved a couple of entries in the TagID table that were in the wrong section

Feb. 4, 2008 - Added a number of unknown TagID's, decode some tags in the WhiteSample and DecoderTable data blocks, and fix incorrect SubDir for SerialNumber tag

Nov. 16, 2007 - Added a number of unknown blocks

Sep. 12, 2007 - Change name of CanonPictureInfo record to CanonAFInfo

Nov. 28, 2006 - Highlight the possibility of OtherData existing in the directory block


Please e-mail me if you find any errors or omissions in this document. My address is philharvey66 at gmail.com - Thanks!

Created Jan. 28, 2005
Last revised Mar. 21, 2018

<-- Back to ExifTool home page