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 uses two different RAW formats, and newer models produce CR2 instead of CRW files. The CR2 files use a TIFF-based format, which is different than the CRW CIFF format documented here. (See this page for details about the CR2 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.
A Canon CRW file starts with the following byte sequence:
Offset Number
of bytesValue Name Description 0 2 "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. 2 4 0x0000001a HeaderLength 32-bit integer giving the length of the CRW file header. For current camera models the header is 26 bytes long. 6 8 "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. 14 4 0x00010002 CRWVersion 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. 18 8 0 Reserved Two 32-bit integers, currently set to zero.
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 blockNumber
of bytesValue Name Description 0 S -
-
-
-
-ValueData The value data referenced by offsets in the directory S 2 N DirCount 16-bit integer giving the number of directory entries S + 2 N * 10 -
-
-DirEntries The CRW directory entries S + 2 + N*10 any - OtherData (be aware there may be other data hiding here) BlockSize - 4 4 S DirStart 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!)
The CRW directory consists of N 10-byte entries. The format of each entry is as follows:
Offset
within entryNumber
of bytesName Description 0 2 Tag 16-bit integer identifying the type of data 2 4 Size 32-bit integer giving the number of bytes in the value data 6 4 Offset 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.
The 16-bit Tag value is composed of 3 bit fields, as follows:
Bits Mask Name Description 14-15 0xc000 DataLocation Specifies the location of the data 11-13 0x3800 DataFormat Identifies the information format 0-10 0x07ff TagIndex Index to identify the specific type of information
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:
DataLocation Where Description 0x0000 ValueData Values are stored in the ValueData block, at the specified Offset and Size 0x4000 Directory 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? -
Three Tag bits are used to specify the data format:
DataFormat Alignment Description 0x0000 1-Byte A series of bytes 0x0800 1-Byte A null-terminated ASCII string 0x1000 2-Byte A series of 16-bit integers 0x1800 4-Byte A series of 32-bit integers or floats 0x2000 1-Byte A structure which is a mixture of formats 0x2800
0x30001-Byte A subdirectory block 0x3800 ? -
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.
TagID EXIF SubDir Name Size Description 1-Byte Alignment 0x0000 - any NullRecord 0 This is a null directory entry 0x0001 - any FreeBytes varies Unused bytes in the ValueData 0x0006 - 0x300b - 8 - 0x0032 - 0x300b CanonColorInfo1 768 or 2048 Block of color information (format unknown) 0x0036 - 0x300b ? varies - 0x003f - 0x300b ? 5120 - 0x0040 - 0x300b ? 256 - 0x0041 - 0x300b ? 256 - ASCII Strings 0x0805 - 0x2804 CanonFileDescription 32 Description of the file format. eg) "EOS DIGITAL REBEL CMOS RAW" 0x0805 - 0x300a UserComment 256 User comment (usually blank) 0x080a - 0x2807 CanonRawMakeModel 32 Two end-to-end null-terminated ASCII strings giving the camera make and model. eg) "Canon","Canon EOS DIGITAL REBEL" 0x080b 0x07 0x3004 CanonFirmwareVersion 32 Firmware version. eg) "Firmware Version 1.1.1" 0x080c - ? ComponentVersion ? - 0x080d - 0x3004 ROMOperationMode 4 eg) The string "USA" for 300D's sold in North America 0x0810 0x09 0x2807 OwnerName 32 Owner's name. eg) "Phil Harvey" 0x0815 0x06 0x2804 CanonImageType 32 Type of file. eg) "CRW:EOS DIGITAL REBEL CMOS RAW" 0x0816 - 0x300a OriginalFileName 32 Original file name. eg) "CRW_1834.CRW" 0x0817 - 0x300a ThumbnailFileName 32 Thumbnail file name. eg) "CRW_1834.THM" 2-Byte Alignment 0x100a - 0x300a TargetImageType 2 0=real-world subject, 1=written document 0x1010 - 0x3002 ShutterReleaseMethod 2 0=single shot, 1=continuous shooting 0x1011 - 0x3002 ShutterReleaseTiming 2 0=priority on shutter, 1=priority on focus 0x1014 - 0x3002 - 8 - 0x1016 - 0x3002 ReleaseSetting 2 - 0x101c - 0x3004 BaseISO 2 The camera body's base ISO sensitivity 0x1026 - 0x300a - 6 - 0x1028 0x03 0x300b CanonFlashInfo? 8 Unknown information, flash related 0x1029 0x02 0x300b FocalLength 8 Four 16 bit integers: 0) unknown, 1) focal length in mm, 2-3) sensor width and height in units of 1/1000 inch 0x102a 0x04 0x300b CanonShotInfo varies Data block giving shot information 0x102c - 0x300b CanonColorInfo2 256 Data block of color information (format unknown) 0x102d 0x01 0x300b CanonCameraSettings varies Data block giving camera settings 0x1030 - 0x300b WhiteSample 102 or 118 White sample information with encrypted 8x8 sample data 0x1031 - 0x300b SensorInfo 34 Sensor size and resolution information 0x1033 0x0f 0x300b CanonCustomFunctions varies Data block giving Canon custom settings 0x1038 0x12 0x300b CanonAFInfo varies Data block giving AF-specific information 0x1039 0x13 0x300b ? 8 - 0x103c - 0x300b ? 156 - 0x107f - 0x300b - varies - 0x1093 0x93 0x300b CanonFileInfo 18 Data block giving file-specific information 0x10a8 0xa8 0x300b ? 20 - 0x10a9 0xa9 0x300b ColorBalance 82 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. 0x10aa 0xaa 0x300b ? 10 - 0x10ad - 0x300b ? 62 - 0x10ae 0xae 0x300b ColorTemperature 2 16-bit integer giving the color temperature 0x10af - 0x300b ? 2 - 0x10b4 0xb4 0x300b ColorSpace 2 16-bit integer specifying the color space (1=sRGB, 2=Adobe RGB, 0xffff=uncalibrated) 0x10b5 0xb5 0x300b RawJpgInfo 10 Data block giving embedded JPG information 0x10c0 0xc0 0x300b ? 26 - 0x10c1 0xc1 0x300b ? 26 - 0x10c2 - 0x300b ? 884 - 4-Byte Alignment 0x1803 - 0x300a ImageFormat 8 32-bit integer specifying image format (0x20001 for CRW), followed by 32-bit float giving target compression ratio 0x1804 - 0x300a RecordID 4 The number of pictures taken since the camera was manufactured 0x1805 - 0x3002 - 8 - 0x1806 - 0x3002 SelfTimerTime 4 32-bit integer giving self-timer time in milliseconds 0x1807 - 0x3002 TargetDistanceSetting 4 32-bit float giving target distance in mm 0x180b 0x0c 0x3004 SerialNumber 4 The camera body number for EOS models. eg) 00560012345 0x180e - 0x300a TimeStamp 12 32-bit integer giving the time in seconds when the picture was taken, followed by a 32-bit timezone in seconds 0x1810 - 0x300a ImageInfo 28 Data block containing image information, including rotation 0x1812 - 0x3004 - 40 - 0x1813 - 0x3002 FlashInfo 8 Two 32-bit floats: The flash guide number and the flash threshold 0x1814 - 0x3003 MeasuredEV 4 32-bit float giving the measured EV 0x1817 0x08 0x300a FileNumber 4 32-bit integer giving the number of this file. eg) 1181834 0x1818 - 0x3002 ExposureInfo 12 Three 32-bit floats: Exposure compensation, Tv, Av 0x1819 - 0x300b - 64 - 0x1834 0x10 0x300b CanonModelID 4 Unsigned 32-bit integer giving unique model ID 0x1835 - 0x300b DecoderTable 16 RAW decoder table information 0x183b 0x15 0x300b SerialNumberFormat 4 32-bit integer (0x90000000=format 1, 0xa0000000=format 2) Mixed Data Records 0x2005 - root RawData varies The raw data itself (the bulk of the CRW file) 0x2007 - root JpgFromRaw varies The embedded JPEG image (2048x1360 pixels for the 300D with Canon firmware) 0x2008 - root ThumbnailImage varies Thumbnail image (JPEG, 160x120 pixels) SubDirectory Blocks 0x2804 - 0x300a ImageDescription varies The image description subdirectory 0x2807 - 0x300a CameraObject varies The camera object subdirectory 0x3002 - 0x300a ShootingRecord varies The shooting record subdirectory 0x3003 - 0x300a MeasuredInfo varies The measured information subdirectory 0x3004 - 0x2807 CameraSpecification varies The camera specification subdirectory 0x300a - root ImageProps varies The main subdirectory containing all meta information 0x300b - 0x300a ExifInformation varies The subdirectory containing most of the JPEG/TIFF EXIF information
Sept. 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
Sept. 12, 2007 - Change name of CanonPictureInfo record to CanonAFInfo
Nov. 28, 2006 - Highlight the possibility of OtherData existing in the directory block
Created Jan. 28, 2005
Last revised Sept. 20, 2010