DNG File Specification
DNG File Specification
Corporate Headquarters
345 Park Avenue
San Jose, CA 95110- 2704
(408) 536-6000
http://www.adobe.com
Digital Negative (DNG)
Specification
Version 1.4.0.0
June 2012
2
x
= 2 ( )
wherep
denotes the photon noise, expressed in photons. The conversion factor between
photons (x
= 3 ( )
p g p
= 4 ( )
Substituting equations 2, 3, and 4 into equation 1 yields:
N
2
g p
( )
2
r
2
+ =
g
2
x
( ) r
2
+ =
g x ( ) r
2
+ =
Therefore the total noiseN can be expressed as a two-parameter function of the signal x:
N x ( ) g x r
2
+ =
S
i
s O
i
+ =
for model parameters S
i
g O
i
r
2
= , = .
This tag uses the convention of a normalized noise model, i.e., N x ( ) is the standard deviation
(i.e., noise) of a random variable x, where x represents a recorded linear signal in the range
x 01 [ , ] e . The specified parameters (S
i
O
i
, ) must also be appropriately normalized.
Digital Negative Specification September 2012 70
DNG Tags
Additional Tags for Version 1.4.0.0
4
Additional Tags for Version 1.4.0.0
The following tags have been added for the 1.4.0.0 version of this specification.
DefaultUserCrop
Tag 51125 (C7B5.H)
Type RATIONAL
Count 4
Value Value 0: 0.0
Value 1: 0.0
Value 2: 1.0
Value 3: 1.0
Default Value 0: 0.0
Value 1: 0.0
Value 2: 1.0
Value 3: 1.0
Usage Raw IFD
Description
Specifies a default user crop rectangle in relative coordinates.
The values must satisfy:
0.0 <= top < bottom <= 1.0
0.0 <= left < right <= 1.0
The default values of (top = 0, left = 0, bottom = 1, right = 1) correspond exactly to the default
crop rectangle (as specified by the DefaultCropOrigin and DefaultCropSize tags).
Digital Negative Specification September 2012 71
DNG Tags
DefaultBlackRender
4
DefaultBlackRender
Tag 51110 (C7A6.H)
Type LONG
Count 1
Value See below
Default 0
Usage IFD 0 or Camera Profile IFD
Description
This optional tag in a color profile provides a hint to the raw converter regarding how to handle
the black point (e.g., flare subtraction) during rendering. The currently defined values are:
0 = Auto
1 = None
If set to Auto, the raw converter should perform black subtraction during rendering. The
amount and method of black subtraction may be automatically determined and may be image-
dependent.
If set to None, the raw converter should not perform any black subtraction during rendering.
This may be desirable when using color lookup tables (e.g., LookTable) or tone curves in
camera profiles to perform a fixed, consistent level of black subtraction.
BaselineExposureOffset
Tag 51109 (C7A5.H)
Type RATIONAL
Count 1
Value See below
Default 0.0
Usage IFD 0 or Camera Profile IFD
Description
Provides a way for color profiles to increase or decrease exposure during raw conversion.
Digital Negative Specification September 2012 72
DNG Tags
ProfileLookTableEncoding
4
BaselineExposureOffset specifies the amount (in EV units) to add to the BaselineExposure tag
during image rendering. For example, if the BaselineExposure value for a given camera model
is +0.3, and the BaselineExposureOffset value for a given camera profile used to render an
image for that camera model is -0.7, then the actual default exposure value used during
rendering will be +0.3 - 0.7 = -0.4.
ProfileLookTableEncoding
Tag 51108 (C7A4.H)
Type LONG
Count 1
Value See below
Default 0
Usage IFD 0 or Camera Profile IFD
Description
Provides a way for color profiles to specify how indexing into a 3D LookTable is performed
during raw conversion. This tag is not applicable to a 2.5D LookTable (i.e., where the Value
dimension is 1).
The currently defined values are:
0 = Linear encoding
1 = sRGB encoding
If set to 0 (Linear encoding), then the method used to apply a 3D LookTable is as follows:
1. Convert linear ProPhoto RGB values to HSV.
2. Use the HSV coordinates to index into the color table.
3. Apply color table result to the original HSV values.
4. Convert modified HSV values back to linear ProPhoto RGB.
If set to 1 (sRGB encoding), then the method used to apply a 3D LookTable is as follows:
1. Convert linear ProPhoto RGB values to HSV.
2. Encode V coordinate using the sRGB encoding curve.
3. Use the encoded HSV coordinates to index into the color table.
Digital Negative Specification September 2012 73
DNG Tags
ProfileHueSatMapEncoding
4
4. Apply color table result to the encoded values from step b.
5. Decode V coordinate using the sRGB decoding curve (inverse of step b).
6. Convert HSV values back to linear ProPhoto RGB (inverse of step a).
The second method (sRGB encoding) may be desirable to provide additional table precision to
dark (shadow) image values.
ProfileHueSatMapEncoding
Tag 51107 (C7A3.H)
Type LONG
Count 1
Value See below
Default 0
Usage IFD 0 or Camera Profile IFD
Description
Provides a way for color profiles to specify how indexing into a 3D HueSatMap is performed
during raw conversion. This tag is not applicable to 2.5D HueSatMap tables (i.e., where the
Value dimension is 1).
The currently defined values are:
0 = Linear encoding
1 = sRGB encoding
If set to 0 (Linear encoding), then the method used to apply a 3D HueSatMap is as follows:
1. Convert linear ProPhoto RGB values to HSV.
2. Use the HSV coordinates to index into the color table.
3. Apply color table result to the original HSV values.
4. Convert modified HSV values back to linear ProPhoto RGB.
If set to 1 (sRGB encoding), then the method used to apply a 3D HueSatMap is as follows:
1. Convert linear ProPhoto RGB values to HSV.
2. Encode V coordinate using the sRGB encoding curve.
Digital Negative Specification September 2012 74
DNG Tags
OriginalDefaultFinalSize
4
3. Use the encoded HSV coordinates to index into the color table.
4. Apply color table result to the encoded values from step b.
5. Decode V coordinate using the sRGB decoding curve (inverse of step b).
6. Convert HSV values back to linear ProPhoto RGB (inverse of step a).
The second method (sRGB encoding) may be desirable to provide additional table precision to
dark (shadow) image values.
OriginalDefaultFinalSize
Tag 51089 (C791.H)
Type SHORT or LONG
Count 2
Value Value 0: width
Value 1: length
Default See below
Usage IFD
Description
If this file is a proxy for a larger original DNG file, this tag specifics the default final size of
the larger original file from which this proxy was generated.
The default value for this tag is default final size of the current DNG file, which is
DefaultCropSize * DefaultScale.
Digital Negative Specification September 2012 75
DNG Tags
OriginalBestQualityFinalSize
4
OriginalBestQualityFinalSize
Tag 51090 (C792.H)
Type SHORT or LONG
Count 2
Value Value 0: width
Value 1: length
Default See below
Usage IFD
Description
If this file is a proxy for a larger original DNG file, this tag specifics the best quality final size
of the larger original file from which this proxy was generated.
The default value for this tag is the OriginalDefaultFinalSize, if specified. Otherwise the
default value for this tag is the best quality size of the current DNG file, which is
DefaultCropSize * DefaultScale * BestQualityScale.
OriginalDefaultCropSize
Tag 51091 (C793.H)
Type SHORT or LONG or
RATIONAL
Count 2
Value Value 0: width
Value 1: length
Default See below
Usage IFD 0
Description
If this file is a proxy for a larger original DNG file, this tag specifics the DefaultCropSize of
the larger original file from which this proxy was generated.
The default value for this tag is the OriginalDefaultFinalSize, if specified. Otherwise, the
default value for this tag is the DefaultCropSize of the current DNG file.
Digital Negative Specification September 2012 76
DNG Tags
NewRawImageDigest
4
NewRawImageDigest
Tag 51111 (C7A7.H)
Type BYTE
Count 16
Value See below
Default Optional
Usage IFD 0
Description
This tag is a modified MD5 digest of the raw image data. It has been updated from the
algorithm used to compute the RawImageDigest tag be more multi-processor friendly, and to
support lossy compression algorithms. The details of the algorithm used to compute this tag
are documented in the Adobe DNG SDK source code.
RawToPreviewGain
Tag 51112 (C7A8.H)
Type DOUBLE
Count 1
Value See below
Default 1.0
Usage Preview IFD
Description
The gain (what number the sample values are multiplied by) between the main raw IFD and
the preview IFD containing this tag.
Digital Negative Specification September 2012 77
5
Mapping Raw Values to Linear
Reference Values
The section describes DNG's processing model for mapping stored raw sensor values into
linear reference values.
Linear reference values encode zero light as 0.0, and the maximum useful value (limited by
either sensor saturation or analog to digital converter clipping) as 1.0. If SamplesPerPixel is
greater than one, each sample plane should be processed independently.
The processing model follows these steps:
Linearization
Black Subtraction
Rescaling
Clipping
Linearization
The first step is to process the raw values through the look-up table specified by the
LinearizationTable tag, if any. If the raw value is greater than the size of the table, it is mapped
to the last entry of the table.
Black Subtraction
The black level for each pixel is then computed and subtracted. The black level for each pixel
is the sum of the black levels specified by the BlackLevel, BlackLevelDeltaH and
BlackLevelDeltaV tags.
Rescaling
The black subtracted values are then rescaled to map them to a logical 0.0 to 1.0 range. The
scale factor is the inverse of the difference between the value specified in the WhiteLevel tag
and the maximum computed black level for the sample plane.
Digital Negative Specification September 2012 78
Mapping Raw Values to Linear Reference Values
Clipping
5
Clipping
The rescaled values are then clipped to a 0.0 to 1.0 logical range.
Digital Negative Specification September 2012 79
6
Mapping Camera Color Space to
CIE XYZ Space
This section describes the DNG processing model for mapping between the camera color
space coordinates (linear reference values) and CIE XYZ (with a D50 white point).
Camera Calibration Matrices
DNG 1.2.0.0 and later supports different companies creating the camera calibration tags using
different reference cameras.
When rendering a DNG file using a camera profile, it is important to know if the selected
camera profile was designed using the same reference camera used to create the camera
calibration tags. If so, then the camera calibration tags should be used. If not, then it is
preferable to ignore the camera calibration tags and use identity matrices instead in order to
minimize the worse case calibration mismatch error.
This matching is done by comparing the CameraCalibrationSignature tag and the
ProfileCalibrationSignature tag for the selected camera profile. If they match, then use the
camera calibration tags. If not, then use identity matrices.
One or Two Color Calibrations
DNG provides for one or two sets of color calibration tags, each set optimized for a different
illuminant. If both sets of color calibration tags are included, then the raw converter should
interpolate between the calibrations based on the white balance selected by the user.
If two calibrations are included, then it is recommended that one of the calibrations be for a
low color temperature illuminant (e.g., Standard-A) and the second calibration illuminant be
for a higher color temperature illuminant (e.g., D55 or D65). This combination has been found
to work well for a wide range of real-world digital camera images.
DNG versions earlier than 1.2.0.0 allow the raw converter to choose the interpolation
algorithm. DNG 1.2.0.0 and later requires a specific interpolation algorithm: linear
interpolation using inverse correlated color temperature.
To find the interpolation weighting factor between the two tag sets, find the correlated color
temperature for the user-selected white balance and the two calibration illuminants. If the
white balance temperature is between two calibration illuminant temperatures, then invert all
the temperatures and use linear interpolation. Otherwise, use the closest calibration tag set.
Digital Negative Specification September 2012 80
Mapping Camera Color Space to CIE XYZ Space
Definitions used in the following sections
6
Definitions used in the following sections
Let n be the dimensionality of the camera color space (usually 3 or 4).
Let CM be the n-by-3 matrix interpolated from the ColorMatrix1 and ColorMatrix2 tags.
Let CC be the n-by-n matrix interpolated from the CameraCalibration1 and
CameraCalibration2 tags (or identity matrices, if the signatures dont match).
Let AB be the n-by-n matrix, which is zero except for the diagonal entries, which are defined
by the AnalogBalance tag.
Let RM be the 3-by-n matrix interpolated from the ReductionMatrix1 and ReductionMatrix2
tags.
Let FM be the 3-by-n matrix interpolated from the ForwardMatrix1 and ForwardMatrix2 tags.
Translating White Balance xy Coordinates to Camera Neutral
Coordinates
If the white balance is specified in terms of a CIE xy coordinate, then a camera neutral
coordinate can be derived by first finding the correlated color temperature for the xy value.
This value determines the interpolation weighting factor between the two sets of color
calibration tags.
The XYZ to camera space matrix is:
XYZtoCamera = AB * CC * CM
The camera neutral can be found by expanding the xy value to a 3-by-1 XYZ matrix (assuming
Y = 1.0) and multiplying it by the XYZtoCamera matrix:
CameraNeutral = XYZtoCamera * XYZ
Translating Camera Neutral Coordinates to White Balance xy
Coordinates
This process is slightly more complex than the transform in the other direction because it
requires an iterative solution.
1. Guess an xy value. Use that guess to find the interpolation weighting factor between the
color calibration tags. Find the XYZtoCamera matrix as above.
Digital Negative Specification September 2012 81
Mapping Camera Color Space to CIE XYZ Space
Camera to XYZ (D50) Transform
6
2. Find a new xy value by computing:
XYZ = Inverse (XYZtoCamera) * CameraNeutral
(If the XYZtoCamera matrix is not square, then use the pseudo inverse.)
3. Convert the resulting XYZ to a new xy value.
4. Iterate until the xy values converge to a solution.
Camera to XYZ (D50) Transform
DNG 1.2.0.0 and later support two methods of specifying the camera to XYZ (D50) transform,
depending on whether or not the forward matrix tags are included in the camera profile.
The use of the forward matrix tags is recommended for two reasons. First, it allows the camera
profile creator to control the chromatic adaptation algorithm used to convert between the
calibration illuminant and D50. Second, it causes the white balance adjustment (if the user
white balance does not match the calibration illuminant) to be done by scaling the camera
coordinates rather than by adapting the resulting XYZ values, which has been found to work
better in extreme cases.
If the ForwardMatrix tags are not included in the camera profile:
1. First, invert the XYZtoCamera matrix.
If n = 3, this is:
CameraToXYZ = Inverse (XYZtoCamera)
If n > 3, and the reduction matrix tags are included, then:
CameraToXYZ = Inverse (RM * XYZtoCamera) * RM
Otherwise:
CameraToXYZ = PseudoInverse (XYZtoCamera)
2. The white balanced transform is computed:
CameraToXYZ_D50 = CA * CameraToXYZ
CA, above, is a chromatic adaptation matrix that maps from the white balance xy value to
the D50 white point. The recommended method for computing this chromatic adaptation
matrix is to use the linear Bradford algorithm.
Digital Negative Specification September 2012 82
Mapping Camera Color Space to CIE XYZ Space
If the ForwardMatrix tags are included in the camera profile:
6
If the ForwardMatrix tags are included in the camera profile:
CameraToXYZ_D50 = FM * D * Inverse (AB * CC)
D, above, is a diagonal n-by-n matrix, computed so that the CameraToXYZ_D50 matrix maps
the selected camera neutral to XYZ D50. The forward matrix is required to map a unit vector
to XYZ D50 by definition, so D can be computed by finding the neutral for the reference
camera:
ReferenceNeutral = Inverse (AB * CC) * CameraNeutral
And then: D = Invert (AsDiagonalMatrix (ReferenceNeutral))
Applying the Hue/Saturation/Value Mapping Table
After the camera colors have been converted to XYZ (D50) values, the Hue/Saturation/Value
mapping table, if any, is applied. If there are two Hue/Saturation/Value mapping tables, then
they are interpolated in the same way that color calibration tags are interpolated. If only one
Hue/Saturation/Value table is included, then it is used regardless of the selected white balance.
1. First, the XYZ (D50) values are converted to linear RGB coordinates, using the ProPhoto
RGB primaries. (This is also known as RIMM space).
2. The linear RGB coordinates are converted to HSV coordinates (Hue-Saturation-Value).
3. The HSV coordinates are used to index the mapping table using tri-linear interpolation,
resulting in three values: hue shift (in degrees); saturation scale factor; value scale factor. If
the division count in a dimension is 1, then the table is constant for that dimension.
4. Hue is indexed using wrap-around math. For example, if HueDivisions is equal to 3, then
the table samples are at 0 degrees (red), 120 degrees (green), and 240 degrees (blue).
5. The hue coordinate is modified by adding the hue shift.
6. The saturation coordinate is modified by multiplying by the saturation scale factor, and
then clipping to no more than 1.0.
7. The value coordinate is modified by multiplying by the value scale factor, and then clipping
to no more than 1.0.
8. The HSV coordinates are converted to linear RGB coordinates, and then back to XYZ
(D50) values.
It is recommended that these tables be limited to use a ValueDivisions equal to 1, so the table
is only indexed by hue and saturation. In this way, all colors with the same hue and saturation,
but with different values, map to the same new hue and saturation while preserving their value
ratios.
Digital Negative Specification September 2012 83
7
Opcode List Processing
An opcode list is a list of opcodes, each of which does some specified image processing
operation. Each opcode is performed in sequence.
Opcode lists are always stored in big-endian byte order, no matter what the files main byte
order is. This allows DNG utility programs to copy opcode lists from file to file, without
needing to understand their detailed internal structure.
At the start of opcode list, there is a 32-bit unsigned integer count, which contains the number
of opcodes in the list. This is followed by the data for each opcode.
Each opcode starts with a 32-bit unsigned integer, which contains the opcode ID. The opcode
ID identifies the specific opcode. Documentation for each supported opcode ID in provided
later in this chapter.
Next is a 32-bit unsigned integer, which contains the DNG specification version in which the
opcode ID was defined. It is expected that new opcode IDs will be defined in future DNG
specification versions. A DNG reader should never attempt to process an opcode with a
version higher than DNG specification it was written to support.
Next is a 32-bit unsigned integer, which contains various flag bits. There are two defined flag
bits. If bit 0 (the least significant bit) is set to 1, the opcode is considered optional, and the
DNG reader may decide to not apply this opcode if it wishes, or it does not understand the
opcode ID. If bit 1 (the second to least significant bit) is set to 1, the opcode can be skipped
when doing preview quality processing, and only needs to be applied when doing full
quality processing.
Next is a 32-bit unsigned integer, containing the number of bytes in a variable size parameter
area for the opcode. The format of this variable size parameter area is dependent on the
specific opcode ID, and is documented later in this chapter, along with each supported opcode
ID.
When processing an opcode list, image values are clipped after the application of each opcode
to the logical range of the image being modified. For OpcodeList1, this range is 0 to 2
32
1 for
images with a bit depth greater than 16, otherwise 0 to 2
16
1 . For OpcodeList2 and
OpcodeList3, the logical range is 0.0 to 1.0.
The rest of this chapter contains information on each supported opcode ID.
Digital Negative Specification September 2012 84
Opcode List Processing
WarpRectilinear
7
WarpRectilinear
Opcode ID 1
DNG Version 1.3.0.0
Parameters
N LONG
k
r
0
i ,
DOUBLE
k
r
1
i ,
DOUBLE
k
r
2
i ,
DOUBLE
k
r
3
i ,
DOUBLE
k
t
0
i ,
DOUBLE
k
t
1
i ,
DOUBLE
For each coefficient set i 1 2 . N , , , e :
c
x
DOUBLE
c
y
DOUBLE
Description
This opcode applies a warp to an image and can be used to correct geometric distortion and
lateral (transverse) chromatic aberration for rectilinear lenses. The warp function supports
both radial and tangential distortion correction.
Let K
i
k
r
0
i ,
k
r
1
i ,
k
r
2
i ,
k
r
3
i ,
k
t
0
i ,
k
t
1
i ,
, , , , , { } = denote the i th coefficient set, where
i 1 2 . N
. , , , e
Parameter N is the number of coefficient sets. N must be 1 or the total number of image
planes. If N 1 = , then a single set of warp coefficients (i.e., K
1
) is applied to all image
planes, i.e., all planes undergo the same transformation. If N 1 > , coefficient set K
i
is used to
process the i th image plane, e.g., K
1
defines the warp function for the first image plane, K
2
defines the warp function for the second image plane, etc.
Parameters K
i
k
r
0
i ,
k
r
1
i ,
k
r
2
i ,
k
r
3
i ,
k
t
0
i ,
k
t
1
i ,
, , , , , { } = are the radial and tangential
coefficients that define the warp function for the i th image plane; see below for
Digital Negative Specification September 2012 85
Opcode List Processing
WarpRectilinear
7
implementation details and restrictions. Note that if k
r
0
i ,
1 = and the remaining terms are
zero, then the warp function is the identity (i.e., no warp will be applied).
Parameters c
x
c
y
, ( ) are the normalized x- and y-coordinates of the optical center, relative to
the top-left pixel of the image. Example 1: specifying (0.5, 0.5) means that the optical center
lies exactly at the image center. Example 2: specifying (1, 0) means that the optical center lies
at the top-right pixel of the image.
Processing of this opcode is performed as follows.
Let I'
i
x' y' , ( ) be the pixel value of the i th plane of the original unwarped image at pixel
position x' y' , ( ) i.e., before opcode processing.
Let I
i
x y , ( ) be the pixel value of the i th plane of the warped image at pixel position x y , ( )
i.e., after opcode processing.
For each pixel x y , ( ) of the i th plane of the warped image, compute:
i.e., the pixel at position x' y' , ( ) in the original unwarped image is effectively moved to
position x y , ( ) in the final warped image, where
x' c
x
m x
r
x
t
A + A ( ) + =
y' c
y
m y
r
y
t
A + A ( ) + =
c
x
x
0
c
x
x
1
x
0
( ) + =
c
y
y
0
c
y
y
1
y
0
( ) + =
m
x
max x
0
c
x
x
1
c
x
, ( ) =
m
y
max y
0
c
y
y
1
c
y
, ( ) =
m m
x
2
m
y
2
+ =
r x
2
y
2
A + A =
f k
r
0
i ,
k
r
1
i ,
r
2
k
r
2
i ,
r
4
k
r
3
i ,
r
6
+ + + =
x A x c
x
( ) m =
y A y c
y
( ) m =
Digital Negative Specification September 2012 86
Opcode List Processing
WarpRectilinear
7
[Continued from the previous page...]
x
r
A f x A =
y
r
A f y A =
x
t
A k
t
0
i ,
2 x y A A ( ) k
t
1
i ,
r
2
2 x
2
A + ( ) + =
y
t
A k
t
1
i ,
2 x y A A ( ) k
t
0
i ,
r
2
2 y
2
A + ( ) + =
x
0
y
0
, ( ) pixel coordinates of the top-left pixel of the warped image =
x
1
y
1
, ( ) pixel coord. of the bottom-right pixel of the warped image =
Notes and Restrictions
x
r
A y
r
A , ( ) and x
t
A y
t
A , ( ) are the radial and tangential warp components, respectively.
m is the Euclidean distance (in pixels) from the optical center to the farthest pixel in the
warped image.
r is the normalized Euclidean distance in 0 1 , | | ( ) from the optical center to a given pixel in
the warped image.
It is recommended that implementations use a suitable resampling kernel, such as a cubic
spline.
This opcode can be used to correct lateral (transverse) chromatic aberration by specifying the
appropriate coefficients for each image plane separately.
Each coefficient set K
i
must satisfy the following constraints. Let x' y' , ( ) F x y , ( ) = be the
2D warp function defined above. Let x' F
x
x y , ( ) = and y' F
y
x y , ( ) = be the x-component
and y-component of F x y , ( ) , respectively. Let w r ( ) k
r
0
i ,
r k
r
1
i ,
r
3
k
r
2
i ,
r
5
k
r
3
i ,
r
7
+ + + = .
The constraints are:
F x y , ( ) must be invertible.
Fx x y , ( ) must be an increasing function of x for all x x
0
x
1
, | | e , i.e., cF
x
x y , ( ) cx 0 > .
Fy x y , ( ) must be an increasing function of y for all y y
0
y
1
, | | e , i.e., cF
y
x y , ( ) cy 0 > .
w r ( ) must be an increasing function of r for all r 0 1 , | | e , i.e., w' r ( ) 0 > .
Digital Negative Specification September 2012 87
Opcode List Processing
WarpFisheye
7
WarpFisheye
Opcode ID 2
DNG Version 1.3.0.0
Parameters
N LONG
k
r
0
i ,
DOUBLE
k
r
1
i ,
DOUBLE
k
r
2
i ,
DOUBLE
k
r
3
i ,
DOUBLE
For each coefficient set i 1 2 . N , , , e :
c
x
DOUBLE
c
y
DOUBLE
Description
This opcode applies a warp to an image and can be used to unwrap an image captured with a
fisheye lens and map it instead to a perspective projection. It can also be used to correct
geometric distortion and lateral (transverse) chromatic aberration for both fisheye and
rectilinear lenses.
Let K
i
k
r
0
i ,
k
r
1
i ,
k
r
2
i ,
k
r
3
i ,
, , , { } = denote the i th coefficient set, where i 1 2 . N , , , e .
Parameter N is the number of coefficient sets. N must be 1 or the total number of image
planes. If N 1 = , then a single set of warp coefficients (i.e., K
1
) is applied to all image
planes, i.e., all planes undergo the same transformation. If N 1 > , coefficient set K
i
is used to
process the i th image plane, e.g., K
1
defines the warp function for the first image plane, K
2
defines the warp function for the second image plane, etc.
Parameters K
i
k
r
0
i ,
k
r
1
i ,
k
r
2
i ,
k
r
3
i ,
, , , { } = are the coefficients that define the warp function
for the i th image plane; see below for implementation details and restrictions.
Parameters c
x
c
y
, ( ) are the normalized x- and y-coordinates of the optical center, relative to
the top-left pixel of the image. Example 1: specifying (0.5, 0.5) means that the optical center
lies exactly at the image center. Example 2: specifying (1, 0) means that the optical center lies
at the top-right pixel of the image.
Digital Negative Specification September 2012 88
Opcode List Processing
WarpFisheye
7
Processing of this opcode is performed as follows.
Let I'
i
x' y' , ( ) be the pixel value of the i th plane of the original unwarped image at pixel
position x' y' , ( ) i.e., before opcode processing.
Let I
i
x y , ( ) be the pixel value of the i th plane of the warped image at pixel position x y , ( )
i.e., after opcode processing.
For each pixel x y , ( ) of the i th plane of the warped image, compute:
i.e., the pixel at position x' y' , ( ) in the original unwarped image is effectively moved to
position x y , ( ) in the final warped image, where
x' c
x
m f x A ( ) + =
y' c
y
m f y A ( ) + =
c
x
x
0
c
x
x
1
x
0
( ) + =
c
y
y
0
c
y
y
1
y
0
( ) + =
m
x
max x
0
c
x
x
1
c
x
, ( ) =
m
y
max y
0
c
y
y
1
c
y
, ( ) =
m m
x
2
m
y
2
+ =
r x
2
y
2
A + A =
u arctan r ( ) =
f
1
r
--- k
r
0
i ,
u k
r
1
i ,
u
3
k
r
2
i ,
u
5
k
r
3
i ,
u
7
+ + + ( ) =
x A x c
x
( ) m =
y A y c
y
( ) m =
x
0
y
0
, ( ) pixel coordinates of the top-left pixel of the warped image =
x
1
y
1
, ( ) pixel coord. of the bottom-right pixel of the warped image =
Notes and Restrictions
m is the Euclidean distance (in pixels) from the optical center to the farthest pixel in the
warped image.
r is the normalized Euclidean distance in 0 1 , | | ( ) from the optical center to a given pixel in
the warped image.
Digital Negative Specification September 2012 89
Opcode List Processing
FixVignetteRadial
7
It is recommended that implementations use a suitable resampling kernel, such as a cubic
spline.
This opcode can be used to correct lateral (transverse) chromatic aberration by specifying the
appropriate coefficients for each image plane separately.
Each coefficient set K
i
must satisfy the following constraints. Let
w r ( ) k
r
0
i ,
u k
r
1
i ,
u
3
k
r
2
i ,
u
5
k
r
3
i ,
u
7
+ + + = , where u arctan r ( ) = . w r ( ) must be an
increasing function of r for all r 0 1 , | | e , i.e., w' r ( ) 0 > .
FixVignetteRadial
Opcode ID 3
DNG Version 1.3.0.0
Parameters
k
0
DOUBLE
k
1
DOUBLE
k
2
DOUBLE
k
3
DOUBLE
k
4
DOUBLE
c
x
DOUBLE
c
y
DOUBLE
Description
This opcode applies a gain function to an image and can be used to correct vignetting.
Parameters (k
0
k
1
k
2
k
3
k
4
, , , , ) define a radially-symmetric gain function, explained below.
Note that if all k
i
terms are zero, then the gain function is the identity (i.e., no gain will be
applied).
Parameters (c
x
c
y
, ) are the normalized x- and y-coordinates of the optical center, relative to
the top-left pixel of the image. Example 1: specifying (0.5; 0.5) means that the optical center
lies exactly at the image center. Example 2: specifying (1, 0) means that the optical center lies
at the top-right pixel of the image.
Processing of this opcode is performed as follows.
Let I'
i
x y , ( ) be the uncorrected pixel value of the i th plane of the image at pixel position
(x y , ) (i.e., before opcode processing).
Digital Negative Specification September 2012 90
Opcode List Processing
FixBadPixelsConstant
7
Let I
i
x y , ( ) be the corrected pixel value of the i th plane of the image at pixel position (x y , )
(i.e., after opcode processing).
For each pixel (x y , ) in the i th plane of the image, compute:
I
i
x y , ( ) g I'
i
x y , ( ) =
where
g 1 k
0
r
2
k
1
r
4
k
2
r
6
k
3
r
8
k
4
r
10
+ + + + + =
c
x
x
0
c
x
x
1
x
0
( ) + =
c
y
y
0
c
y
y
1
y
0
( ) + =
m
x
max x
0
c
x
x
1
c
x
, ( ) =
m
y
max y
0
c
y
y
1
c
y
, ( ) =
m m
x
2
m
y
2
+ =
r
1
m
---- x c
x
( )
2
y c
y
( )
2
+ =
x
0
y
0
, ( ) pixel coordinates of the top-left pixel of the image =
x
1
y
1
, ( ) pixel coordinates of the bottom-right pixel of the image =
Note that m represents the Euclidean distance (in pixels) from the optical center to the farthest
pixel in the image, and r represents the normalized Euclidean distance in 0 1 , | | ( ) from the
optical center to a given pixel.
FixBadPixelsConstant
Opcode ID 4
DNG Version 1.3.0.0
Parameters
Constant - LONG
BayerPhase - LONG
Description
This opcode patches (interpolates over) bad pixels in a Bayer pattern CFA image. The bad
pixels are marked in the image by setting the bad pixels to a value of Constant.
Digital Negative Specification September 2012 91
Opcode List Processing
FixBadPixelsList
7
If BayerPhase is 0, then the top-left pixel of the image is red pixel.
If BayerPhase is 1, then the top-left pixel of the image is green pixel in a green/red row.
If BayerPhase is 2, then the top-left pixel of the image is green pixel in a green/blue row.
If BayerPhase is 3, then the top-left pixel of the image is blue pixel.
FixBadPixelsList
Opcode ID 5
DNG Version 1.3.0.0
Parameters
BayerPhase - LONG
BadPointCount - LONG
BadRectCount - LONG
For Each BadPointCount:
BadPointRow - LONG
BadPointColumn - LONG
For Each BadRectCount:
BadRectTop - LONG
BadRectLeft - LONG
BadRectBottom - LONG
BadRectRight - LONG
Description
This opcode patches (interpolates over) bad pixels and rectangles in a Bayer pattern CFA
image. The bad pixels and rectangles are specified as parameters for this opcode.
If BayerPhase is 0, then the top-left pixel of the image is red pixel.
If BayerPhase is 1, then the top-left pixel of the image is green pixel in a green/red row.
If BayerPhase is 2, then the top-left pixel of the image is green pixel in a green/blue row.
If BayerPhase is 3, then the top-left pixel of the image is blue pixel.
BadPointCount is the number of bad pixels to patch. BadPointRow and BadPointColumn
specify the coordinates of the bad pixels to patch.
Digital Negative Specification September 2012 92
Opcode List Processing
TrimBounds
7
BadRectCount is the number of bad rectangles to patch. BadRectTop, BadRectLeft,
BadRectBottom, and BadRectRight specify the coordinates of the bad rectangles to patch.
TrimBounds
Opcode ID 6
DNG Version 1.3.0.0
Parameters
Top - LONG
Left - LONG
Bottom - LONG
Right - LONG
Description
This opcode trims the image to the rectangle specified by Top, Left, Bottom, and Right.
MapTable
Opcode ID 7
DNG Version 1.3.0.0
Parameters
Top - LONG
Left - LONG
Bottom - LONG
Right - LONG
Plane - LONG
Planes - LONG
RowPitch - LONG
ColPitch - LONG
TableSize - LONG
For Each TableSize:
Digital Negative Specification September 2012 93
Opcode List Processing
MapPolynomial
7
TableEntry - SHORT
Description
This opcode maps a specified area and plane range of an image through a 16-bit LUT.
The bounds of the area of the image to be affected is specified by the Top, Left, Bottom, Right
parameters. The first plane, and the number of planes, to be modified are specified by the
Plane and Planes parameters. If RowPitch not equal to one, then only every RowPitch rows
starting at the Top are affected. If ColPitch is not equal to one, then only every ColPitch
columns starting at Left are affected.
TableSize specifies the number of entries in the 16-bit LUT. TableEntry specifies each table
entry.
MapPolynomial
Opcode ID 8
DNG Version 1.3.0.0
Parameters
Top - LONG
Left - LONG
Bottom - LONG
Right - LONG
Plane - LONG
Planes - LONG
RowPitch - LONG
ColPitch - LONG
Degree - LONG
For Each Value 0...Degree:
Coefficient - DOUBLE
Description
This opcode maps a specified area and plane range of an image through a polynomial function.
The bounds of the area of the image to be affected is specified by the Top, Left, Bottom, Right
parameters. The first plane, and the number of planes, to be modified are specified by the
Plane and Planes parameters. If RowPitch not equal to one, then only every RowPitch rows
Digital Negative Specification September 2012 94
Opcode List Processing
GainMap
7
starting at the Top are affected. If ColPitch is not equal to one, then only every ColPitch
columns starting at Left are affected.
The mapping function is a polynomial of degree Degree. The maximum allowed value for
Degree is 8. The coefficients are stored in increasing order, starting with the zero degree
coefficient (constant term).
GainMap
Opcode ID 9
DNG Version 1.3.0.0
Parameters
Top - LONG
Left - LONG
Bottom - LONG
Right - LONG
Plane - LONG
Planes - LONG
RowPitch - LONG
ColPitch - LONG
MapPointsV - LONG
MapPointsH - Long
MapSpacingV - DOUBLE
MapSpacingH - DOUBLE
MapOriginV - DOUBLE
MapOriginH - DOUBLE
MapPlanes - LONG
For Each MapPointsV
For Each MapPointsH
For Each MapPlanes
MapGain - FLOAT
Digital Negative Specification September 2012 95
Opcode List Processing
DeltaPerRow
7
Description
This opcode multiplies a specified area and plane range of an image by a gain map.
The bounds of the area of the image to be affected is specified by the Top, Left, Bottom, Right
parameters. The first plane, and the number of planes, to be modified are specified by the
Plane and Planes parameters. If RowPitch not equal to one, then only every RowPitch rows
starting at the Top are affected. If ColPitch is not equal to one, then only every ColPitch
columns starting at Left are affected.
The gain map is a sub-sampled 2-D 32-bit floating-point image. MapPointsV is the number of
samples in vertical direction. MapPointsH is the number of samples in the horizontal direction.
The gain map is not required to cover the entire image being modified. Inside the gain map
bounds, values are interpolated using bi-linear interpolation. Outside the gain map bounds,
values are replicated from the edges of the gain map.
The origin of the gain map relative to image being modified is specified by MapOriginV
(vertical direction) and MapOriginH (horizontal direction), which are in relative coordinates,
where 1.0 is equal to the height or width of the image being modified, respectively.
The spacing between gain map points is specified by MapSpacingV (vertical direction) and
MapSpacingH (horizontal direction). Again these are in relative coordinates, where 1.0 is
equal to the height or width of the image being modified, respectively.
MapPlanes specifies the number of planes in the gain map. If Planes > MapPlanes, the last
gain map plane is used for any remaining planes being modified.
DeltaPerRow
Opcode ID 10
DNG Version 1.3.0.0
Parameters
Top - LONG
Left - LONG
Bottom - LONG
Right - LONG
Plane - LONG
Planes - LONG
RowPitch - LONG
ColPitch - LONG
Digital Negative Specification September 2012 96
Opcode List Processing
DeltaPerColumn
7
Count - LONG
For Each Count:
Delta - FLOAT
Description
This opcode applies a per-row delta (constant offset) to a specified area and plane range of an
image.
The bounds of the area of the image to be affected is specified by the Top, Left, Bottom, Right
parameters. The first plane, and the number of planes, to be modified are specified by the
Plane and Planes parameters. If RowPitch not equal to one, then only every RowPitch rows
starting at the Top are affected. If ColPitch is not equal to one, then only every ColPitch
columns starting at Left are affected.
Count is the number of deltas, and is required to match the number of affected rows in the
specified area.
The delta to add to each affected row is specified by Delta.
DeltaPerColumn
Opcode ID 11
DNG Version 1.3.0.0
Parameters
Top - LONG
Left - LONG
Bottom - LONG
Right - LONG
Plane - LONG
Planes - LONG
RowPitch - LONG
ColPitch - LONG
Count - LONG
For Each Count:
Delta - FLOAT
Digital Negative Specification September 2012 97
Opcode List Processing
ScalePerRow
7
Description
This opcode applies a per-column delta (constant offset) to a specified area and plane range of
an image.
The bounds of the area of the image to be affected is specified by the Top, Left, Bottom, Right
parameters. The first plane, and the number of planes, to be modified are specified by the
Plane and Planes parameters. If RowPitch not equal to one, then only every RowPitch rows
starting at the Top are affected. If ColPitch is not equal to one, then only every ColPitch
columns starting at Left are affected.
Count is the number of deltas, and is required to match the number of affected columns in the
specified area.
The delta to add to each affected column is specified by Delta.
ScalePerRow
Opcode ID 12
DNG Version 1.3.0.0
Parameters
Top - LONG
Left - LONG
Bottom - LONG
Right - LONG
Plane - LONG
Planes - LONG
RowPitch - LONG
ColPitch - LONG
Count - LONG
For Each Count:
Scale - FLOAT
Description
This opcode applies a per-row scale to a specified area and plane range of an image.
The bounds of the area of the image to be affected is specified by the Top, Left, Bottom, Right
parameters. The first plane, and the number of planes, to be modified are specified by the
Plane and Planes parameters. If RowPitch not equal to one, then only every RowPitch rows
Digital Negative Specification September 2012 98
Opcode List Processing
ScalePerColumn
7
starting at the Top are affected. If ColPitch is not equal to one, then only every ColPitch
columns starting at Left are affected.
Count is the number of scale values, and is required to match the number of affected rows in
the specified area.
The scale to multiply each affected row by is specified by Scale.
ScalePerColumn
Opcode ID 13
DNG Version 1.3.0.0
Parameters
Top - LONG
Left - LONG
Bottom - LONG
Right - LONG
Plane - LONG
Planes - LONG
RowPitch - LONG
ColPitch - LONG
Count - LONG
For Each Count:
Scale - FLOAT
Description
This opcode applies a per-column scale to a specified area and plane range of an image.
The bounds of the area of the image to be affected is specified by the Top, Left, Bottom, Right
parameters. The first plane, and the number of planes, to be modified are specified by the
Plane and Planes parameters. If RowPitch not equal to one, then only every RowPitch rows
starting at the Top are affected. If ColPitch is not equal to one, then only every ColPitch
columns starting at Left are affected.
Count is the number of scale values, and is required to match the number of affected columns
in the specified area.
The scale to multiply each affected column by is specified by Scale.
Digital Negative Specification September 2012 99
Appendix A: Compatibility with
Previous Versions
This appendix documents only the differences between this and previous versions of the DNG
specification that are relevant to compatibility. Differences that are not relevant to
compatibility (e.g., new optional tags that DNG readers are not required to support) are not
documented in this appendix.
This information is useful in enabling DNG readers to correctly read DNG files with older
version numbers. It also helps determine what version DNG writers can include in the
DNGBackwardVersion tag.
The first version of the DNG speciation that was published was version 1.0.0.0.
Compatibility Issue 1: ActiveArea Tag
The ActiveArea tag was added to the DNG specification in version 1.1.0.0. Previous versions
of the DNG specification do not support storing masked pixels.
DNG writers should set the DNGBackwardVersion to a minimum of 1.1.0.0 if the masked
pixels are stored in the DNG file.
Compatibility Issue 2: 16-bit Lossless JPEG Encoding
The Lossless JPEG encoder/decoder used by Adobe applications to read and write DNG files
before version 1.1.0.0 incorrectly deviated from the JPEG specification when dealing with 16-
bit data. Since both the encoder and decoder deviated in the same way, no data was lost;
however the data stream did not exactly match the data stream specified in the Lossless JPEG
specification.
Because the vast majority of DNG 1.0.0.0 files using 16-bit Lossless JPEG encoding were
created by Adobe applications, it is strongly recommended that software that reads or writes
DNG files with version numbers less than 1.1.0.0 incorporate this deviation. Software that
reads or writes DNG files with version 1.1.0.0 or later can safely assume that the Lossless
JPEG stream is fully compliant with the Lossless JPEG specification.
Description of deviation
Lossless JPEG encodes the difference between a predicted value and the actual value for each
pixel. With 16-bit data, these differences are computed modulo 16-bits, so the range of
possible differences is -32768 to + 32767. Two values are stored for the difference. First the
number of bits required to store the difference (encoded via a Huffman code), and then the
actual difference.
Digital Negative Specification September 2012 100
Appendix A: Compatibility with Previous Versions
Compatibility Issue 3: SubTileBlockSize
Using the difference encoding scheme in the Lossless JPEG specification, only one difference
value would take 16-bits to store: -32768. The Lossless JPEG specification special cases this
difference bit length, and since there is only one possible difference value it does not bother to
use any bits to store the actual difference.
In earlier versions of DNG the special case logic is not present, and the difference value for -
32768 is stored in the compressed data stream as with all other difference bit lengths.
Compatibility Issue 3: SubTileBlockSize
The SubTileBlockSize tag was added to the DNG specification in version 1.2.0.0. Earlier
versions of the DNG specification did not support this feature.
DNG writers should set the DNGBackwardVersion tag to a minimum of 1.2.0.0 if non-default
values are used for this tag.
Compatibility Issue 4: RowInterleaveFactor
The RowInterleaveFactor tag was added to the DNG specification in version 1.2.0.0. Earlier
versions of the DNG specification did not support this feature.
DNG writers should set the DNGBackwardVersion tag to a minimum of 1.2.0.0 if non-default
values are used for this tag.
Compatibility Issue 5: PreviewColorSpace
The PreviewColorSpace tag was added to the DNG specification in version 1.2.0.0. Earlier
versions of the DNG specification did not support this feature.
DNG writers should set the DNGBackwardVersion tag to a minimum of 1.2.0.0 if non-default
values are used for this tag.
Compatibility Issue 6: CFALayout
CFALayout values 6 through 9 were added to the DNG specification in version 1.3.0.0. Earlier
versions of the DNG specification did not support these CFALayout values.
DNG writers should set the DNGBackwardVersion tag to a minimum of 1.3.0.0 if CFALayout
values 6 through 9 are used.
Digital Negative Specification September 2012 101
Appendix A: Compatibility with Previous Versions
Compatibility Issue 7: Opcode Lists
Compatibility Issue 7: Opcode Lists
The OpcodeList1, OpcodeList2, and OpcodeList3 tags, plus the initial set of supported
Opcode IDs, were added to the DNG specification in version 1.3.0.0.
DNG writers should not set the DNGBackwardVersion to a version less than the DNG version
for any opcode that is not marked optional.
Compatibility Issue 8: Floating Point Image Data
Support for floating point image data was added in DNG Version 1.4.0.0.
DNG writers should set the DNGBackwardVersion tag to a minimum of 1.4.0.0 if the main
image IFD uses floating point data.
Compatibility Issue 9: Transparent Pixels
Support for transparent pixels was added in DNG Version 1.4.0.0.
DNG writers should set the DNGBackwardVersion tag to a minimum of 1.4.0.0 if the DNG
file contains an IFD with NewSubFileType equal to 4.
Compatibility Issue 10: Deflate Compression
Support for compression code 8 (Deflate) was added in DNG Version 1.4.0.0.
DNG writers should set the DNGBackwardVersion tag to a minimum of 1.4.0.0 if the main
image IFD uses compression code 8.
Compatibility Issue 11: Lossy JPEG Compression
Support for compression code 34892 (Lossy JPEG) was added in DNG Version 1.4.0.0.
DNG writers should set the DNGBackwardVersion tag to a minimum of 1.4.0.0 if the main
image IFD uses compression code 34892.