libtiff: Add DNG tags up to version 1.6.0.0 and some TIFF/EP tags and update documentation

From b90b20d36d7833f54a1f3014c324f6c21b988006 Mon Sep 17 00:00:00 2001
From: Su_Laus <[EMAIL REDACTED]>
Date: Tue, 25 Apr 2023 20:05:14 +0200
Subject: [PATCH] Add DNG tags up to version 1.6.0.0 and some TIFF/EP tags and
 update documentation

Amend MR !337 'Add support for DNG tags up to version 1.6.0.0 and some TIFF/EP tags' from Sami Liedes:
- Set most tags to OkToChange=1.
- Define BATTERYLEVEL tag as ASCII and convert values of rational variant to ASCII.
- TIFF documentation updated for tags recognized by LibTiff (DNG 1.6 and others).
- TIFF/EP tags added, which are equivalent to EXIF tags. This addresses part of #418 as well.
- Definition of tags reformatted (clang-format off) for better readability of tag comments in tiff.h and tif_dirinfo.c
---
 doc/functions/libtiff.rst        |  327 +-----
 doc/multi_page.rst               |    2 +
 doc/specification/coverage.rst   | 1756 ++++++++++++++++++++++++++++--
 libtiff/tif_dirinfo.c            |  971 +++++++----------
 libtiff/tif_dirread.c            |   87 ++
 libtiff/tiff.h                   | 1034 ++++++++----------
 libtiff/tiffio.h                 |    6 +
 test/rational_precision2double.c |    2 +-
 8 files changed, 2647 insertions(+), 1538 deletions(-)

diff --git a/doc/functions/libtiff.rst b/doc/functions/libtiff.rst
index b4ad327f..d118dec0 100644
--- a/doc/functions/libtiff.rst
+++ b/doc/functions/libtiff.rst
@@ -574,331 +574,8 @@ will work.
 Tag usage
 ---------
 
