Nikon has not published NEF. This page describes what open source decoders (dcraw
and its successors) and ExifTool have worked out. A NEF file is a TIFF file; most are
big-endian (MM).
Directories
| Directory | Content |
|---|---|
| IFD 0 | A small uncompressed RGB thumbnail, the camera make and model, and the SubIFDs tag (0x014A) and Exif IFD pointer. |
| Sub-IFD with NewSubfileType 1 | A JPEG preview (JPEGInterchangeFormat and its length). |
| Sub-IFD with NewSubfileType 0 | The raw data: ImageWidth, ImageLength, BitsPerSample 12 or 14, Compression, PhotometricInterpretation 32803 (colour filter array), StripOffsets, StripByteCounts, CFARepeatPatternDim and CFAPattern. |
| Exif IFD | Exposure data and the Nikon maker note (0x927C). |
| Compression | Raw data |
|---|---|
| 1 | Uncompressed, possibly packed (see NEFCompression below) |
| 34713 | Nikon’s own compression |
Maker note
In NEF files the maker note starts with its own header and holds a complete TIFF structure, so its offsets are relative to that inner header, not to the file:
| Offset | Size | Content |
|---|---|---|
| 0 | 6 | Nikon and a zero byte |
| 6 | 4 | Maker note version, such as 02 10 00 00 |
| 10 | 8 | TIFF header: byte order, 42, and the offset of the maker note IFD (usually 8) |
| 18 | varies | The maker note IFD and its data |
Tags a raw decoder needs:
| Tag | Name | Use |
|---|---|---|
0x000C | WB_RBLevels | Red and blue white balance multipliers |
0x001D | SerialNumber | Key for decrypting other tags |
0x003D | BlackLevel | Four black levels, one per CFA colour |
0x0093 | NEFCompression | How the raw data is stored (below) |
0x0096 | NEFLinearizationTable | Decoder header and tone curve for compressed data (below) |
0x0097 | ColorBalance | White balance data; encrypted from version 0200 onwards |
0x00A7 | ShutterCount | Second key for decryption |
0x0E22 | NEFBitDepth | 12 or 14, or 8 × 3 and 16 × 3 for RGB data |
Encrypted tags (ShotInfo 0x0091, ColorBalance 0x0097 and
others) are decrypted with an XOR stream whose keys come from look-up tables indexed by
the serial number and by the four bytes of the shutter count combined. The tables are
in dcraw and ExifTool.
NEFCompression
| Value | Storage |
|---|---|
| 1 | Lossy (type 1) |
| 2 | Uncompressed |
| 3 | Lossless |
| 4 | Lossy (type 2) |
| 5 | Striped packed 12 bits |
| 6 | Uncompressed, reduced to 12 bits |
| 7 | Unpacked 12 bits |
| 8 | Small (reduced size raw) |
| 9 | Packed 12 bits |
| 10 | Packed 14 bits |
| 13 | High Efficiency |
| 14 | High Efficiency ★ |
The High Efficiency modes of the Z cameras are reported to use intoPIX’s TicoRAW codec, which is not publicly documented.
Linearisation table
Tag 0x0096 starts the information a decoder needs for Compression 34713.
Numbers are in the maker note’s byte order.
| Offset | Size | Field |
|---|---|---|
| 0 | 1 | Version byte 0: 0x44 lossy, 0x46 lossless |
| 1 | 1 | Version byte 1: 0x20 for lossy type 2 with a split |
| 2 | 8 | Four 16-bit starting predictors: even rows (columns 0, 1), odd rows (columns 0, 1) |
| 10 | 2 | Number of curve points |
| 12 | 2 each | The curve. For version 44 20, outputs for evenly spaced inputs, to be interpolated; otherwise a full lookup table with one entry per input value. Lossless files (0x46) do not use it. |
| 562 | 2 | For version 44 20: the row at which the second Huffman table takes over |
When version byte 0 is 0x49 or byte 1 is 0x58, the data
above starts 2110 bytes later.
Nikon compression
- Rows are coded one after another, each pixel as a Huffman-coded difference. The Huffman code gives the number of difference bits; then come the bits of the difference, read as in lossless JPEG (a leading 0 bit means a negative value).
- The first two pixels of each row are predicted from the pixel two rows above (the starting predictors for the first rows); the others from the pixel two columns to the left. The prediction follows the 2 × 2 colour pattern.
- Lossy files map the result through the curve to the linear 12 or 14-bit value; the curve spaces bright values further apart.
- There are six fixed Huffman tables: 12-bit lossy, 12-bit lossy after the split,
12-bit lossless, and the same three for 14 bits. Version
0x46selects lossless; 14-bit data selects the 14-bit tables.
Uncompressed and packed data is read row by row: packed 12-bit data holds two values in three bytes, 14-bit data four values in seven bytes.