Sony has not published ARW. This page follows the open source decoders (dcraw and its successors) and ExifTool. An ARW file is a little-endian TIFF file.
Directories
| Directory | Content |
|---|---|
| IFD 0 | A JPEG preview, make and model, the Exif IFD (with Sony’s maker note), and the tags below. |
| IFD 1 | A small JPEG thumbnail. |
| Raw IFD | Reached through SubIFDs (0x014A) on most cameras: ImageWidth, ImageLength, BitsPerSample, Compression, CFA tags, StripOffsets or TileOffsets, and the tone curve 0x7010. |
| SR2 private data | Pointed to by DNGPrivateData (0xC634) in IFD 0: an IFD with the keys to the encrypted SR2 sub-IFD (below). |
SR2 private data
The private IFD holds the tags below; the sub-IFD they point to is encrypted and, once decrypted, is a further IFD with the black levels and white balance. ExifTool notes that the information is written to ARW files by other models too, and that SR2 files come from the DSC-R1.
| Tag | Name | Meaning |
|---|---|---|
0x7200 | SR2SubIFDOffset | Offset of the encrypted sub-IFD |
0x7201 | SR2SubIFDLength | Its length in bytes |
0x7221 | SR2SubIFDKey | The 32-bit key |
0x7240, 0x7241 | IDC_IFD, IDC2_IFD | Sony Image Data Converter settings (the SonyIDC table was not in the text read) |
0x7250 | MRWInfo | Minolta-style raw information, on some early models |
Tags of the decrypted SR2 sub-IFD (ExifTool; none are writable). The white balance levels are four or three signed shorts:
| Tag | Name | Type |
|---|---|---|
0x7300, 0x7310 | BlackLevel | 4 shorts |
0x7302, 0x7303 | WB_GRBGLevelsAuto, WB_GRBGLevels | 4 signed shorts (green, red, blue, green) |
0x7312, 0x7313 | WB_RGGBLevelsAuto, WB_RGGBLevels | 4 signed shorts |
0x7480–0x7486 | WB_RGBLevels for Daylight (7480), Cloudy (7481), Tungsten (7482), Flash (7483), 4500K (7484), Fluorescent (7486) | 4 signed shorts |
0x74A0–0x74A3 | MaxApertureAtMaxFocal, MaxApertureAtMinFocal, MaxFocalLength, MinFocalLength | – |
0x74C0 | SR2DataIFD | Directory; its tag 0x7770 is ColorMode |
0x7800 | ColorMatrix | – |
0x7820–0x782D | WB_RGBLevels for Daylight, Cloudy, Tungsten, Flash, 4500K, Shade, Fluorescent, FluorescentP1, FluorescentP2, FluorescentM1, 8500K, 6000K, 3200K, 2500K | 3 signed shorts |
0x787F | WhiteLevel | 3 shorts |
0x797D, 0x7980, 0x7982 | VignettingCorrParams, ChromaticAberrationCorrParams, DistortionCorrParams | – |
The maker note’s RAWFileType (0x2029) tells the storage: 0 compressed, 1
uncompressed, 2 lossless compressed, 3 compressed 2, 65535 not applicable. FileFormat
(0xB000, four bytes) separates JPEG, SR2 (1 0 0 0) and the ARW versions (2 0
0 0 is ARW 1.0, 6 0 0 0 is ARW 6.0).
Decryption works on 32-bit big-endian words. A table of 128 words is seeded from the
key with key = key × 48828125 + 1 for the first four, then each further
word is (pad[p−4] ^ pad[p−2]) << 1 | (pad[p−3] ^ pad[p−1]) >> 31.
Each data word is XORed with pad[p] ^ pad[p+64] (indices modulo 128), and
that value replaces pad[p−1]. In dcraw’s sony_decrypt the
fourth pad word is first replaced by pad[3] << 1 | (pad[0] ^ pad[2]) >> 31,
the words from 4 to 126 follow the recurrence above, and all 127 are then byte-swapped
to big-endian before use.
Compression
| Compression | Raw data |
|---|---|
| 1 | Uncompressed: 12 or 14-bit values stored in 16 bits each, row by row |
| 32767 | Sony compressed: the lossy 8-bits-per-pixel coding below on almost all cameras; a Huffman coding on the earliest ARW cameras such as the DSLR-A100 |
| 7 | Lossless compressed (newer cameras): tiled lossless JPEG |
Lossy compressed raw
Each row is cut into 32-column stretches. Within a stretch, the 16 pixels of one colour (every other column) are coded in one 16-byte block, then the 16 pixels of the other colour in the next block. A block is read as a little-endian bit string:
| Bits | Field |
|---|---|
| 0–10 | max: the largest value of the 16 |
| 11–21 | min: the smallest value |
| 22–25 | imax: which of the 16 pixels holds max |
| 26–29 | imin: which pixel holds min |
| 30–127 | 14 × 7 bits: the other pixels, in order |
A shift sh is the smallest value from 0 to 4 with
0x80 << sh > max − min. Each 7-bit value v becomes
(v << sh) + min, capped at 2047. The 11-bit results are then mapped
through the tone curve to linear values.
The curve comes from tag 0x7010: four knee points (each stored as a
short and shifted right by 2), between 0 and 4095 on the 12-bit scale. Between
successive knees the slope doubles: 1, 2, 4, 8, 16. dcraw applies it to twice the 11-bit
value.
Early Huffman coding
The earliest ARW cameras coded each column from right to left, even rows first and then odd rows, as lossless-JPEG-style Huffman differences from the previous value, using a fixed table of 18 codes. A running sum gives the 12-bit value.
dcraw’s table is the 18 values 0xF11, 0xF10, 0xE0F, 0xD0E, 0xC0D, 0xB0C, 0xA0B,
0x90A, 0x809, 0x708, 0x607, 0x506, 0x405, 0x304, 0x303, 0x300, 0x202, 0x201. The
high byte is the code length and the low byte the symbol (the number of difference
bits); the lookup is a 15-bit table in which each entry fills 215 − length
slots. The decoder walks the columns from the last to the first, rows 0, 2, 4, … and
then 1, 3, 5, …, and a sum above 12 bits is an error.
Sources
- ExifTool: Sony tags – RAWFileType, FileFormat, SR2Private, SR2SubIFD and SR2DataIFD tables
- dcraw.c (ncruces mirror) –
sony_decrypt,sony_arw_load_raw,sony_arw2_load_raw, read as a description - The tone curve tag
0x7010, the compression codes 7 and 32767 and the SubIFDs layout are from the earlier reading and were not in the text re-read here
Earlier formats
Sony’s first raw format, SRF, encrypts the image data itself with the same word cipher; ARW uses it only for the SR2 private data.