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
Value
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.
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
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!)
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
Name
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.
Tag Bits
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
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:
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
?
-
DataFormat
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 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.
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
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)
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
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!