-The table below lists the TIFF
-tags that are recognized and handled by the library.
-If no use is indicated in the table, then the library
-reads and writes the tag, but does not use it internally.
-Note that some tags are meaningful only when a particular
-compression scheme is being used; e.g. ``Group3Options``
-is only useful if ``Compression``
-is set to CCITT Group 3 encoding.
-Tags of this sort are considered *codec-specific*
-tags and the library does not recognize them except when the
-``Compression``
-tag has been previously set to the relevant compression scheme.
-
-.. list-table:: libtiff supported tags
-    :widths: 10 2 2 15
-    :header-rows: 1
-
-    * - Tag name
-      - Value
-      - R/W
-      - Library Use/Notes
-    * - ``Artist``
-      - 315
-      - R/W
-      -
-    * - ``BadFaxLines``
-      - 326
-      - R/W
-      -
-    * - ``BitsPerSample``
-      - 258
-      - R/W
-      - lots
-    * - ``CellLength``
-      - 265
-      -
-      - parsed but ignored
-    * - ``CellWidth``
-      - 264
-      -
-      - parsed but ignored
-    * - ``CleanFaxData``
-      - 327
-      - R/W
-      -
-    * - ``ColorMap``
-      - 320
-      - R/W
-      -
-    * - ``ColorResponseUnit``
-      - 300
-      -
-      - parsed but ignored
-    * - ``Compression``
-      - 259
-      - R/W
-      - choosing codec
-    * - ``ConsecutiveBadFaxLines``
-      - 328
-      - R/W
-      -
-    * - ``Copyright``
-      - 33432
-      - R/W
-      -
-    * - ``DataType``
-      - 32996
-      - R
-      - obsoleted by ``SampleFormat`` tag
-    * - ``DateTime``
-      - 306
-      - R/W
-      -
-    * - ``DocumentName``
-      - 269
-      - R/W
-      -
-    * - ``DotRange``
-      - 336
-      - R/W
-      -
-    * - ``ExtraSamples``
-      - 338
-      - R/W
-      - lots
-    * - ``FaxRecvParams``
-      - 34908
-      - R/W
-      -
-    * - ``FaxSubAddress``
-      - 34909
-      - R/W
-      -
-    * - ``FaxRecvTime``
-      - 34910
-      - R/W
-      -
-    * - ``FillOrder``
-      - 266
-      - R/W
-      - control bit order
-    * - ``FreeByteCounts``
-      - 289
-      -
-      - parsed but ignored
-    * - ``FreeOffsets``
-      - 288
-      -
-      - parsed but ignored
-    * - ``GrayResponseCurve``
-      - 291
-      -
-      - parsed but ignored
-    * - ``GrayResponseUnit``
-      - 290
-      -
-      - parsed but ignored
-    * - ``Group3Options``
-      - 292
-      - R/W
-      - used by Group 3 codec
-    * - ``Group4Options``
-      - 293
-      - R/W
-      -
-    * - ``HostComputer``
-      - 316
-      - R/W
-      -
-    * - ``ImageDepth``
-      - 32997
-      - R/W
-      - tile/strip calculations
-    * - ``ImageDescription``
-      - 270
-      - R/W
-      -
-    * - ``ImageLength``
-      - 257
-      - R/W
-      - lots
-    * - ``ImageWidth``
-      - 256
-      - R/W
-      - lots
-    * - ``InkNames``
-      - 333
-      - R/W
-      -
-    * - ``InkSet``
-      - 332
-      - R/W
-      -
-    * - ``JPEGTables``
-      - 347
-      - R/W
-      - used by JPEG codec
-    * - ``Make``
-      - 271
-      - R/W
-      -
-    * - ``Matteing``
-      - 32995
-      - R
-      - obsoleted by ExtraSamples tag
-    * - ``MaxSampleValue``
-      - 281
-      - R/W
-      -
-    * - ``MinSampleValue``
-      - 280
-      - R/W
-      -
-    * - ``Model``
-      - 272
-      - R/W
-      -
-    * - ``NewSubFileType``
-      - 254
-      - R/W
-      - called ``SubFileType`` in spec
-    * - ``NumberOfInks``
-      - 334
-      - R/W
-      -
-    * - ``Orientation``
-      - 274
-      - R/W
-      -
-    * - ``PageName``
-      - 285
-      - R/W
-      -
-    * - ``PageNumber``
-      - 297
-      - R/W
-      -
-    * - ``PhotometricInterpretation``
-      - 262
-      - R/W
-      - used by Group 3 and JPEG codecs
-    * - ``PlanarConfiguration``
-      - 284
-      - R/W
-      - data i/o
-    * - ``Predictor``
-      - 317
-      - R/W
-      - used by LZW and Deflate codecs
-    * - ``PrimaryChromacities``
-      - 319
-      - R/W
-      -
-    * - ``ReferenceBlackWhite``
-      - 532
-      - R/W
-      -
-    * - ``ResolutionUnit``
-      - 296
-      - R/W
-      - used by Group 3 codec
-    * - ``RowsPerStrip``
-      - 278
-      - R/W
-      - data i/o
-    * - ``SampleFormat``
-      - 339
-      - R/W
-      -
-    * - ``SamplesPerPixel``
-      - 277
-      - R/W
-      - lots
-    * - ``SMinSampleValue``
-      - 340
-      - R/W
-      -
-    * - ``SMaxSampleValue``
-      - 341
-      - R/W
-      -
-    * - ``Software``
-      - 305
-      - R/W
-      -
-    * - ``StoNits``
-      - 37439
-      - R/W
-      -
-    * - ``StripByteCounts``
-      - 279
-      - R/W
-      - data i/o
-    * - ``StripOffsets``
-      - 273
-      - R/W
-      - data i/o
-    * - ``SubFileType``
-      - 255
-      - R/W
-      - called ``OSubFileType`` in spec
-    * - ``TargetPrinter``
-      - 337
-      - R/W
-      -
-    * - ``Thresholding``
-      - 263
-      - R/W
-      -
-    * - ``TileByteCounts``
-      - 324
-      - R/W
-      - data i/o
-    * - ``TileDepth``
-      - 32998
-      - R/W
-      - tile/strip calculations
-    * - ``TileLength``
-      - 323
-      - R/W
-      - data i/o
-    * - ``TileOffsets``
-      - 324
-      - R/W
-      - data i/o
-    * - ``TileWidth``
-      - 322
-      - R/W
-      - data i/o
-    * - ``TransferFunction``
-      - 301
-      - R/W
-      -
-    * - ``WhitePoint``
-      - 318
-      - R/W
-      -
-    * - ``XPosition``
-      - 286
-      - R/W
-      -
-    * - ``XResolution``
-      - 282
-      - R/W
-      -
-    * - ``YCbCrCoefficients``
-      - 529
-      - R/W
-      - used by ``TIFFRGBAImage`` support
-    * - ``YCbCrPositioning``
-      - 531
-      - R/W
-      - tile/strip size calculations
-    * - ``YCbCrSubsampling``
-      - 530
-      - R/W
-      -
-    * - ``YPosition``
-      - 286
-      - R/W
-      -
-    * - ``YResolution``
-      - 283
-      - R/W
-      - used by Group 3 codec
+For a table of TIFF tags recognized by the library refer to
+:doc:`/specification/coverage`.
 
 "Pseudo tags"
 -------------
diff --git a/doc/multi_page.rst b/doc/multi_page.rst
index d4e5dcd5..9b0776b8 100644
--- a/doc/multi_page.rst
+++ b/doc/multi_page.rst
@@ -29,6 +29,8 @@ In the case of several SubIFDs of a main image, there are two possibilities
 that are not even mutually exclusive.
 
 a. The ``SubIFD`` tag contains an array with all offsets of the SubIFDs.
+   This is called SubIFD tree and DNG recommends the use of SubIFD trees,
+   as described in the TIFF-EP specification. SubIFD chains are not supported.
 b. The SubIFDs are concatenated with their ``NextIFD`` parameters
    to a SubIFD chain.
 
