A DNG file is a TIFF file, in either byte order, that follows TIFF 6.0 and TIFF/EP and adds the tags on the tags page. This page covers how the images inside it are organised and stored.
Directories
- The file starts with a normal TIFF header:
IIorMM, the number 42, and the offset of IFD 0. - IFD 0 holds
DNGVersionand the other tags that describe the camera and its colour. It is usually a small preview image. - The raw image is in IFD 0 itself or, more often, in one of the sub-IFDs listed by
the TIFF tag
SubIFDs(0x014A). Further sub-IFDs can hold larger previews, masks and depth maps. - The Exif IFD (
0x8769) and GPS IFD (0x8825) hang off IFD 0 as in any TIFF file.
Each image directory is marked by NewSubFileType (0x00FE):
| NewSubFileType | Image |
|---|---|
| 0 | The main image: the raw data |
| 1 | A preview (reduced-resolution image) |
0x10001 | An alternative preview, such as one in another colour space |
| 4 | Transparency mask of the main image |
| 5 | Transparency mask of a preview |
| 8 | Depth map of the main image |
| 9 | Depth map of a preview |
| 16 | Enhanced image data: the main image after processing such as demosaicing |
0x10004 | Semantic mask, such as a sky or skin mask |
Photometric interpretation
| Value | Data |
|---|---|
| 32803 | Colour filter array: one sample per pixel through the sensor’s filter pattern (most raw images) |
| 34892 | Linear raw: full colour samples per pixel, already demosaiced but not colour-converted |
| 51177 | Depth map |
| 52527 | Semantic mask |
| 1, 2, 6 | Black is zero, RGB, YCbCr: previews |
| 4 | Transparency mask |
Compression
| Compression | Meaning in DNG |
|---|---|
| 1 | Uncompressed. Samples of 8 to 32 bits; sizes other than 8, 16 and 32 are packed, most significant bit first. |
| 7 | JPEG. For raw data: lossless Huffman JPEG (ITU T.81 process 14), one JPEG stream per tile or strip. For previews: baseline JPEG. |
| 8 | Deflate (zlib), used for floating point raw data and depth maps. |
| 34892 | Lossy JPEG, for raw data that has been compressed with loss (DNG 1.4). |
| 52546 | JPEG XL (DNG 1.7), for raw data and previews. |
Deflate-compressed data can use these Predictor values (floating point
data has SampleFormat 3, at 16, 24 or 32 bits):
| Predictor | Meaning |
|---|---|
| 1 | None |
| 2 | Horizontal differencing (TIFF) |
| 3 | Floating point: bytes regrouped by significance, then differenced (Adobe’s TIFF technical note 3) |
| 34892 | Horizontal differencing, two samples apart |
| 34893 | Horizontal differencing, four samples apart |
| 34894 | Floating point, two samples apart |
| 34895 | Floating point, four samples apart |
Raw images are normally tiled (TileWidth, TileLength,
TileOffsets, TileByteCounts) so they can be decoded in
parallel; strips are also allowed.
Colour filter array
A CFA image uses the TIFF/EP tags CFARepeatPatternDim
(0x828D, rows and columns of the repeating pattern) and
CFAPattern (0x828E, one colour code per cell, row by row),
with the DNG tags CFAPlaneColor and CFALayout.
| CFAPattern code | Colour |
|---|---|
| 0 | Red |
| 1 | Green |
| 2 | Blue |
| 3 | Cyan |
| 4 | Magenta |
| 5 | Yellow |
| 6 | White |
A Bayer RGGB sensor has CFARepeatPatternDim 2, 2 and
CFAPattern 0, 1, 1, 2. CFAPlaneColor (default 0, 1, 2) maps
the plane numbers to these codes.
| CFALayout | Sensor grid |
|---|---|
| 1 | Rectangular (square) layout |
| 2 | Staggered: even columns offset down ½ row |
| 3 | Staggered: even columns offset up ½ row |
| 4 | Staggered: even rows offset right ½ column |
| 5 | Staggered: even rows offset left ½ column |
| 6 | Even rows offset up ½ row, even columns offset left ½ column |
| 7 | Even rows offset up ½ row, even columns offset right ½ column |
| 8 | Even rows offset down ½ row, even columns offset left ½ column |
| 9 | Even rows offset down ½ row, even columns offset right ½ column |
From raw values to a picture
- Read the stored samples and apply
OpcodeList1(see opcodes). - Map them through
LinearizationTable, if present. - Subtract the black level (
BlackLevelplusBlackLevelDeltaHandBlackLevelDeltaV) and scale so thatWhiteLevelbecomes 1.0. Only theActiveAreais used;MaskedAreasare covered pixels for measuring black. - Apply
OpcodeList2. - Demosaic a CFA image to full colour, then apply
OpcodeList3. - Crop to
DefaultCropOriginandDefaultCropSize, and scale byDefaultScale. - Convert from camera colour to CIE XYZ with the colour matrices, interpolating
between the calibration illuminants for the white balance in
AsShotNeutralorAsShotWhiteXY.