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: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.
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!
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 A series of characters identifying the file as a Canon CRW file. 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.
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.
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 BlockSize - 4 4 S DirStart 32-bit integer giving the size of the ValueData
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...).
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).
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 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.
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 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 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 ? -
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 0x0032 - 0x300b CanonColorInfo1 2048 Block of color information (format unknown) ASCII Strings 0x0805 - 0x2804 CanonFileDescription 32 Description of the file format. ie) "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. ie) "Canon","Canon EOS DIGITAL REBEL" 0x080b 0x07 0x3004 CanonFirmwareVersion 32 Firmware version. ie) "Firmware Version 1.1.1" 0x080c - ? ComponentVersion ? - 0x080d - 0x3004 ROMOperationMode 4 ie) The string "USA" for 300D's sold in North America 0x0810 0x09 0x2807 OwnerName 32 Owner's name. ie) "Phil Harvey" 0x0815 0x06 0x2804 CanonImageType 32 Type of file. ie) "CRW:EOS DIGITAL REBEL CMOS RAW" 0x0816 - 0x300a OriginalFileName 32 Original file name. ie) "CRW_1834.CRW" 0x0817 - 0x300a ThumbnailFileName 32 Thumbnail file name. ie) "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 0x1016 - 0x3002 ReleaseSetting 2 - 0x101c - 0x3004 BaseISO 2 The camera body's base ISO sensitivity 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 - ? CanonColorInfo2 ? Data block of color information (format unknown) 0x102d 0x01 0x300b CanonCameraSettings 92 Data block giving camera settings 0x1030 - ? WhiteSample ? Encrypted 8x8 white sample 0x1031 - 0x300b SensorInfo 34 Sensor size and resolution information 0x1033 0x0f 0x300b CanonCustomFunctions Varies Data block giving Canon custom settings 0x1038 0x12 0x300b CanonPictureInfo Varies Data block giving picture-specific information 0x1039 0x13 0x300b ? 8 - 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 - 0x10ae 0xae 0x300b ColorTemperature 2 16-bit integer giving the color temperature 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 - 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 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 0x2807 SerialNumber 4 The camera body number. ie) 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 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. ie) 1181834 0x1818 - 0x3002 ExposureInfo 12 Three 32-bit floats: Exposure compensation, Tv, Av 0x1834 0x10 0x300b CanonModelID 4 Unsigned 32-bit integer giving unique model ID 0x1835 - 0x300b DecoderTable 16 RAW decoder table 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
P. Harvey - Last revised Jun. 27, 2006