diff --git a/doc/specification/coverage.rst b/doc/specification/coverage.rst
index bf139505..75bc7c5f 100644
--- a/doc/specification/coverage.rst
+++ b/doc/specification/coverage.rst
@@ -5,6 +5,9 @@ The library is capable of dealing with images that are written to
 follow the 5.0 or 6.0 TIFF spec.  There is also considerable support
 for some of the more esoteric portions of the 6.0 TIFF spec.
 
+Baseline
+--------
+
 .. list-table:: Core requirements
     :widths: 5 20
     :header-rows: 0
@@ -176,6 +179,25 @@ proposal given in TIFF Technical Note #2.
 The following table shows the tags that are recognized
 and how they are used by the library.  If no use is indicated,
 then the library reads and writes the tag, but does not use it internally.
+For the meaning of the tags look in https://www.awaresystems.be/imaging/tiff/tifftags.html
+
+:file:`libtiff` supports also many private tags allocated for organizations that wish to
+store additional information in a TIFF file.
+Tags for TIFF/EP and for Digital Negative (DNG) Specification 1.6.0
+(see https://helpx.adobe.com/content/dam/help/en/photoshop/pdf/dng_spec_1_6_0_0.pdf)
+are included.
+
+Note that some tags are meaningful only when a particular
+compression scheme is being used; e.g. ``Group3Options``
+is only useful if ``Compression``
+is set to CCITT Group 3 encoding.
+Tags of this sort are considered *codec-specific*
+tags and the library does not recognize them except when the
+``Compression``
+tag has been previously set to the relevant compression scheme.
+
+Tags Recognized by LibTIFF
+--------------------------
 
 .. list-table:: Tags used by libtiff
     :widths: 5 1 1 5
@@ -186,15 +208,15 @@ then the library reads and writes the tag, but does not use it internally.
       - R/W<
       - Library's Use (Comments)
 
-    * - ``NewSubFileType``
+    * - ``SubfileType``
       - 254
       - R/W
-      - none (called ``SubFileType`` in :file:`<tiff.h>`)
+      - none (also known as ``NewSubfileType``)
 
-    * - ``SubFileType``
+    * - ``OldSubfileType``
       - 255
       - R/W
-      - none (called ``OSubFileType`` in :file:`<tiff.h>`)
+      - parsed but ignored (also known as ``SubFileType``)
 
     * - ``ImageWidth``
       - 256
@@ -224,17 +246,17 @@ then the library reads and writes the tag, but does not use it internally.
     * - ``Thresholding``
       - 263
       - R/W
-      -
+      - (tag in tif.h wrongly written as "Threshholding")
 
     * - ``CellWidth``
       - 264
+      - R/W
       -
-      - parsed but ignored
 
     * - ``CellLength``
       - 265
+      - R/W
       -
-      - parsed but ignored
 
     * - ``FillOrder``
       - 266
@@ -322,39 +344,29 @@ then the library reads and writes the tag, but does not use it internally.
       -
 
     * - ``YPosition``
-      - 286
+      - 287
       - R/W
       -
 
     * - ``FreeOffsets``
       - 288
-      -
+      - R/W
       - parsed but ignored
 
     * - ``FreeByteCounts``
       - 289
-      -
+      - R/W
       - parsed but ignored
 
     * - ``GrayResponseUnit``
       - 290
-      -
+      - R/W
       - parsed but ignored
 
     * - ``GrayResponseCurve``
       - 291
-      -
-      - parsed but ignored
-
-    * - ``Group3Options``
-      - 292
-      - R/W
-      - used by Group 3 codec
-
-    * - ``Group4Options``
-      - 293
       - R/W
-      -
+      - parsed but ignored
 
     * - ``ResolutionUnit``
       - 296
@@ -368,7 +380,7 @@ then the library reads and writes the tag, but does not use it internally.
 
     * - ``ColorResponseUnit``
       - 300
-      -
+      - R/W
       - parsed but ignored
 
     * - ``TransferFunction``
@@ -396,17 +408,12 @@ then the library reads and writes the tag, but does not use it internally.
       - R/W
       -
 
-    * - ``Predictor``
-      - 317
-      - R/W
-      - used by LZW codec
-
     * - ``WhitePoint``
       - 318
       - R/W
       -
 
-    * - ``PrimaryChromacities``
+    * - ``PrimaryChromaticities``
       - 319
       - R/W
       -
@@ -416,6 +423,11 @@ then the library reads and writes the tag, but does not use it internally.
       - R/W
       -
 
+    * - ``HalftoneHints``
+      - 321
+      - R/W
+      -
+
     * - ``TileWidth``
       - 322
       - R/W
@@ -432,25 +444,10 @@ then the library reads and writes the tag, but does not use it internally.
       - data i/o
 
     * - ``TileByteCounts``
-      - 324
+      - 325
       - R/W
       - data i/o
 
-    * - ``BadFaxLines``
-      - 326
-      - R/W
-      -
-
-    * - ``CleanFaxData``
-      - 327
-      - R/W
-      -
-
-    * - ``ConsecutiveBadFaxLines``
-      - 328
-      - R/W
-      -
-
     * - ``SubIFD``
       - 330
       - R/W
@@ -466,6 +463,11 @@ then the library reads and writes the tag, but does not use it internally.
       - R/W
       -
 
+    * - ``NumberOfInks``
+      - 334
+      - R/W
+      -
+
     * - ``DotRange``
       - 336
       - R/W
@@ -496,10 +498,20 @@ then the library reads and writes the tag, but does not use it internally.
       - R/W
       -
 
-    * - ``JPEGTables``
-      - 347
+    * - ``ClipPath``
+      - 343
+      - R/W
+      -
+
+    * - ``XClipPathUnits``
+      - 344
+      - R/W
+      -
+
+    * - ``YClipPathUnits``
+      - 345
       - R/W
-      - used by JPEG codec
+      -
 
     * - ``YCbCrCoefficients``
       - 529
@@ -509,7 +521,7 @@ then the library reads and writes the tag, but does not use it internally.
     * - ``YCbCrSubsampling``
       - 530
       - R/W
-      - tile/strip size calculations
+      - tile / strip size calculations
 
     * - ``YCbCrPositioning``
       - 531
@@ -521,6 +533,11 @@ then the library reads and writes the tag, but does not use it internally.
       - R/W
       -
 
+    * - ``XMLPacket``
+      - 700
+      - R/W
+      -
+
     * - ``Matteing``
       - 32995
       - R
@@ -534,42 +551,1631 @@ then the library reads and writes the tag, but does not use it internally.
     * - ``ImageDepth``
       - 32997
       - R/W
-      - tile/strip calculations
+      - tile / strip size calculations
 
     * - ``TileDepth``
       - 32998
       - R/W
-      - tile/strip calculations
+      - tile / strip size calculations
+
+    * - ``ImageFullWidth``
+      - 33300
+      - R/W
+      -
+
+    * - ``ImageFullLength``
+      - 33301
+      - R/W
+      -
+
+    * - ``TextureFormat``
+      - 33302
+      - R/W
+      -
+
+    * - ``TextureWrapModes``
+      - 33303
+      - R/W
+      -
+
+    * - ``FieldOfViewCotangent``
+      - 33304
+      - R/W
+      -
+
+    * - ``MatrixWorldToScreen``
+      - 33305
+      - R/W
+      -
+
+    * - ``MatrixWorldToCamera``
+      - 33306
+      - R/W
+      -
+
+    * - ``Copyright``
+      - 33432
+      - R/W
+      -
+
+    * - ``RichTIFFIPTC``
+      - 33723
+      - R/W
+      - (also known as TIFF/EP IPTC/NAA; 
+        :file:`libtiff` type is UNDEFINED or BYTE,
+        but often times incorrectly specified as LONG,
+        because TIFF/EP (ISO/DIS 12234-2) specifies type LONG or ASCII)
+
+    * - ``Photoshop``
+      - 34377
+      - R/W
+      -
+
+    * - ``EXIFIFDOffset``
+      - 34665
+      - R/W
+      -
+
+    * - ``ICC Profile``
+      - 34675
+      - R/W
+      -
+
+    * - ``GPSIFDOffset``
+      - 34853
+      - R/W
+      -
+
+    * - ``FaxRecvParams``
+      - 34908
+      - R/W
+      -
+
+    * - ``FaxSubAddress``
+      - 34909
+      - R/W
+      -
+
+    * - ``FaxRecvTime``
+      - 34910
+      - R/W
+      -
+
+    * - ``FaxDcs``
+      - 34911
+      - R/W
+      -
 
     * - ``StoNits``
       - 37439
       - R/W
       -
 
-The ``Matteing`` and ``DataType``
-tags have been obsoleted by the 6.0
-``ExtraSamples`` and ``SampleFormat`` tags.
-Consult the documentation on the
-``ExtraSamples`` tag and Associated Alpha for elaboration.  Note however
-that if you use Associated Alpha, you are expected to save data that is
-pre-multipled by Alpha.  If this means nothing to you, check out
-Porter & Duff's paper in the '84 SIGGRAPH proceedings: "Compositing Digital
-Images".
+    * - ``Adobe Photoshop Document Data Block``
+      - 37724
+      - R/W
+      -
 
-The ``ImageDepth``
-tag is a non-standard, but registered tag that specifies
-the Z-dimension of volumetric data.  The combination of ``ImageWidth``,
-``ImageLength``, and ``ImageDepth``,
-defines a 3D volume of pixels that are
-further specified by ``BitsPerSample`` and
-``SamplesPerPixel``.  The ``TileDepth``
-tag (also non-standard, but registered) can be used to specified a
-subvolume "tiling" of a volume of data.
+    * - ``InteroperabilityIFDOffset``
+      - 40965
+      - R/W
+      -
 
-The Colorimetry, and CMYK tags are additions that appear in TIFF 6.0.
-Consult the TIFF 6.0 specification and :doc:`index`.
+    * - ``DNGVersion``
+      - 50706
+      - R/W
+      - DNG 1.0 tags
+
+    * - ``DNGBackwardVersion``
+      - 50707
+      - R/W
+      -
+
+    * - ``UniqueCameraModel``
+      - 50708
+      - R/W
+      -
+
+    * - ``LocalizedCameraModel``
+      - 50709
+      - R/W
+      -
+
+    * - ``CFAPlaneColor``
+      - 50710
+      - R/W
+      -
+
+    * - ``CFALayout``
+      - 50711
+      - R/W
+      -
+
+    * - ``LinearizationTable``
+      - 50712
+      - R/W
+      -
+
+    * - ``BlackLevelRepeatDim``
+      - 50713
+      - R/W
+      -
+
+    * - ``BlackLevel``
+      - 50714
+      - R/W
+      -
+
+    * - ``BlackLevelDeltaH``
+      - 50715
+      - R/W
+      -
+
+    * - ``BlackLevelDeltaV``
+      - 50716
+      - R/W
+      -
+
+    * - ``WhiteLevel``
+      - 50717
+      - R/W
+      -
+
+    * - ``DefaultScale``
+      - 50718
+      - R/W
+      -
+
+    * - ``DefaultCropOrigin``
+      - 50719
+      - R/W
+      -
+
+    * - ``DefaultCropSize``
+      - 50720
+      - R/W
+      -
+
+    * - ``ColorMatrix1``
+      - 50721
+      - R/W
+      -
+
+    * - ``ColorMatrix2``
+      - 50722
+      - R/W
+      -
+
+    * - ``CameraCalibration1``
+      - 50723
+      - R/W
+      -
+
+    * - ``CameraCalibration2``
+      - 50724
+      - R/W
+      -
+
+    * - ``ReductionMatrix1``
+      - 50725
+      - R/W
+      -
+
+    * - ``ReductionMatrix2``
+      - 50726
+      - R/W
+      -
+
+    * - ``AnalogBalance``
+      - 50727
+      - R/W
+      -
+
+    * - ``AsShotNeutral``
+      - 50728
+      - R/W
+      -
+
+    * - ``AsShotWhiteXY``
+      - 50729
+      - R/W
+      -
+
+    * - ``BaselineExposure``
+      - 50730
+      - R/W
+      -
+
+    * - ``BaselineNoise``
+      - 50731
+      - R/W
+      -
+
+    * - ``BaselineSharpness``
+      - 50732
+      - R/W
+      -
+
+    * - ``BayerGreenSplit``
+      - 50733
+      - R/W
+      -
+
+    * - ``LinearResponseLimit``
+      - 50734
+      - R/W
+      -
+
+    * - ``CameraSerialNumber``
+      - 50735
+      - R/W
+      -
+
+    * - ``LensInfo``
+      - 50736
+      - R/W
+      -
+
+    * - ``ChromaBlurRadius``
+      - 50737
+      - R/W
+      -
+
+    * - ``AntiAliasStrength``
+      - 50738
+      - R/W
+      -
+
+    * - ``ShadowScale``
+      - 50739
+      - R/W
+      -
+
+    * - ``DNGPrivateData``
+      - 50740
+      - R/W
+      -
+
+    * - ``MakerNoteSafety``
+      - 50741
+      - R/W
+      -
+
+    * - ``CalibrationIlluminant1``
+      - 50778
+      - R/W
+      -
+
+    * - ``CalibrationIlluminant2``
+      - 50779
+      - R/W
+      -
+
+    * - ``BestQualityScale``
+      - 50780
+      - R/W
+      -
+
+    * - ``RawDataUniqueID``
+      - 50781
+      - R/W
+      -
+
+    * - ``OriginalRawFileName``
+      - 50827
+      - R/W
+      -
+
+    * - ``OriginalRawFileData``
+      - 50828
+      - R/W
+      -
+
+    * - ``ActiveArea``
+      - 50829
+      - R/W
+      -
+
+    * - ``MaskedAreas``
+      - 50830
+      - R/W
+      -
+
+    * - ``AsShotICCProfile``
+      - 50831
+      - R/W
+      -
+
+    * - ``AsShotPreProfileMatrix``
+      - 50832
+      - R/W
+      -
+
+    * - ``CurrentICCProfile``
+      - 50833
+      - R/W
+      -
+
+    * - ``CurrentPreProfileMatrix``
+      - 50834
+      - R/W
+      -
+
+    * - ``PerSample``
+      - 65563
+      - R/W
+      -  (only internal pseudo tag)
+
+    * - ``ColorimetricReference``
+      - 50879
+      - R/W
+      - DNG 1.2 tags
+
+    * - ``CameraCalibrationSignature``
+      - 50931
+      - R/W
+      -
+
+    * - ``ProfileCalibrationSignature``
+      - 50932
+      - R/W
+      -
+
+    * - ``ExtraCameraProfiles``
+      - 50933
+      - R/W
+      -
+
+    * - ``AsShotProfileName``
+      - 50934
+      - R/W
+      -
+
+    * - ``NoiseReductionApplied``
+      - 50935
+      - R/W
+      -
+
+    * - ``ProfileName``
+      - 50936
+      - R/W
+      -
+
+    * - ``ProfileHueSatMapDims``
+      - 50937
+      - R/W
+      -
+
+    * - ``ProfileHueSatMapData1``
+      - 50938
+      - R/W
+      -
+
+    * - ``ProfileHueSatMapData2``
+      - 50939
+      - R/W
+      -
+
+    * - ``ProfileToneCurve``
+      - 50940
+      - R/W
+      -
+
+    * - ``ProfileEmbedPolicy``
+      - 50941
+      - R/W
+      -
+
+    * - ``ProfileCopyright``
+      - 50942
+      - R/W
+      -
+
+    * - ``ForwardMatrix1``
+      - 50964
+      - R/W
+      -
+
+    * - ``ForwardMatrix2``
+      - 50965
+      - R/W
+      -
+
+    * - ``PreviewApplicationName``
+      - 50966
+      - R/W
+      -
+
+    * - ``PreviewApplicationVersion``
+      - 50967
+      - R/W
+      -
+
+    * - ``PreviewSettingsName``
+      - 50968
+      - R/W
+      -
+
+    * - ``PreviewSettingsDigest``
+      - 50969
+      - R/W
+      -
+
+    * - ``PreviewColorSpace``
+      - 50970
+      - R/W
+      -
+
+    * - ``PreviewDateTime``
+      - 50971
+      - R/W
+      -
+
+    * - ``RawImageDigest``
+      - 50972
+      - R/W
+      -
+
+    * - ``OriginalRawFileDigest``
+      - 50973
+      - R/W
+      -
+
+    * - ``SubTileBlockSize``
+      - 50974
+      - R/W
+      -
+
+    * - ``RowInterleaveFactor``
+      - 50975
+      - R/W
+      -
+
+    * - ``ProfileLookTableDims``
+      - 50981
+      - R/W
+      -
+
+    * - ``ProfileLookTableData``
+      - 50982
+      - R/W
+      -
+
+    * - ``OpcodeList1``
+      - 51008
+      - R/W
+      - DNG 1.3 tags
+
+    * - ``OpcodeList2``
+      - 51009
+      - R/W
+      -
+
+    * - ``OpcodeList3``
+      - 51022
+      - R/W
+      -
+
+    * - ``NoiseProfile``
+      - 51041
+      - R/W
+      -
+
+    * - ``DefaultUserCrop``
+      - 51125
+      - R/W
+      - DNG 1.4 tags
+
+    * - ``DefaultBlackRender``
+      - 51110
+      - R/W
+      -
+
+    * - ``BaselineExposureOffset``
+      - 51109
+      - R/W
+      -
+
+    * - ``ProfileLookTableEncoding``
+      - 51108
+      - R/W
+      -
+
+    * - ``ProfileHueSatMapEncoding``
+      - 51107
+      - R/W
+      -
+
+    * - ``OriginalDefaultFinalSize``
+      - 51089
+      - R/W
+      -
+
+    * - ``OriginalBestQualityFinalSize``
+      - 51090
+      - R/W
+      -
+
+    * - ``OriginalDefaultCropSize``
+      - 51091
+      - R/W
+      -
+
+    * - ``NewRawImageDigest``
+      - 51111
+      - R/W
+      -
+
+    * - ``RawToPreviewGain``
+      - 51112
+      - R/W
+      -
+
+    * - ``DepthFormat``
+      - 51177
+      - R/W
+      - DNG 1.5 tags
+
+    * - ``DepthNear``
+      - 51178
+      - R/W
+      -
+
+    * - ``DepthFar``
+      - 51179
+      - R/W
+      -
+
+    * - ``DepthUnits``
+      - 51180
+      - R/W
+      -
+
+    * - ``DepthMeasureType``
+      - 51181
+      - R/W
+      -
+
+    * - ``EnhanceParams``
+      - 51182
+      - R/W
+      -
+
+    * - ``ProfileGainTableMap``
+      - 52525
+      - R/W
+      - DNG 1.6 tags
+
+    * - ``SemanticName``
+      - 52526
+      - R/W
+      -
+
+    * - ``SemanticInstanceID``
+      - 52528
+      - R/W
+      -
+
+    * - ``MaskSubArea``
+      - 52536
+      - R/W
+      -
+
+    * - ``RGBTables``
+      - 52543
+      - R/W
+      -
+
+    * - ``CalibrationIlluminant3``
+      - 52529
+      - R/W
+      -
+
+    * - ``ColorMatrix3``
+      - 52531
+      - R/W
+      -
+
+    * - ``CameraCalibration3``
+      - 52530
+      - R/W
+      -
+
+    * - ``ReductionMatrix3``
+      - 52538
+      - R/W
+      -
+
+    * - ``ProfileHueSatMapData3``
+      - 52537
+      - R/W
+      -
+
+    * - ``ForwardMatrix3``
+      - 52532
+      - R/W
+      -
+
+    * - ``IlluminantData1``
+      - 52533
+      - R/W
+      -
+
+    * - ``IlluminantData2``
+      - 52534
+      - R/W
+      -
+
+    * - ``IlluminantData3``
+      - 53535
+      - R/W
+      -
+
+    * - ``EP CFARepeatPatternDim``
+      - 33421
+      - R/W
+      - TIFF/EP tags
+
+    * - ``EP CFAPattern``
+      - 33422
+      - R/W
+      -
+
+    * - ``EP BatteryLevel``
+      - 33423
+      - R/W
+      -
+
+    * - ``EP Interlace``
+      - 34857
+      - R/W
+      -
+
+    * - ``EP TimeZoneOffset``
+      - 34858
+      - R/W
+      -
+
+    * - ``EP SelfTimerMode``
+      - 34859
+      - R/W
+      -
+
+    * - ``EP FlashEnergy``
+      - 37387
+      - R/W
+      -
+
+    * - ``EP SpatialFrequencyResponse``
+      - 37388
+      - R/W
+      -
+
+    * - ``EP Noise``
+      - 37389
+      - R/W
+      -
+
+    * - ``EP FocalPlaneXResolution``
+      - 37390
+      - R/W
+      -
+
+    * - ``EP FocalPlaneYResolution``
+      - 37391
+      - R/W
+      -
+
+    * - ``EP FocalPlaneResolutionUnit``
+      - 37392
+      - R/W
+      -
+
+    * - ``EP ImageNumber``
+      - 37393
+      - R/W
+      -
+
+    * - ``EP SecurityClassification``
+      - 37394
+      - R/W
+      -
+
+    * - ``EP ImageHistory``
+      - 37395
+      - R/W
+      -
+
+    * - ``EP ExposureIndex``
+      - 37397
+      - R/W
+      -
+
+    * - ``EP StandardId``
+      - 37398
+      - R/W
+      -
+
+    * - ``EP SensingMethod``
+      - 37399
+      - R/W
+      -
+
+    * - ``EP ExposureTime``
+      - 33434
+      - R/W
+      - TIFF/EP tags equivalent to EXIF tags
+
+    * - ``EP FNumber``
+      - 33437
+      - R/W
+      -
+
+    * - ``EP ExposureProgram``
+      - 34850
+      - R/W
+      -
+
+    * - ``EP SpectralSensitivity``
+      - 34852
+      - R/W
+      -
+
+    * - ``EP ISOSpeedRatings``
+      - 34855
+      - R/W
+      -
+
+    * - ``EP OptoelectricConversionFactor``
+      - 34856
+      - R/W
+      -
+
+    * - ``EP DateTimeOriginal``
+      - 36867
+      - R/W
+      -
+
+    * - ``EP CompressedBitsPerPixel``
+      - 37122
+      - R/W
+      -
+
+    * - ``EP ShutterSpeedValue``
+      - 37377
+      - R/W
+      -
+
+    * - ``EP ApertureValue``
+      - 37378
+      - R/W
+      -
+
+    * - ``EP BrightnessValue``
+      - 37379
+      - R/W
+      -
+
+    * - ``EP ExposureBiasValue``
+      - 37380
+      - R/W
+      -
+
+    * - ``EP MaxApertureValue``
+      - 37381
+      - R/W
+      -
+
+    * - ``EP SubjectDistance``
+      - 37382
+      - R/W
+      -
+
+    * - ``EP MeteringMode``
+      - 37383
+      - R/W
+      -
+
+    * - ``EP LightSource``
+      - 37384
+      - R/W
+      -
+
+    * - ``EP Flash``
+      - 37385
+      - R/W
+      -
+
+    * - ``EP FocalLength``
+      - 37386
+      - R/W
+      -
+
+    * - ``EP SubjectLocation``
+      - 37396
+      - R/W
+      -
+
+    * - ``Indexed``
+      - 346
+      - R/W
+      - TIFF/FX tags
+
+    * - ``GlobalParametersIFD``
+      - 400
+      - R/W
+      -
+
+    * - ``ProfileType``
+      - 401
+      - R/W
+      -
+
+    * - ``FaxProfile``
+      - 402
+      - R/W
+      -
+
+    * - ``CodingMethods``
+      - 403
+      - R/W
+      -
+
+    * - ``VersionYear``
+      - 404
+      - R/W
+      -
+
+    * - ``ModeNumber``
+      - 405
+      - R/W
+      -
+
+    * - ``Decode``
+      - 433
+      - R/W
+      -
+
+    * - ``ImageBaseColor``
+      - 434
+      - R/W
+      -
+
+    * - ``T82Options``
+      - 435
+      - R/W
+      -
+
+    * - ``StripRowCounts``
+      - 559
+      - R/W
+      - part of RFC 2301 for fax
+
+    * - ``ImageLayer``
+      - 34732
+      - R/W
+      -
+
+The ``Matteing`` and ``DataType``
+tags have been obsoleted by the 6.0
+``ExtraSamples`` and ``SampleFormat`` tags.
+Consult the documentation on the
+``ExtraSamples`` tag and Associated Alpha for elaboration.  Note however
+that if you use Associated Alpha, you are expected to save data that is
+pre-multipled by Alpha.  If this means nothing to you, check out
+Porter & Duff's paper in the '84 SIGGRAPH proceedings: "Compositing Digital
+Images".
+
+Tag ``RichTIFFIPTC`` (33723)is defined wrongly in TIFF/EP definition as "LONG or ASCII".
+``libtiff`` defines it as "UNDEFINED or BYTE".
+
+The ``ImageDepth``
+tag is a non-standard, but registered tag that specifies
+the Z-dimension of volumetric data.  The combination of ``ImageWidth``,
+``ImageLength``, and ``ImageDepth``,
+defines a 3D volume of pixels that are
+further specified by ``BitsPerSample`` and
+``SamplesPerPixel``.  The ``TileDepth``
+tag (also non-standard, but registered) can be used to specified a
+subvolume "tiling" of a volume of data.
+
+The Colorimetry, and CMYK tags are additions that appear in TIFF 6.0.
+Consult the TIFF 6.0 specification and :doc:`index`.
+
+Codecs / Compression
+--------------------
+
+The following tags are used by codecs.
+
+.. list-table:: Codec / Compression Tags used by libtiff
+    :widths: 5 1 1 5
+    :header-rows: 1
+
+    * - Tag Name
+      - Value
+      - R/W<
+      - Library's Use (Comments)
+
+    * - ``Predictor``
+      - 317
+      - R/W
+      - LZW codec
+
+    * - ``JPEGTables``
+      - 347
+      - R/W
+      - JPEG
+
+    * - ``JpegInterchangeFormat``
+      - 513
+      - R/W
+      - OJPEG
+
+    * - ``JpegInterchangeFormatLength``
+      - 514
+      - R/W
+      - OJPEG
+
+    * - ``JpegQTables``
+      - 519
+      - R/W
+      - OJPEG
+
+    * - ``JpegDcTables``
+      - 520
+      - R/W
+      - OJPEG
+
+    * - ``JpegAcTables``
+      - 521
+      - R/W
+      - OJPEG
+
+    * - ``JpegProc``
+      - 512
+      - R/W
+      - OJPEG
+
+    * - ``JpegRestartInterval``
+      - 515
+      - R/W
+      - OJPEG
+
+    * - ``BadFaxLines``
+      - 326
+      - R/W
+      - CCITT / fax
+
+    * - ``CleanFaxData``
+      - 327
+      - R/W
+      - CCITT / fax
+
+    * - ``ConsecutiveBadFaxLines``
+      - 328
+      - R/W
+      - CCITT / fax
+
+    * - ``Group3Options``
+      - 292
+      - R/W
+      - CCITT / fax
+
+    * - ``Group4Options``
+      - 293
+      - R/W
+      - CCITT / fax
+
+    * - ``LercParameters``
+      - 50674
+      - R/W
+      - LERC
+
+Note: This *codec-specific*
+tags and the library does not recognize them except when the
+``Compression``
+tag has been previously set to the relevant compression scheme.
+
+The JPEG-related tag is specified in
+:doc:`technote2`, which defines
+a revised JPEG-in-TIFF scheme (revised over the appendix that was
+part of the TIFF 6.0 specification).
+
+EXIF / GPS Custom IFDs
+----------------------
+
+In addition to the standard TIFF tags, :file:`libtiff` has predefined IFDs
+(image file directories) with the tags for EXIF (version 2.32) and EXIF-GPS
+as custom directories.
+For reading / writing of this IFDs refer to :doc:`/functions/TIFFCustomDirectory`.
+
+EXIF Custom Tags
+................
+
+.. list-table:: EXIF 2.32 Tags used by libtiff
+    :widths: 5 1 1 5
+    :header-rows: 1
+
+    * - Tag Name
+      - Value
+      - R/W<
+      - Library's Use (Comments)
+
+    * - ``ExposureTime``
+      - 33434
+      - R/W
+      -
+
+    * - ``FNumber``
+      - 33437
+      - R/W
+      -
+
+    * - ``ExposureProgram``
+      - 34850
+      - R/W
+      -
+
+    * - ``Sp

(Patch may be truncated, please check the link at the top of this post.)