1 /*
2 * Copyright (c) 1988-1997 Sam Leffler
3 * Copyright (c) 1991-1997 Silicon Graphics, Inc.
4 *
5 * Permission to use, copy, modify, distribute, and sell this software and
6 * its documentation for any purpose is hereby granted without fee, provided
7 * that (i) the above copyright notices and this permission notice appear in
8 * all copies of the software and related documentation, and (ii) the names of
9 * Sam Leffler and Silicon Graphics may not be used in any advertising or
10 * publicity relating to the software without the specific, prior written
11 * permission of Sam Leffler and Silicon Graphics.
12 *
13 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
14 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
15 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
16 *
17 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
18 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
19 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
21 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
22 * OF THIS SOFTWARE.
23 */
24
25 /*
26 * TIFF Library.
27 *
28 * Core Directory Tag Support.
29 */
30 #include "tiffiop.h"
31 #include <stdlib.h>
32
33 /*
34 * NOTE: THIS ARRAY IS ASSUMED TO BE SORTED BY TAG.
35 *
36 * NOTE: The second field (field_readcount) and third field (field_writecount)
37 * sometimes use the values TIFF_VARIABLE (-1), TIFF_VARIABLE2 (-3)
38 * and TIFF_SPP (-2). The macros should be used but would throw off
39 * the formatting of the code, so please interpret the -1, -2 and -3
40 * values accordingly.
41 */
42
43 /* const object should be initialized */
44 #ifdef _MSC_VER
45 #pragma warning(push)
46 #pragma warning(disable : 4132)
47 #endif
48 static const TIFFFieldArray tiffFieldArray;
49 static const TIFFFieldArray exifFieldArray;
50 static const TIFFFieldArray gpsFieldArray;
51 #ifdef _MSC_VER
52 #pragma warning(pop)
53 #endif
54 /*--: Rational2Double: --
55 * The Rational2Double upgraded libtiff functionality allows the definition and
56 * achievement of true double-precision accuracy for TIFF tags of RATIONAL type
57 * and field_bit=FIELD_CUSTOM using the set_field_type = TIFF_SETGET_DOUBLE.
58 * Unfortunately, that changes the old implemented interface for TIFFGetField().
59 * In order to keep the old TIFFGetField() interface behavior those tags have to
60 * be redefined with set_field_type = TIFF_SETGET_FLOAT!
61 *
62 * Rational custom arrays are already defined as _Cxx_FLOAT, thus can stay.
63 *
64 */
65
66 static const TIFFField tiffFields[] = {
67 {TIFFTAG_SUBFILETYPE, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32,
68 TIFF_SETGET_UNDEFINED, FIELD_SUBFILETYPE, 1, 0, "SubfileType", NULL},
69 {TIFFTAG_OSUBFILETYPE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UNDEFINED,
70 TIFF_SETGET_UNDEFINED, FIELD_IGNORE, 1, 0, "OldSubfileType", NULL},
71 {TIFFTAG_IMAGEWIDTH, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32,
72 TIFF_SETGET_UNDEFINED, FIELD_IMAGEDIMENSIONS, 0, 0, "ImageWidth", NULL},
73 {TIFFTAG_IMAGELENGTH, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32,
74 TIFF_SETGET_UNDEFINED, FIELD_IMAGEDIMENSIONS, 1, 0, "ImageLength", NULL},
75 {TIFFTAG_BITSPERSAMPLE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16,
76 TIFF_SETGET_UNDEFINED, FIELD_BITSPERSAMPLE, 0, 0, "BitsPerSample", NULL},
77 {TIFFTAG_COMPRESSION, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16,
78 TIFF_SETGET_UNDEFINED, FIELD_COMPRESSION, 0, 0, "Compression", NULL},
79 {TIFFTAG_PHOTOMETRIC, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16,
80 TIFF_SETGET_UNDEFINED, FIELD_PHOTOMETRIC, 0, 0,
81 "PhotometricInterpretation", NULL},
82 {TIFFTAG_THRESHHOLDING, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16,
83 TIFF_SETGET_UNDEFINED, FIELD_THRESHHOLDING, 1, 0, "Threshholding", NULL},
84 {TIFFTAG_CELLWIDTH, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16,
85 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "CellWidth", NULL},
86 {TIFFTAG_CELLLENGTH, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16,
87 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "CellLength", NULL},
88 {TIFFTAG_FILLORDER, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16,
89 TIFF_SETGET_UNDEFINED, FIELD_FILLORDER, 0, 0, "FillOrder", NULL},
90 {TIFFTAG_DOCUMENTNAME, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII,
91 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "DocumentName", NULL},
92 {TIFFTAG_IMAGEDESCRIPTION, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII,
93 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ImageDescription", NULL},
94 {TIFFTAG_MAKE, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII,
95 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Make", NULL},
96 {TIFFTAG_MODEL, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII,
97 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Model", NULL},
98 {TIFFTAG_STRIPOFFSETS, -1, -1, TIFF_LONG8, 0, TIFF_SETGET_UNDEFINED,
99 TIFF_SETGET_UNDEFINED, FIELD_STRIPOFFSETS, 0, 0, "StripOffsets", NULL},
100 {TIFFTAG_ORIENTATION, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16,
101 TIFF_SETGET_UNDEFINED, FIELD_ORIENTATION, 0, 0, "Orientation", NULL},
102 {TIFFTAG_SAMPLESPERPIXEL, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16,
103 TIFF_SETGET_UNDEFINED, FIELD_SAMPLESPERPIXEL, 0, 0, "SamplesPerPixel",
104 NULL},
105 {TIFFTAG_ROWSPERSTRIP, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32,
106 TIFF_SETGET_UNDEFINED, FIELD_ROWSPERSTRIP, 0, 0, "RowsPerStrip", NULL},
107 {TIFFTAG_STRIPBYTECOUNTS, -1, -1, TIFF_LONG8, 0, TIFF_SETGET_UNDEFINED,
108 TIFF_SETGET_UNDEFINED, FIELD_STRIPBYTECOUNTS, 0, 0, "StripByteCounts",
109 NULL},
110 {TIFFTAG_MINSAMPLEVALUE, -2, -1, TIFF_SHORT, 0, TIFF_SETGET_UINT16,
111 TIFF_SETGET_UNDEFINED, FIELD_MINSAMPLEVALUE, 1, 0, "MinSampleValue", NULL},
112 {TIFFTAG_MAXSAMPLEVALUE, -2, -1, TIFF_SHORT, 0, TIFF_SETGET_UINT16,
113 TIFF_SETGET_UNDEFINED, FIELD_MAXSAMPLEVALUE, 1, 0, "MaxSampleValue", NULL},
114 {TIFFTAG_XRESOLUTION, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT,
115 TIFF_SETGET_UNDEFINED, FIELD_RESOLUTION, 1, 0, "XResolution", NULL},
116 {TIFFTAG_YRESOLUTION, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT,
117 TIFF_SETGET_UNDEFINED, FIELD_RESOLUTION, 1, 0, "YResolution", NULL},
118 {TIFFTAG_PLANARCONFIG, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16,
119 TIFF_SETGET_UNDEFINED, FIELD_PLANARCONFIG, 0, 0, "PlanarConfiguration",
120 NULL},
121 {TIFFTAG_PAGENAME, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII,
122 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "PageName", NULL},
123 {TIFFTAG_XPOSITION, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT,
124 TIFF_SETGET_UNDEFINED, FIELD_POSITION, 1, 0, "XPosition", NULL},
125 {TIFFTAG_YPOSITION, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT,
126 TIFF_SETGET_UNDEFINED, FIELD_POSITION, 1, 0, "YPosition", NULL},
127 {TIFFTAG_FREEOFFSETS, -1, -1, TIFF_LONG8, 0, TIFF_SETGET_UNDEFINED,
128 TIFF_SETGET_UNDEFINED, FIELD_IGNORE, 0, 0, "FreeOffsets", NULL},
129 {TIFFTAG_FREEBYTECOUNTS, -1, -1, TIFF_LONG8, 0, TIFF_SETGET_UNDEFINED,
130 TIFF_SETGET_UNDEFINED, FIELD_IGNORE, 0, 0, "FreeByteCounts", NULL},
131 {TIFFTAG_GRAYRESPONSEUNIT, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UNDEFINED,
132 TIFF_SETGET_UNDEFINED, FIELD_IGNORE, 1, 0, "GrayResponseUnit", NULL},
133 {TIFFTAG_GRAYRESPONSECURVE, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_UNDEFINED,
134 TIFF_SETGET_UNDEFINED, FIELD_IGNORE, 1, 0, "GrayResponseCurve", NULL},
135 {TIFFTAG_RESOLUTIONUNIT, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16,
136 TIFF_SETGET_UNDEFINED, FIELD_RESOLUTIONUNIT, 1, 0, "ResolutionUnit", NULL},
137 {TIFFTAG_PAGENUMBER, 2, 2, TIFF_SHORT, 0, TIFF_SETGET_UINT16_PAIR,
138 TIFF_SETGET_UNDEFINED, FIELD_PAGENUMBER, 1, 0, "PageNumber", NULL},
139 {TIFFTAG_COLORRESPONSEUNIT, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UNDEFINED,
140 TIFF_SETGET_UNDEFINED, FIELD_IGNORE, 1, 0, "ColorResponseUnit", NULL},
141 {TIFFTAG_TRANSFERFUNCTION, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_OTHER,
142 TIFF_SETGET_UNDEFINED, FIELD_TRANSFERFUNCTION, 1, 0, "TransferFunction",
143 NULL},
144 {TIFFTAG_SOFTWARE, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII,
145 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Software", NULL},
146 {TIFFTAG_DATETIME, 20, 20, TIFF_ASCII, 0, TIFF_SETGET_ASCII,
147 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "DateTime", NULL},
148 {TIFFTAG_ARTIST, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII,
149 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Artist", NULL},
150 {TIFFTAG_HOSTCOMPUTER, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII,
151 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "HostComputer", NULL},
152 {TIFFTAG_WHITEPOINT, 2, 2, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT,
153 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "WhitePoint", NULL},
154 {TIFFTAG_PRIMARYCHROMATICITIES, 6, 6, TIFF_RATIONAL, 0,
155 TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0,
156 "PrimaryChromaticities", NULL},
157 {TIFFTAG_COLORMAP, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_OTHER,
158 TIFF_SETGET_UNDEFINED, FIELD_COLORMAP, 1, 0, "ColorMap", NULL},
159 {TIFFTAG_HALFTONEHINTS, 2, 2, TIFF_SHORT, 0, TIFF_SETGET_UINT16_PAIR,
160 TIFF_SETGET_UNDEFINED, FIELD_HALFTONEHINTS, 1, 0, "HalftoneHints", NULL},
161 {TIFFTAG_TILEWIDTH, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32,
162 TIFF_SETGET_UNDEFINED, FIELD_TILEDIMENSIONS, 0, 0, "TileWidth", NULL},
163 {TIFFTAG_TILELENGTH, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32,
164 TIFF_SETGET_UNDEFINED, FIELD_TILEDIMENSIONS, 0, 0, "TileLength", NULL},
165 {TIFFTAG_TILEOFFSETS, -1, 1, TIFF_LONG8, 0, TIFF_SETGET_UNDEFINED,
166 TIFF_SETGET_UNDEFINED, FIELD_STRIPOFFSETS, 0, 0, "TileOffsets", NULL},
167 {TIFFTAG_TILEBYTECOUNTS, -1, 1, TIFF_LONG8, 0, TIFF_SETGET_UNDEFINED,
168 TIFF_SETGET_UNDEFINED, FIELD_STRIPBYTECOUNTS, 0, 0, "TileByteCounts",
169 NULL},
170 {TIFFTAG_SUBIFD, -1, -1, TIFF_IFD8, 0, TIFF_SETGET_C16_IFD8,
171 TIFF_SETGET_UNDEFINED, FIELD_SUBIFD, 1, 1, "SubIFD",
172 (TIFFFieldArray *)&tiffFieldArray},
173 {TIFFTAG_INKSET, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16,
174 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "InkSet", NULL},
175 {TIFFTAG_INKNAMES, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_C16_ASCII,
176 TIFF_SETGET_UNDEFINED, FIELD_INKNAMES, 1, 1, "InkNames", NULL},
177 {TIFFTAG_NUMBEROFINKS, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16,
178 TIFF_SETGET_UNDEFINED, FIELD_NUMBEROFINKS, 1, 0, "NumberOfInks", NULL},
179 {TIFFTAG_DOTRANGE, 2, 2, TIFF_SHORT, 0, TIFF_SETGET_UINT16_PAIR,
180 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "DotRange", NULL},
181 {TIFFTAG_TARGETPRINTER, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII,
182 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "TargetPrinter", NULL},
183 {TIFFTAG_EXTRASAMPLES, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_C16_UINT16,
184 TIFF_SETGET_UNDEFINED, FIELD_EXTRASAMPLES, 0, 1, "ExtraSamples", NULL},
185 {TIFFTAG_SAMPLEFORMAT, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_UINT16,
186 TIFF_SETGET_UNDEFINED, FIELD_SAMPLEFORMAT, 0, 0, "SampleFormat", NULL},
187 {TIFFTAG_SMINSAMPLEVALUE, -2, -1, TIFF_ANY, 0, TIFF_SETGET_DOUBLE,
188 TIFF_SETGET_UNDEFINED, FIELD_SMINSAMPLEVALUE, 1, 0, "SMinSampleValue",
189 NULL},
190 {TIFFTAG_SMAXSAMPLEVALUE, -2, -1, TIFF_ANY, 0, TIFF_SETGET_DOUBLE,
191 TIFF_SETGET_UNDEFINED, FIELD_SMAXSAMPLEVALUE, 1, 0, "SMaxSampleValue",
192 NULL},
193 {TIFFTAG_CLIPPATH, -3, -3, TIFF_BYTE, 0, TIFF_SETGET_C32_UINT8,
194 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "ClipPath", NULL},
195 {TIFFTAG_XCLIPPATHUNITS, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32,
196 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "XClipPathUnits", NULL},
197 {TIFFTAG_YCLIPPATHUNITS, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32,
198 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "YClipPathUnits", NULL},
199 {TIFFTAG_YCBCRCOEFFICIENTS, 3, 3, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT,
200 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "YCbCrCoefficients", NULL},
201 {TIFFTAG_YCBCRSUBSAMPLING, 2, 2, TIFF_SHORT, 0, TIFF_SETGET_UINT16_PAIR,
202 TIFF_SETGET_UNDEFINED, FIELD_YCBCRSUBSAMPLING, 0, 0, "YCbCrSubsampling",
203 NULL},
204 {TIFFTAG_YCBCRPOSITIONING, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16,
205 TIFF_SETGET_UNDEFINED, FIELD_YCBCRPOSITIONING, 0, 0, "YCbCrPositioning",
206 NULL},
207 {TIFFTAG_REFERENCEBLACKWHITE, 6, 6, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT,
208 TIFF_SETGET_UNDEFINED, FIELD_REFBLACKWHITE, 1, 0, "ReferenceBlackWhite",
209 NULL},
210 {TIFFTAG_XMLPACKET, -3, -3, TIFF_BYTE, 0, TIFF_SETGET_C32_UINT8,
211 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "XMLPacket", NULL},
212 /* begin SGI tags */
213 {TIFFTAG_MATTEING, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16,
214 TIFF_SETGET_UNDEFINED, FIELD_EXTRASAMPLES, 0, 0, "Matteing", NULL},
215 {TIFFTAG_DATATYPE, -2, -1, TIFF_SHORT, 0, TIFF_SETGET_UINT16,
216 TIFF_SETGET_UNDEFINED, FIELD_SAMPLEFORMAT, 0, 0, "DataType", NULL},
217 {TIFFTAG_IMAGEDEPTH, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32,
218 TIFF_SETGET_UNDEFINED, FIELD_IMAGEDEPTH, 0, 0, "ImageDepth", NULL},
219 {TIFFTAG_TILEDEPTH, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32,
220 TIFF_SETGET_UNDEFINED, FIELD_TILEDEPTH, 0, 0, "TileDepth", NULL},
221 /* end SGI tags */
222 /* begin Pixar tags */
223 {TIFFTAG_PIXAR_IMAGEFULLWIDTH, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32,
224 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ImageFullWidth", NULL},
225 {TIFFTAG_PIXAR_IMAGEFULLLENGTH, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32,
226 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ImageFullLength", NULL},
227 {TIFFTAG_PIXAR_TEXTUREFORMAT, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII,
228 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "TextureFormat", NULL},
229 {TIFFTAG_PIXAR_WRAPMODES, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII,
230 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "TextureWrapModes", NULL},
231 {TIFFTAG_PIXAR_FOVCOT, 1, 1, TIFF_FLOAT, 0, TIFF_SETGET_FLOAT,
232 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FieldOfViewCotangent", NULL},
233 {TIFFTAG_PIXAR_MATRIX_WORLDTOSCREEN, 16, 16, TIFF_FLOAT, 0,
234 TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0,
235 "MatrixWorldToScreen", NULL},
236 {TIFFTAG_PIXAR_MATRIX_WORLDTOCAMERA, 16, 16, TIFF_FLOAT, 0,
237 TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0,
238 "MatrixWorldToCamera", NULL},
239 {TIFFTAG_CFAREPEATPATTERNDIM, 2, 2, TIFF_SHORT, 0, TIFF_SETGET_C0_UINT16,
240 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "CFARepeatPatternDim", NULL},
241 {TIFFTAG_CFAPATTERN, -1, -1, TIFF_BYTE, 0, TIFF_SETGET_C16_UINT8,
242 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "CFAPattern", NULL},
243 {TIFFTAG_COPYRIGHT, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII,
244 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Copyright", NULL},
245 /* end Pixar tags */
246 {TIFFTAG_RICHTIFFIPTC, -3, -3, TIFF_UNDEFINED, 0, TIFF_SETGET_C32_UINT8,
247 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "RichTIFFIPTC", NULL},
248 {TIFFTAG_PHOTOSHOP, -3, -3, TIFF_BYTE, 0, TIFF_SETGET_C32_UINT8,
249 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "Photoshop", NULL},
250 /*--: EXIFIFD and GPSIFD specified as TIFF_LONG by Aware-Systems and not
251 * TIFF_IFD8 as in original LibTiff. However, for IFD-like tags, libtiff
252 * uses the data type TIFF_IFD8 in tiffFields[]-tag definition combined with
253 * a special handling procedure in order to write either a 32-bit value
254 * and the TIFF_IFD type-id into ClassicTIFF files or a 64-bit value and the
255 * TIFF_IFD8 type-id into BigTIFF files. */
256 {TIFFTAG_EXIFIFD, 1, 1, TIFF_IFD8, 0, TIFF_SETGET_IFD8,
257 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "EXIFIFDOffset",
258 (TIFFFieldArray *)&exifFieldArray},
259 {TIFFTAG_ICCPROFILE, -3, -3, TIFF_UNDEFINED, 0, TIFF_SETGET_C32_UINT8,
260 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "ICC Profile", NULL},
261 {TIFFTAG_GPSIFD, 1, 1, TIFF_IFD8, 0, TIFF_SETGET_IFD8,
262 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "GPSIFDOffset",
263 (TIFFFieldArray *)&gpsFieldArray},
264 {TIFFTAG_FAXRECVPARAMS, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32,
265 TIFF_SETGET_UINT32, FIELD_CUSTOM, TRUE, FALSE, "FaxRecvParams", NULL},
266 {TIFFTAG_FAXSUBADDRESS, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII,
267 TIFF_SETGET_ASCII, FIELD_CUSTOM, TRUE, FALSE, "FaxSubAddress", NULL},
268 {TIFFTAG_FAXRECVTIME, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32,
269 TIFF_SETGET_UINT32, FIELD_CUSTOM, TRUE, FALSE, "FaxRecvTime", NULL},
270 {TIFFTAG_FAXDCS, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII,
271 TIFF_SETGET_ASCII, FIELD_CUSTOM, TRUE, FALSE, "FaxDcs", NULL},
272 {TIFFTAG_STONITS, 1, 1, TIFF_DOUBLE, 0, TIFF_SETGET_DOUBLE,
273 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "StoNits", NULL},
274 {TIFFTAG_IMAGESOURCEDATA, -3, -3, TIFF_UNDEFINED, 0, TIFF_SETGET_C32_UINT8,
275 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1,
276 "Adobe Photoshop Document Data Block", NULL},
277 {TIFFTAG_INTEROPERABILITYIFD, 1, 1, TIFF_IFD8, 0, TIFF_SETGET_IFD8,
278 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "InteroperabilityIFDOffset",
279 NULL},
280 /* begin DNG tags */
281 {TIFFTAG_DNGVERSION, 4, 4, TIFF_BYTE, 0, TIFF_SETGET_C0_UINT8,
282 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "DNGVersion", NULL},
283 {TIFFTAG_DNGBACKWARDVERSION, 4, 4, TIFF_BYTE, 0, TIFF_SETGET_C0_UINT8,
284 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "DNGBackwardVersion", NULL},
285 {TIFFTAG_UNIQUECAMERAMODEL, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII,
286 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "UniqueCameraModel", NULL},
287 {TIFFTAG_LOCALIZEDCAMERAMODEL, -1, -1, TIFF_BYTE, 0, TIFF_SETGET_C16_UINT8,
288 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "LocalizedCameraModel", NULL},
289 {TIFFTAG_CFAPLANECOLOR, -1, -1, TIFF_BYTE, 0, TIFF_SETGET_C16_UINT8,
290 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "CFAPlaneColor", NULL},
291 {TIFFTAG_CFALAYOUT, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16,
292 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "CFALayout", NULL},
293 {TIFFTAG_LINEARIZATIONTABLE, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_C16_UINT16,
294 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "LinearizationTable", NULL},
295 {TIFFTAG_BLACKLEVELREPEATDIM, 2, 2, TIFF_SHORT, 0, TIFF_SETGET_C0_UINT16,
296 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "BlackLevelRepeatDim", NULL},
297 {TIFFTAG_BLACKLEVEL, -1, -1, TIFF_RATIONAL, 0, TIFF_SETGET_C16_FLOAT,
298 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "BlackLevel", NULL},
299 {TIFFTAG_BLACKLEVELDELTAH, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT,
300 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "BlackLevelDeltaH", NULL},
301 {TIFFTAG_BLACKLEVELDELTAV, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT,
302 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "BlackLevelDeltaV", NULL},
303 {TIFFTAG_WHITELEVEL, -1, -1, TIFF_LONG, 0, TIFF_SETGET_C16_UINT32,
304 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "WhiteLevel", NULL},
305 {TIFFTAG_DEFAULTSCALE, 2, 2, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT,
306 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "DefaultScale", NULL},
307 {TIFFTAG_BESTQUALITYSCALE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT,
308 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "BestQualityScale", NULL},
309 {TIFFTAG_DEFAULTCROPORIGIN, 2, 2, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT,
310 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "DefaultCropOrigin", NULL},
311 {TIFFTAG_DEFAULTCROPSIZE, 2, 2, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT,
312 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "DefaultCropSize", NULL},
313 {TIFFTAG_COLORMATRIX1, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT,
314 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "ColorMatrix1", NULL},
315 {TIFFTAG_COLORMATRIX2, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT,
316 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "ColorMatrix2", NULL},
317 {TIFFTAG_CAMERACALIBRATION1, -1, -1, TIFF_SRATIONAL, 0,
318 TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1,
319 "CameraCalibration1", NULL},
320 {TIFFTAG_CAMERACALIBRATION2, -1, -1, TIFF_SRATIONAL, 0,
321 TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1,
322 "CameraCalibration2", NULL},
323 {TIFFTAG_REDUCTIONMATRIX1, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT,
324 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "ReductionMatrix1", NULL},
325 {TIFFTAG_REDUCTIONMATRIX2, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT,
326 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "ReductionMatrix2", NULL},
327 {TIFFTAG_ANALOGBALANCE, -1, -1, TIFF_RATIONAL, 0, TIFF_SETGET_C16_FLOAT,
328 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "AnalogBalance", NULL},
329 {TIFFTAG_ASSHOTNEUTRAL, -1, -1, TIFF_RATIONAL, 0, TIFF_SETGET_C16_FLOAT,
330 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "AsShotNeutral", NULL},
331 {TIFFTAG_ASSHOTWHITEXY, 2, 2, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT,
332 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "AsShotWhiteXY", NULL},
333 {TIFFTAG_BASELINEEXPOSURE, 1, 1, TIFF_SRATIONAL, 0, TIFF_SETGET_FLOAT,
334 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "BaselineExposure", NULL},
335 {TIFFTAG_BASELINENOISE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT,
336 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "BaselineNoise", NULL},
337 {TIFFTAG_BASELINESHARPNESS, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT,
338 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "BaselineSharpness", NULL},
339 {TIFFTAG_BAYERGREENSPLIT, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32,
340 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "BayerGreenSplit", NULL},
341 {TIFFTAG_LINEARRESPONSELIMIT, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT,
342 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "LinearResponseLimit", NULL},
343 {TIFFTAG_CAMERASERIALNUMBER, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII,
344 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "CameraSerialNumber", NULL},
345 {TIFFTAG_LENSINFO, 4, 4, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT,
346 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "LensInfo", NULL},
347 {TIFFTAG_CHROMABLURRADIUS, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT,
348 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "ChromaBlurRadius", NULL},
349 {TIFFTAG_ANTIALIASSTRENGTH, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT,
350 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "AntiAliasStrength", NULL},
351 {TIFFTAG_SHADOWSCALE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT,
352 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "ShadowScale", NULL},
353 {TIFFTAG_DNGPRIVATEDATA, -1, -1, TIFF_BYTE, 0, TIFF_SETGET_C16_UINT8,
354 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "DNGPrivateData", NULL},
355 {TIFFTAG_MAKERNOTESAFETY, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16,
356 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "MakerNoteSafety", NULL},
357 {TIFFTAG_CALIBRATIONILLUMINANT1, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16,
358 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "CalibrationIlluminant1", NULL},
359 {TIFFTAG_CALIBRATIONILLUMINANT2, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16,
360 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "CalibrationIlluminant2", NULL},
361 {TIFFTAG_RAWDATAUNIQUEID, 16, 16, TIFF_BYTE, 0, TIFF_SETGET_C0_UINT8,
362 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "RawDataUniqueID", NULL},
363 {TIFFTAG_ORIGINALRAWFILENAME, -1, -1, TIFF_BYTE, 0, TIFF_SETGET_C16_UINT8,
364 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "OriginalRawFileName", NULL},
365 {TIFFTAG_ORIGINALRAWFILEDATA, -1, -1, TIFF_UNDEFINED, 0,
366 TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1,
367 "OriginalRawFileData", NULL},
368 {TIFFTAG_ACTIVEAREA, 4, 4, TIFF_LONG, 0, TIFF_SETGET_C0_UINT32,
369 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "ActiveArea", NULL},
370 {TIFFTAG_MASKEDAREAS, -1, -1, TIFF_LONG, 0, TIFF_SETGET_C16_UINT32,
371 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "MaskedAreas", NULL},
372 {TIFFTAG_ASSHOTICCPROFILE, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8,
373 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "AsShotICCProfile", NULL},
374 {TIFFTAG_ASSHOTPREPROFILEMATRIX, -1, -1, TIFF_SRATIONAL, 0,
375 TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1,
376 "AsShotPreProfileMatrix", NULL},
377 {TIFFTAG_CURRENTICCPROFILE, -1, -1, TIFF_UNDEFINED, 0,
378 TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1,
379 "CurrentICCProfile", NULL},
380 {TIFFTAG_CURRENTPREPROFILEMATRIX, -1, -1, TIFF_SRATIONAL, 0,
381 TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1,
382 "CurrentPreProfileMatrix", NULL},
383 {TIFFTAG_PERSAMPLE, 0, 0, TIFF_SHORT, 0, TIFF_SETGET_UNDEFINED,
384 TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, TRUE, FALSE, "PerSample", NULL},
385 /* end DNG tags */
386 /* begin TIFF/FX tags */
387 {TIFFTAG_INDEXED, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16,
388 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "Indexed", NULL},
389 {TIFFTAG_GLOBALPARAMETERSIFD, 1, 1, TIFF_IFD8, 0, TIFF_SETGET_IFD8,
390 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "GlobalParametersIFD", NULL},
391 {TIFFTAG_PROFILETYPE, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32,
392 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "ProfileType", NULL},
393 {TIFFTAG_FAXPROFILE, 1, 1, TIFF_BYTE, 0, TIFF_SETGET_UINT8,
394 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "FaxProfile", NULL},
395 {TIFFTAG_CODINGMETHODS, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32,
396 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "CodingMethods", NULL},
397 {TIFFTAG_VERSIONYEAR, 4, 4, TIFF_BYTE, 0, TIFF_SETGET_C0_UINT8,
398 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "VersionYear", NULL},
399 {TIFFTAG_MODENUMBER, 1, 1, TIFF_BYTE, 0, TIFF_SETGET_UINT8,
400 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "ModeNumber", NULL},
401 {TIFFTAG_DECODE, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT,
402 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "Decode", NULL},
403 {TIFFTAG_IMAGEBASECOLOR, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_C16_UINT16,
404 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "ImageBaseColor", NULL},
405 {TIFFTAG_T82OPTIONS, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32,
406 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "T82Options", NULL},
407 {TIFFTAG_STRIPROWCOUNTS, -1, -1, TIFF_LONG, 0, TIFF_SETGET_C16_UINT32,
408 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "StripRowCounts", NULL},
409 {TIFFTAG_IMAGELAYER, 2, 2, TIFF_LONG, 0, TIFF_SETGET_C0_UINT32,
410 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "ImageLayer", NULL},
411 /* end TIFF/FX tags */
412 /* begin pseudo tags */
413 };
414
415 /*
416 * EXIF tags (Version 2.31, July 2016 plus version 2.32 May 2019)
417 */
418 static const TIFFField exifFields[] = {
419 {EXIFTAG_EXPOSURETIME, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT,
420 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ExposureTime", NULL},
421 {EXIFTAG_FNUMBER, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT,
422 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FNumber", NULL},
423 {EXIFTAG_EXPOSUREPROGRAM, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16,
424 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ExposureProgram", NULL},
425 {EXIFTAG_SPECTRALSENSITIVITY, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII,
426 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SpectralSensitivity", NULL},
427 {EXIFTAG_ISOSPEEDRATINGS, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_C16_UINT16,
428 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "ISOSpeedRatings", NULL},
429 {EXIFTAG_OECF, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8,
430 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "OptoelectricConversionFactor",
431 NULL},
432 {EXIFTAG_SENSITIVITYTYPE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16,
433 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SensitivityType", NULL},
434 {EXIFTAG_STANDARDOUTPUTSENSITIVITY, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32,
435 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "StandardOutputSensitivity",
436 NULL},
437 {EXIFTAG_RECOMMENDEDEXPOSUREINDEX, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32,
438 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "RecommendedExposureIndex",
439 NULL},
440 {EXIFTAG_ISOSPEED, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32,
441 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ISOSpeed", NULL},
442 {EXIFTAG_ISOSPEEDLATITUDEYYY, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32,
443 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ISOSpeedLatitudeyyy", NULL},
444 {EXIFTAG_ISOSPEEDLATITUDEZZZ, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32,
445 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ISOSpeedLatitudezzz", NULL},
446 {EXIFTAG_EXIFVERSION, 4, 4, TIFF_UNDEFINED, 0, TIFF_SETGET_C0_UINT8,
447 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ExifVersion", NULL},
448 {EXIFTAG_DATETIMEORIGINAL, 20, 20, TIFF_ASCII, 0, TIFF_SETGET_ASCII,
449 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "DateTimeOriginal", NULL},
450 {EXIFTAG_DATETIMEDIGITIZED, 20, 20, TIFF_ASCII, 0, TIFF_SETGET_ASCII,
451 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "DateTimeDigitized", NULL},
452 {EXIFTAG_OFFSETTIME, 7, 7, TIFF_ASCII, 0, TIFF_SETGET_ASCII,
453 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "OffsetTime", NULL},
454 {EXIFTAG_OFFSETTIMEORIGINAL, 7, 7, TIFF_ASCII, 0, TIFF_SETGET_ASCII,
455 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "OffsetTimeOriginal", NULL},
456 {EXIFTAG_OFFSETTIMEDIGITIZED, 7, 7, TIFF_ASCII, 0, TIFF_SETGET_ASCII,
457 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "OffsetTimeDigitized", NULL},
458 {EXIFTAG_COMPONENTSCONFIGURATION, 4, 4, TIFF_UNDEFINED, 0,
459 TIFF_SETGET_C0_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0,
460 "ComponentsConfiguration", NULL},
461 {EXIFTAG_COMPRESSEDBITSPERPIXEL, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT,
462 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "CompressedBitsPerPixel", NULL},
463 {EXIFTAG_SHUTTERSPEEDVALUE, 1, 1, TIFF_SRATIONAL, 0, TIFF_SETGET_FLOAT,
464 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ShutterSpeedValue", NULL},
465 {EXIFTAG_APERTUREVALUE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT,
466 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ApertureValue", NULL},
467 {EXIFTAG_BRIGHTNESSVALUE, 1, 1, TIFF_SRATIONAL, 0, TIFF_SETGET_FLOAT,
468 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "BrightnessValue", NULL},
469 {EXIFTAG_EXPOSUREBIASVALUE, 1, 1, TIFF_SRATIONAL, 0, TIFF_SETGET_FLOAT,
470 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ExposureBiasValue", NULL},
471 {EXIFTAG_MAXAPERTUREVALUE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT,
472 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "MaxApertureValue", NULL},
473 /*--: EXIFTAG_SUBJECTDISTANCE: LibTiff returns value of "-1" if numerator
474 * equals 4294967295 (0xFFFFFFFF) to indicate infinite distance! However,
475 * there are two other EXIF tags where numerator indicates a special value
476 * and six other cases where the denominator indicates special values, which
477 * are not treated within LibTiff!! */
478 {EXIFTAG_SUBJECTDISTANCE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT,
479 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SubjectDistance", NULL},
480 {EXIFTAG_METERINGMODE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16,
481 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "MeteringMode", NULL},
482 {EXIFTAG_LIGHTSOURCE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16,
483 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "LightSource", NULL},
484 {EXIFTAG_FLASH, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16,
485 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Flash", NULL},
486 {EXIFTAG_FOCALLENGTH, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT,
487 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FocalLength", NULL},
488 {EXIFTAG_SUBJECTAREA, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_C16_UINT16,
489 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "SubjectArea", NULL},
490 {EXIFTAG_MAKERNOTE, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8,
491 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "MakerNote", NULL},
492 {EXIFTAG_USERCOMMENT, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8,
493 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "UserComment", NULL},
494 {EXIFTAG_SUBSECTIME, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII,
495 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SubSecTime", NULL},
496 {EXIFTAG_SUBSECTIMEORIGINAL, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII,
497 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SubSecTimeOriginal", NULL},
498 {EXIFTAG_SUBSECTIMEDIGITIZED, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII,
499 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SubSecTimeDigitized", NULL},
500 {EXIFTAG_TEMPERATURE, 1, 1, TIFF_SRATIONAL, 0, TIFF_SETGET_FLOAT,
501 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Temperature", NULL},
502 {EXIFTAG_HUMIDITY, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT,
503 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Humidity", NULL},
504 {EXIFTAG_PRESSURE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT,
505 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Pressure", NULL},
506 {EXIFTAG_WATERDEPTH, 1, 1, TIFF_SRATIONAL, 0, TIFF_SETGET_FLOAT,
507 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "WaterDepth", NULL},
508 {EXIFTAG_ACCELERATION, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT,
509 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Acceleration", NULL},
510 {EXIFTAG_CAMERAELEVATIONANGLE, 1, 1, TIFF_SRATIONAL, 0, TIFF_SETGET_FLOAT,
511 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "CameraElevationAngle", NULL},
512 {EXIFTAG_FLASHPIXVERSION, 4, 4, TIFF_UNDEFINED, 0, TIFF_SETGET_C0_UINT8,
513 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FlashpixVersion", NULL},
514 {EXIFTAG_COLORSPACE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16,
515 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ColorSpace", NULL},
516 {EXIFTAG_PIXELXDIMENSION, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32,
517 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "PixelXDimension", NULL},
518 {EXIFTAG_PIXELYDIMENSION, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32,
519 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "PixelYDimension", NULL},
520 {EXIFTAG_RELATEDSOUNDFILE, 13, 13, TIFF_ASCII, 0, TIFF_SETGET_ASCII,
521 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "RelatedSoundFile", NULL},
522 {EXIFTAG_FLASHENERGY, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT,
523 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FlashEnergy", NULL},
524 {EXIFTAG_SPATIALFREQUENCYRESPONSE, -1, -1, TIFF_UNDEFINED, 0,
525 TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1,
526 "SpatialFrequencyResponse", NULL},
527 {EXIFTAG_FOCALPLANEXRESOLUTION, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT,
528 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FocalPlaneXResolution", NULL},
529 {EXIFTAG_FOCALPLANEYRESOLUTION, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT,
530 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FocalPlaneYResolution", NULL},
531 {EXIFTAG_FOCALPLANERESOLUTIONUNIT, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16,
532 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FocalPlaneResolutionUnit",
533 NULL},
534 {EXIFTAG_SUBJECTLOCATION, 2, 2, TIFF_SHORT, 0, TIFF_SETGET_C0_UINT16,
535 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SubjectLocation", NULL},
536 {EXIFTAG_EXPOSUREINDEX, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT,
537 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ExposureIndex", NULL},
538 {EXIFTAG_SENSINGMETHOD, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16,
539 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SensingMethod", NULL},
540 {EXIFTAG_FILESOURCE, 1, 1, TIFF_UNDEFINED, 0, TIFF_SETGET_UINT8,
541 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FileSource", NULL},
542 {EXIFTAG_SCENETYPE, 1, 1, TIFF_UNDEFINED, 0, TIFF_SETGET_UINT8,
543 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SceneType", NULL},
544 {EXIFTAG_CFAPATTERN, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8,
545 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "CFAPattern", NULL},
546 {EXIFTAG_CUSTOMRENDERED, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16,
547 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "CustomRendered", NULL},
548 {EXIFTAG_EXPOSUREMODE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16,
549 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ExposureMode", NULL},
550 {EXIFTAG_WHITEBALANCE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16,
551 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "WhiteBalance", NULL},
552 {EXIFTAG_DIGITALZOOMRATIO, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT,
553 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "DigitalZoomRatio", NULL},
554 {EXIFTAG_FOCALLENGTHIN35MMFILM, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16,
555 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FocalLengthIn35mmFilm", NULL},
556 {EXIFTAG_SCENECAPTURETYPE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16,
557 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SceneCaptureType", NULL},
558 {EXIFTAG_GAINCONTROL, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT,
559 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "GainControl", NULL},
560 {EXIFTAG_CONTRAST, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16,
561 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Contrast", NULL},
562 {EXIFTAG_SATURATION, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16,
563 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Saturation", NULL},
564 {EXIFTAG_SHARPNESS, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16,
565 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Sharpness", NULL},
566 {EXIFTAG_DEVICESETTINGDESCRIPTION, -1, -1, TIFF_UNDEFINED, 0,
567 TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1,
568 "DeviceSettingDescription", NULL},
569 {EXIFTAG_SUBJECTDISTANCERANGE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16,
570 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SubjectDistanceRange", NULL},
571 {EXIFTAG_IMAGEUNIQUEID, 33, 33, TIFF_ASCII, 0, TIFF_SETGET_ASCII,
572 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ImageUniqueID", NULL},
573 {EXIFTAG_CAMERAOWNERNAME, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII,
574 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "CameraOwnerName", NULL},
575 {EXIFTAG_BODYSERIALNUMBER, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII,
576 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "BodySerialNumber", NULL},
577 {EXIFTAG_LENSSPECIFICATION, 4, 4, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT,
578 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "LensSpecification", NULL},
579 {EXIFTAG_LENSMAKE, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII,
580 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "LensMake", NULL},
581 {EXIFTAG_LENSMODEL, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII,
582 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "LensModel", NULL},
583 {EXIFTAG_LENSSERIALNUMBER, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII,
584 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "LensSerialNumber", NULL},
585 {EXIFTAG_GAMMA, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT,
586 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Gamma", NULL},
587 {EXIFTAG_COMPOSITEIMAGE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16,
588 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "CompositeImage", NULL},
589 {EXIFTAG_SOURCEIMAGENUMBEROFCOMPOSITEIMAGE, 2, 2, TIFF_SHORT, 0,
590 TIFF_SETGET_C0_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0,
591 "SourceImageNumberOfCompositeImage", NULL},
592 {EXIFTAG_SOURCEEXPOSURETIMESOFCOMPOSITEIMAGE, -1, -1, TIFF_UNDEFINED, 0,
593 TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1,
594 "SourceExposureTimesOfCompositeImage", NULL}};
595 /*
596 * EXIF-GPS tags (Version 2.31, July 2016; nothing changed for version 2.32 May
597 * 2019)
598 */
599
600 static const TIFFField gpsFields[] = {
601 /* For the GPS tag definitions in gpsFields[] the standard definition for
602 *Rationals is TIFF_SETGET_DOUBLE and TIFF_SETGET_C0_FLOAT.
603 *-- ATTENTION: After the upgrade with Rational2Double, the GPSTAG values
604 *can now be written and also read in double precision! In order to achieve
605 *double precision for GPS tags: Standard definitions for GPSTAG is kept to
606 *TIFF_SETGET_DOUBLE and TIFF_SETGET_C0_FLOAT is changed to
607 *TIFF_SETGET_C0_DOUBLE.
608 */
609 {GPSTAG_VERSIONID, 4, 4, TIFF_BYTE, 0, TIFF_SETGET_C0_UINT8,
610 TIFF_SETGET_UINT8, FIELD_CUSTOM, 1, 0, "VersionID", NULL},
611 {GPSTAG_LATITUDEREF, 2, 2, TIFF_ASCII, 0, TIFF_SETGET_ASCII,
612 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "LatitudeRef", NULL},
613 {GPSTAG_LATITUDE, 3, 3, TIFF_RATIONAL, 0, TIFF_SETGET_C0_DOUBLE,
614 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Latitude", NULL},
615 {GPSTAG_LONGITUDEREF, 2, 2, TIFF_ASCII, 0, TIFF_SETGET_ASCII,
616 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "LongitudeRef", NULL},
617 {GPSTAG_LONGITUDE, 3, 3, TIFF_RATIONAL, 0, TIFF_SETGET_C0_DOUBLE,
618 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Longitude", NULL},
619 {GPSTAG_ALTITUDEREF, 1, 1, TIFF_BYTE, 0, TIFF_SETGET_UINT8,
620 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "AltitudeRef", NULL},
621 {GPSTAG_ALTITUDE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE,
622 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Altitude", NULL},
623 {GPSTAG_TIMESTAMP, 3, 3, TIFF_RATIONAL, 0, TIFF_SETGET_C0_DOUBLE,
624 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "TimeStamp", NULL},
625 {GPSTAG_SATELLITES, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII,
626 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Satellites", NULL},
627 {GPSTAG_STATUS, 2, 2, TIFF_ASCII, 0, TIFF_SETGET_ASCII,
628 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Status", NULL},
629 {GPSTAG_MEASUREMODE, 2, 2, TIFF_ASCII, 0, TIFF_SETGET_ASCII,
630 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "MeasureMode", NULL},
631 {GPSTAG_DOP, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE,
632 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "DOP", NULL},
633 {GPSTAG_SPEEDREF, 2, 2, TIFF_ASCII, 0, TIFF_SETGET_ASCII,
634 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SpeedRef", NULL},
635 {GPSTAG_SPEED, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE,
636 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Speed", NULL},
637 {GPSTAG_TRACKREF, 2, 2, TIFF_ASCII, 0, TIFF_SETGET_ASCII,
638 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "TrackRef", NULL},
639 {GPSTAG_TRACK, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE,
640 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Track", NULL},
641 {GPSTAG_IMGDIRECTIONREF, 2, 2, TIFF_ASCII, 0, TIFF_SETGET_ASCII,
642 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ImgDirectionRef", NULL},
643 {GPSTAG_IMGDIRECTION, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE,
644 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ImgDirection", NULL},
645 {GPSTAG_MAPDATUM, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII,
646 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "MapDatum", NULL},
647 {GPSTAG_DESTLATITUDEREF, 2, 2, TIFF_ASCII, 0, TIFF_SETGET_ASCII,
648 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "DestLatitudeRef", NULL},
649 {GPSTAG_DESTLATITUDE, 3, 3, TIFF_RATIONAL, 0, TIFF_SETGET_C0_DOUBLE,
650 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "DestLatitude", NULL},
651 {GPSTAG_DESTLONGITUDEREF, 2, 2, TIFF_ASCII, 0, TIFF_SETGET_ASCII,
652 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "DestLongitudeRef", NULL},
653 {GPSTAG_DESTLONGITUDE, 3, 3, TIFF_RATIONAL, 0, TIFF_SETGET_C0_DOUBLE,
654 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "DestLongitude", NULL},
655 {GPSTAG_DESTBEARINGREF, 2, 2, TIFF_ASCII, 0, TIFF_SETGET_ASCII,
656 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "DestBearingRef", NULL},
657 {GPSTAG_DESTBEARING, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE,
658 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "DestBearing", NULL},
659 {GPSTAG_DESTDISTANCEREF, 2, 2, TIFF_ASCII, 0, TIFF_SETGET_ASCII,
660 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "DestDistanceRef", NULL},
661 {GPSTAG_DESTDISTANCE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE,
662 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "DestDistance", NULL},
663 {GPSTAG_PROCESSINGMETHOD, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8,
664 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "ProcessingMethod", NULL},
665 {GPSTAG_AREAINFORMATION, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8,
666 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "AreaInformation", NULL},
667 {GPSTAG_DATESTAMP, 11, 11, TIFF_ASCII, 0, TIFF_SETGET_ASCII,
668 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "DateStamp", NULL},
669 {GPSTAG_DIFFERENTIAL, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16,
670 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Differential", NULL},
671 {GPSTAG_GPSHPOSITIONINGERROR, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE,
672 TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "HorizontalPositioningError",
673 NULL}};
674
675 static const TIFFFieldArray tiffFieldArray = {
676 tfiatImage, 0, TIFFArrayCount(tiffFields), (TIFFField *)tiffFields};
677 static const TIFFFieldArray exifFieldArray = {
678 tfiatExif, 0, TIFFArrayCount(exifFields), (TIFFField *)exifFields};
679 static const TIFFFieldArray gpsFieldArray = {
680 tfiatGps, 0, TIFFArrayCount(gpsFields), (TIFFField *)gpsFields};
681
682 /*
683 * We have our own local lfind() equivalent to avoid subtle differences
684 * in types passed to lfind() on different systems.
685 */
686
td_lfind(const void * key,const void * base,size_t * nmemb,size_t size,int (* compar)(const void *,const void *))687 static void *td_lfind(const void *key, const void *base, size_t *nmemb,
688 size_t size, int (*compar)(const void *, const void *))
689 {
690 char *element, *end;
691
692 end = (char *)base + *nmemb * size;
693 for (element = (char *)base; element < end; element += size)
694 if (!compar(key, element)) /* key found */
695 return element;
696
697 return NULL;
698 }
699
_TIFFGetFields(void)700 const TIFFFieldArray *_TIFFGetFields(void) { return (&tiffFieldArray); }
701
_TIFFGetExifFields(void)702 const TIFFFieldArray *_TIFFGetExifFields(void) { return (&exifFieldArray); }
703
_TIFFGetGpsFields(void)704 const TIFFFieldArray *_TIFFGetGpsFields(void) { return (&gpsFieldArray); }
705
_TIFFSetupFields(TIFF * tif,const TIFFFieldArray * fieldarray)706 void _TIFFSetupFields(TIFF *tif, const TIFFFieldArray *fieldarray)
707 {
708 if (tif->tif_fields && tif->tif_nfields > 0)
709 {
710 uint32_t i;
711
712 for (i = 0; i < tif->tif_nfields; i++)
713 {
714 TIFFField *fld = tif->tif_fields[i];
715 if (fld->field_name != NULL)
716 {
717 if (fld->field_bit == FIELD_CUSTOM && TIFFFieldIsAnonymous(fld))
718 {
719 _TIFFfreeExt(tif, fld->field_name);
720 /* caution: tif_fields[i] must not be the beginning of a
721 * fields-array. Otherwise the following tags are also freed
722 * with the first free().
723 */
724 _TIFFfreeExt(tif, fld);
725 }
726 }
727 }
728
729 _TIFFfreeExt(tif, tif->tif_fields);
730 tif->tif_fields = NULL;
731 tif->tif_nfields = 0;
732 }
733 if (!_TIFFMergeFields(tif, fieldarray->fields, fieldarray->count))
734 {
735 TIFFErrorExtR(tif, "_TIFFSetupFields", "Setting up field info failed");
736 }
737 }
738
tagCompare(const void * a,const void * b)739 static int tagCompare(const void *a, const void *b)
740 {
741 const TIFFField *ta = *(const TIFFField **)a;
742 const TIFFField *tb = *(const TIFFField **)b;
743 /* NB: be careful of return values for 16-bit platforms */
744 if (ta->field_tag != tb->field_tag)
745 return (int)ta->field_tag - (int)tb->field_tag;
746 else
747 return (ta->field_type == TIFF_ANY)
748 ? 0
749 : ((int)tb->field_type - (int)ta->field_type);
750 }
751
tagNameCompare(const void * a,const void * b)752 static int tagNameCompare(const void *a, const void *b)
753 {
754 const TIFFField *ta = *(const TIFFField **)a;
755 const TIFFField *tb = *(const TIFFField **)b;
756 int ret = strcmp(ta->field_name, tb->field_name);
757
758 if (ret)
759 return ret;
760 else
761 return (ta->field_type == TIFF_ANY)
762 ? 0
763 : ((int)tb->field_type - (int)ta->field_type);
764 }
765
_TIFFMergeFields(TIFF * tif,const TIFFField info[],uint32_t n)766 int _TIFFMergeFields(TIFF *tif, const TIFFField info[], uint32_t n)
767 {
768 static const char module[] = "_TIFFMergeFields";
769 static const char reason[] = "for fields array";
770 /* TIFFField** tp; */
771 uint32_t i;
772
773 tif->tif_foundfield = NULL;
774
775 if (tif->tif_fields && tif->tif_nfields > 0)
776 {
777 tif->tif_fields = (TIFFField **)_TIFFCheckRealloc(
778 tif, tif->tif_fields, (tif->tif_nfields + n), sizeof(TIFFField *),
779 reason);
780 }
781 else
782 {
783 tif->tif_fields =
784 (TIFFField **)_TIFFCheckMalloc(tif, n, sizeof(TIFFField *), reason);
785 }
786 if (!tif->tif_fields)
787 {
788 TIFFErrorExtR(tif, module, "Failed to allocate fields array");
789 return 0;
790 }
791
792 /* tp = tif->tif_fields + tif->tif_nfields; */
793 for (i = 0; i < n; i++)
794 {
795 const TIFFField *fip = TIFFFindField(tif, info[i].field_tag, TIFF_ANY);
796
797 /* only add definitions that aren't already present */
798 if (!fip)
799 {
800 tif->tif_fields[tif->tif_nfields] = (TIFFField *)(info + i);
801 tif->tif_nfields++;
802 }
803 }
804
805 /* Sort the field info by tag number */
806 qsort(tif->tif_fields, tif->tif_nfields, sizeof(TIFFField *), tagCompare);
807
808 return n;
809 }
810
_TIFFPrintFieldInfo(TIFF * tif,FILE * fd)811 void _TIFFPrintFieldInfo(TIFF *tif, FILE *fd)
812 {
813 uint32_t i;
814
815 fprintf(fd, "%s: \n", tif->tif_name);
816 for (i = 0; i < tif->tif_nfields; i++)
817 {
818 const TIFFField *fip = tif->tif_fields[i];
819 fprintf(fd, "field[%2d] %5lu, %2d, %2d, %d, %2d, %5s, %5s, %s\n",
820 (int)i, (unsigned long)fip->field_tag, fip->field_readcount,
821 fip->field_writecount, fip->field_type, fip->field_bit,
822 fip->field_oktochange ? "TRUE" : "FALSE",
823 fip->field_passcount ? "TRUE" : "FALSE", fip->field_name);
824 }
825 }
826
827 /*
828 * Return size of TIFFDataType within TIFF-file in bytes
829 */
TIFFDataWidth(TIFFDataType type)830 int TIFFDataWidth(TIFFDataType type)
831 {
832 switch (type)
833 {
834 case 0: /* nothing */
835 case TIFF_BYTE:
836 case TIFF_ASCII:
837 case TIFF_SBYTE:
838 case TIFF_UNDEFINED:
839 return 1;
840 case TIFF_SHORT:
841 case TIFF_SSHORT:
842 return 2;
843 case TIFF_LONG:
844 case TIFF_SLONG:
845 case TIFF_FLOAT:
846 case TIFF_IFD:
847 return 4;
848 case TIFF_RATIONAL:
849 case TIFF_SRATIONAL:
850 case TIFF_DOUBLE:
851 case TIFF_LONG8:
852 case TIFF_SLONG8:
853 case TIFF_IFD8:
854 return 8;
855 default:
856 return 0; /* will return 0 for unknown types */
857 }
858 }
859
860 /*
861 * Return internal storage size of TIFFSetGetFieldType in bytes.
862 * TIFFSetField() and TIFFGetField() have to provide the parameter accordingly.
863 * Replaces internal functions _TIFFDataSize() and _TIFFSetGetFieldSize()
864 * with now extern available function TIFFFieldSetGetSize().
865 */
TIFFFieldSetGetSize(const TIFFField * fip)866 int TIFFFieldSetGetSize(const TIFFField *fip)
867 {
868 /*
869 * TIFFSetField() and TIFFGetField() must provide the parameter accordingly
870 * to the definition of "set_field_type" of the tag definition in
871 * dir_info.c. This function returns the data size for that purpose.
872 *
873 * Furthermore, this data size is also used for the internal storage,
874 * even for TIFF_RATIONAL values for FIELD_CUSTOM, which are stored
875 * internally as 4-byte float, but some of them should be stored internally
876 * as 8-byte double, depending on the "set_field_type" _FLOAT_ or _DOUBLE_.
877 */
878 if (fip == NULL)
879 return 0;
880
881 switch (fip->set_field_type)
882 {
883 case TIFF_SETGET_UNDEFINED:
884 case TIFF_SETGET_ASCII:
885 case TIFF_SETGET_C0_ASCII:
886 case TIFF_SETGET_C16_ASCII:
887 case TIFF_SETGET_C32_ASCII:
888 case TIFF_SETGET_OTHER:
889 return 1;
890 case TIFF_SETGET_UINT8:
891 case TIFF_SETGET_SINT8:
892 case TIFF_SETGET_C0_UINT8:
893 case TIFF_SETGET_C0_SINT8:
894 case TIFF_SETGET_C16_UINT8:
895 case TIFF_SETGET_C16_SINT8:
896 case TIFF_SETGET_C32_UINT8:
897 case TIFF_SETGET_C32_SINT8:
898 return 1;
899 case TIFF_SETGET_UINT16:
900 case TIFF_SETGET_SINT16:
901 case TIFF_SETGET_C0_UINT16:
902 case TIFF_SETGET_C0_SINT16:
903 case TIFF_SETGET_C16_UINT16:
904 case TIFF_SETGET_C16_SINT16:
905 case TIFF_SETGET_C32_UINT16:
906 case TIFF_SETGET_C32_SINT16:
907 return 2;
908 case TIFF_SETGET_INT:
909 case TIFF_SETGET_UINT32:
910 case TIFF_SETGET_SINT32:
911 case TIFF_SETGET_FLOAT:
912 case TIFF_SETGET_UINT16_PAIR:
913 case TIFF_SETGET_C0_UINT32:
914 case TIFF_SETGET_C0_SINT32:
915 case TIFF_SETGET_C0_FLOAT:
916 case TIFF_SETGET_C16_UINT32:
917 case TIFF_SETGET_C16_SINT32:
918 case TIFF_SETGET_C16_FLOAT:
919 case TIFF_SETGET_C32_UINT32:
920 case TIFF_SETGET_C32_SINT32:
921 case TIFF_SETGET_C32_FLOAT:
922 return 4;
923 case TIFF_SETGET_UINT64:
924 case TIFF_SETGET_SINT64:
925 case TIFF_SETGET_DOUBLE:
926 case TIFF_SETGET_IFD8:
927 case TIFF_SETGET_C0_UINT64:
928 case TIFF_SETGET_C0_SINT64:
929 case TIFF_SETGET_C0_DOUBLE:
930 case TIFF_SETGET_C0_IFD8:
931 case TIFF_SETGET_C16_UINT64:
932 case TIFF_SETGET_C16_SINT64:
933 case TIFF_SETGET_C16_DOUBLE:
934 case TIFF_SETGET_C16_IFD8:
935 case TIFF_SETGET_C32_UINT64:
936 case TIFF_SETGET_C32_SINT64:
937 case TIFF_SETGET_C32_DOUBLE:
938 case TIFF_SETGET_C32_IFD8:
939 return 8;
940 default:
941 return 0;
942 }
943 } /*-- TIFFFieldSetGetSize() --- */
944
945 /*
946 * Return size of count parameter of TIFFSetField() and TIFFGetField()
947 * and also if it is required: 0=none, 2=uint16_t, 4=uint32_t
948 */
TIFFFieldSetGetCountSize(const TIFFField * fip)949 int TIFFFieldSetGetCountSize(const TIFFField *fip)
950 {
951 if (fip == NULL)
952 return 0;
953
954 switch (fip->set_field_type)
955 {
956 case TIFF_SETGET_C16_ASCII:
957 case TIFF_SETGET_C16_UINT8:
958 case TIFF_SETGET_C16_SINT8:
959 case TIFF_SETGET_C16_UINT16:
960 case TIFF_SETGET_C16_SINT16:
961 case TIFF_SETGET_C16_UINT32:
962 case TIFF_SETGET_C16_SINT32:
963 case TIFF_SETGET_C16_FLOAT:
964 case TIFF_SETGET_C16_UINT64:
965 case TIFF_SETGET_C16_SINT64:
966 case TIFF_SETGET_C16_DOUBLE:
967 case TIFF_SETGET_C16_IFD8:
968 return 2;
969 case TIFF_SETGET_C32_ASCII:
970 case TIFF_SETGET_C32_UINT8:
971 case TIFF_SETGET_C32_SINT8:
972 case TIFF_SETGET_C32_UINT16:
973 case TIFF_SETGET_C32_SINT16:
974 case TIFF_SETGET_C32_UINT32:
975 case TIFF_SETGET_C32_SINT32:
976 case TIFF_SETGET_C32_FLOAT:
977 case TIFF_SETGET_C32_UINT64:
978 case TIFF_SETGET_C32_SINT64:
979 case TIFF_SETGET_C32_DOUBLE:
980 case TIFF_SETGET_C32_IFD8:
981 return 4;
982 default:
983 return 0;
984 }
985 } /*-- TIFFFieldSetGetCountSize() --- */
986
TIFFFindField(TIFF * tif,uint32_t tag,TIFFDataType dt)987 const TIFFField *TIFFFindField(TIFF *tif, uint32_t tag, TIFFDataType dt)
988 {
989 TIFFField key = {0, 0, 0, TIFF_NOTYPE, 0, 0, 0, 0, 0, 0, NULL, NULL};
990 TIFFField *pkey = &key;
991 const TIFFField **ret;
992 if (tif->tif_foundfield && tif->tif_foundfield->field_tag == tag &&
993 (dt == TIFF_ANY || dt == tif->tif_foundfield->field_type))
994 return tif->tif_foundfield;
995
996 /* If we are invoked with no field information, then just return. */
997 if (!tif->tif_fields)
998 return NULL;
999
1000 /* NB: use sorted search (e.g. binary search) */
1001
1002 key.field_tag = tag;
1003 key.field_type = dt;
1004
1005 ret = (const TIFFField **)bsearch(&pkey, tif->tif_fields, tif->tif_nfields,
1006 sizeof(TIFFField *), tagCompare);
1007 return tif->tif_foundfield = (ret ? *ret : NULL);
1008 }
1009
_TIFFFindFieldByName(TIFF * tif,const char * field_name,TIFFDataType dt)1010 static const TIFFField *_TIFFFindFieldByName(TIFF *tif, const char *field_name,
1011 TIFFDataType dt)
1012 {
1013 TIFFField key = {0, 0, 0, TIFF_NOTYPE, 0, 0, 0, 0, 0, 0, NULL, NULL};
1014 TIFFField *pkey = &key;
1015 const TIFFField **ret;
1016 if (tif->tif_foundfield &&
1017 streq(tif->tif_foundfield->field_name, field_name) &&
1018 (dt == TIFF_ANY || dt == tif->tif_foundfield->field_type))
1019 return (tif->tif_foundfield);
1020
1021 /* If we are invoked with no field information, then just return. */
1022 if (!tif->tif_fields)
1023 return NULL;
1024
1025 /* NB: use linear search since list is sorted by key#, not name */
1026
1027 key.field_name = (char *)field_name;
1028 key.field_type = dt;
1029
1030 ret =
1031 (const TIFFField **)td_lfind(&pkey, tif->tif_fields, &tif->tif_nfields,
1032 sizeof(TIFFField *), tagNameCompare);
1033
1034 return tif->tif_foundfield = (ret ? *ret : NULL);
1035 }
1036
TIFFFieldWithTag(TIFF * tif,uint32_t tag)1037 const TIFFField *TIFFFieldWithTag(TIFF *tif, uint32_t tag)
1038 {
1039 const TIFFField *fip = TIFFFindField(tif, tag, TIFF_ANY);
1040 if (!fip)
1041 {
1042 TIFFErrorExtR(tif, "TIFFFieldWithTag",
1043 "Internal error, unknown tag 0x%x", (unsigned int)tag);
1044 }
1045 return (fip);
1046 }
1047
TIFFFieldWithName(TIFF * tif,const char * field_name)1048 const TIFFField *TIFFFieldWithName(TIFF *tif, const char *field_name)
1049 {
1050 const TIFFField *fip = _TIFFFindFieldByName(tif, field_name, TIFF_ANY);
1051 if (!fip)
1052 {
1053 TIFFErrorExtR(tif, "TIFFFieldWithName",
1054 "Internal error, unknown tag %s", field_name);
1055 }
1056 return (fip);
1057 }
1058
TIFFFieldTag(const TIFFField * fip)1059 uint32_t TIFFFieldTag(const TIFFField *fip) { return fip->field_tag; }
1060
TIFFFieldName(const TIFFField * fip)1061 const char *TIFFFieldName(const TIFFField *fip) { return fip->field_name; }
1062
TIFFFieldDataType(const TIFFField * fip)1063 TIFFDataType TIFFFieldDataType(const TIFFField *fip) { return fip->field_type; }
1064
TIFFFieldPassCount(const TIFFField * fip)1065 int TIFFFieldPassCount(const TIFFField *fip) { return fip->field_passcount; }
1066
TIFFFieldReadCount(const TIFFField * fip)1067 int TIFFFieldReadCount(const TIFFField *fip) { return fip->field_readcount; }
1068
TIFFFieldWriteCount(const TIFFField * fip)1069 int TIFFFieldWriteCount(const TIFFField *fip) { return fip->field_writecount; }
1070
TIFFFieldIsAnonymous(const TIFFField * fip)1071 int TIFFFieldIsAnonymous(const TIFFField *fip) { return fip->field_anonymous; }
1072
_TIFFFindOrRegisterField(TIFF * tif,uint32_t tag,TIFFDataType dt)1073 const TIFFField *_TIFFFindOrRegisterField(TIFF *tif, uint32_t tag,
1074 TIFFDataType dt)
1075
1076 {
1077 const TIFFField *fld;
1078
1079 fld = TIFFFindField(tif, tag, dt);
1080 if (fld == NULL)
1081 {
1082 fld = _TIFFCreateAnonField(tif, tag, dt);
1083 if (!_TIFFMergeFields(tif, fld, 1))
1084 return NULL;
1085 }
1086
1087 return fld;
1088 }
1089
_TIFFCreateAnonField(TIFF * tif,uint32_t tag,TIFFDataType field_type)1090 TIFFField *_TIFFCreateAnonField(TIFF *tif, uint32_t tag,
1091 TIFFDataType field_type)
1092 {
1093 TIFFField *fld;
1094 (void)tif;
1095
1096 fld = (TIFFField *)_TIFFmallocExt(tif, sizeof(TIFFField));
1097 if (fld == NULL)
1098 return NULL;
1099 _TIFFmemset(fld, 0, sizeof(TIFFField));
1100
1101 fld->field_tag = tag;
1102 fld->field_readcount = TIFF_VARIABLE2;
1103 fld->field_writecount = TIFF_VARIABLE2;
1104 fld->field_type = field_type;
1105 fld->field_anonymous =
1106 1; /* indicate that this is an anonymous / unknown tag */
1107 switch (field_type)
1108 {
1109 case TIFF_BYTE:
1110 case TIFF_UNDEFINED:
1111 fld->set_field_type = TIFF_SETGET_C32_UINT8;
1112 fld->get_field_type = TIFF_SETGET_C32_UINT8;
1113 break;
1114 case TIFF_ASCII:
1115 fld->set_field_type = TIFF_SETGET_C32_ASCII;
1116 fld->get_field_type = TIFF_SETGET_C32_ASCII;
1117 break;
1118 case TIFF_SHORT:
1119 fld->set_field_type = TIFF_SETGET_C32_UINT16;
1120 fld->get_field_type = TIFF_SETGET_C32_UINT16;
1121 break;
1122 case TIFF_LONG:
1123 fld->set_field_type = TIFF_SETGET_C32_UINT32;
1124 fld->get_field_type = TIFF_SETGET_C32_UINT32;
1125 break;
1126 case TIFF_RATIONAL:
1127 case TIFF_SRATIONAL:
1128 case TIFF_FLOAT:
1129 fld->set_field_type = TIFF_SETGET_C32_FLOAT;
1130 fld->get_field_type = TIFF_SETGET_C32_FLOAT;
1131 break;
1132 case TIFF_SBYTE:
1133 fld->set_field_type = TIFF_SETGET_C32_SINT8;
1134 fld->get_field_type = TIFF_SETGET_C32_SINT8;
1135 break;
1136 case TIFF_SSHORT:
1137 fld->set_field_type = TIFF_SETGET_C32_SINT16;
1138 fld->get_field_type = TIFF_SETGET_C32_SINT16;
1139 break;
1140 case TIFF_SLONG:
1141 fld->set_field_type = TIFF_SETGET_C32_SINT32;
1142 fld->get_field_type = TIFF_SETGET_C32_SINT32;
1143 break;
1144 case TIFF_DOUBLE:
1145 fld->set_field_type = TIFF_SETGET_C32_DOUBLE;
1146 fld->get_field_type = TIFF_SETGET_C32_DOUBLE;
1147 break;
1148 case TIFF_IFD:
1149 case TIFF_IFD8:
1150 fld->set_field_type = TIFF_SETGET_C32_IFD8;
1151 fld->get_field_type = TIFF_SETGET_C32_IFD8;
1152 break;
1153 case TIFF_LONG8:
1154 fld->set_field_type = TIFF_SETGET_C32_UINT64;
1155 fld->get_field_type = TIFF_SETGET_C32_UINT64;
1156 break;
1157 case TIFF_SLONG8:
1158 fld->set_field_type = TIFF_SETGET_C32_SINT64;
1159 fld->get_field_type = TIFF_SETGET_C32_SINT64;
1160 break;
1161 default:
1162 fld->set_field_type = TIFF_SETGET_UNDEFINED;
1163 fld->get_field_type = TIFF_SETGET_UNDEFINED;
1164 break;
1165 }
1166 fld->field_bit = FIELD_CUSTOM;
1167 fld->field_oktochange = TRUE;
1168 fld->field_passcount = TRUE;
1169 fld->field_name = (char *)_TIFFmallocExt(tif, 32);
1170 if (fld->field_name == NULL)
1171 {
1172 _TIFFfreeExt(tif, fld);
1173 return NULL;
1174 }
1175 fld->field_subfields = NULL;
1176
1177 /*
1178 * note that this name is a special sign to TIFFClose() and
1179 * _TIFFSetupFields() to free the field
1180 * Update:
1181 * This special sign is replaced by fld->field_anonymous flag.
1182 */
1183 (void)snprintf(fld->field_name, 32, "Tag %d", (int)tag);
1184
1185 return fld;
1186 }
1187
1188 /****************************************************************************
1189 * O B S O L E T E D I N T E R F A C E S
1190 *
1191 * Don't use this stuff in your applications, it may be removed in the future
1192 * libtiff versions.
1193 ****************************************************************************/
1194
_TIFFSetGetType(TIFFDataType type,short count,unsigned char passcount)1195 static TIFFSetGetFieldType _TIFFSetGetType(TIFFDataType type, short count,
1196 unsigned char passcount)
1197 {
1198 if (type == TIFF_ASCII && count == TIFF_VARIABLE && passcount == 0)
1199 return TIFF_SETGET_ASCII;
1200
1201 else if (count == 1 && passcount == 0)
1202 {
1203 switch (type)
1204 {
1205 case TIFF_BYTE:
1206 case TIFF_UNDEFINED:
1207 return TIFF_SETGET_UINT8;
1208 case TIFF_ASCII:
1209 return TIFF_SETGET_ASCII;
1210 case TIFF_SHORT:
1211 return TIFF_SETGET_UINT16;
1212 case TIFF_LONG:
1213 return TIFF_SETGET_UINT32;
1214 case TIFF_RATIONAL:
1215 case TIFF_SRATIONAL:
1216 case TIFF_FLOAT:
1217 return TIFF_SETGET_FLOAT;
1218 case TIFF_SBYTE:
1219 return TIFF_SETGET_SINT8;
1220 case TIFF_SSHORT:
1221 return TIFF_SETGET_SINT16;
1222 case TIFF_SLONG:
1223 return TIFF_SETGET_SINT32;
1224 case TIFF_DOUBLE:
1225 return TIFF_SETGET_DOUBLE;
1226 case TIFF_IFD:
1227 case TIFF_IFD8:
1228 return TIFF_SETGET_IFD8;
1229 case TIFF_LONG8:
1230 return TIFF_SETGET_UINT64;
1231 case TIFF_SLONG8:
1232 return TIFF_SETGET_SINT64;
1233 default:
1234 return TIFF_SETGET_UNDEFINED;
1235 }
1236 }
1237
1238 else if (count >= 1 && passcount == 0)
1239 {
1240 switch (type)
1241 {
1242 case TIFF_BYTE:
1243 case TIFF_UNDEFINED:
1244 return TIFF_SETGET_C0_UINT8;
1245 case TIFF_ASCII:
1246 return TIFF_SETGET_C0_ASCII;
1247 case TIFF_SHORT:
1248 return TIFF_SETGET_C0_UINT16;
1249 case TIFF_LONG:
1250 return TIFF_SETGET_C0_UINT32;
1251 case TIFF_RATIONAL:
1252 case TIFF_SRATIONAL:
1253 case TIFF_FLOAT:
1254 return TIFF_SETGET_C0_FLOAT;
1255 case TIFF_SBYTE:
1256 return TIFF_SETGET_C0_SINT8;
1257 case TIFF_SSHORT:
1258 return TIFF_SETGET_C0_SINT16;
1259 case TIFF_SLONG:
1260 return TIFF_SETGET_C0_SINT32;
1261 case TIFF_DOUBLE:
1262 return TIFF_SETGET_C0_DOUBLE;
1263 case TIFF_IFD:
1264 case TIFF_IFD8:
1265 return TIFF_SETGET_C0_IFD8;
1266 case TIFF_LONG8:
1267 return TIFF_SETGET_C0_UINT64;
1268 case TIFF_SLONG8:
1269 return TIFF_SETGET_C0_SINT64;
1270 default:
1271 return TIFF_SETGET_UNDEFINED;
1272 }
1273 }
1274
1275 else if (count == TIFF_VARIABLE && passcount == 1)
1276 {
1277 switch (type)
1278 {
1279 case TIFF_BYTE:
1280 case TIFF_UNDEFINED:
1281 return TIFF_SETGET_C16_UINT8;
1282 case TIFF_ASCII:
1283 return TIFF_SETGET_C16_ASCII;
1284 case TIFF_SHORT:
1285 return TIFF_SETGET_C16_UINT16;
1286 case TIFF_LONG:
1287 return TIFF_SETGET_C16_UINT32;
1288 case TIFF_RATIONAL:
1289 case TIFF_SRATIONAL:
1290 case TIFF_FLOAT:
1291 return TIFF_SETGET_C16_FLOAT;
1292 case TIFF_SBYTE:
1293 return TIFF_SETGET_C16_SINT8;
1294 case TIFF_SSHORT:
1295 return TIFF_SETGET_C16_SINT16;
1296 case TIFF_SLONG:
1297 return TIFF_SETGET_C16_SINT32;
1298 case TIFF_DOUBLE:
1299 return TIFF_SETGET_C16_DOUBLE;
1300 case TIFF_IFD:
1301 case TIFF_IFD8:
1302 return TIFF_SETGET_C16_IFD8;
1303 case TIFF_LONG8:
1304 return TIFF_SETGET_C16_UINT64;
1305 case TIFF_SLONG8:
1306 return TIFF_SETGET_C16_SINT64;
1307 default:
1308 return TIFF_SETGET_UNDEFINED;
1309 }
1310 }
1311
1312 else if (count == TIFF_VARIABLE2 && passcount == 1)
1313 {
1314 switch (type)
1315 {
1316 case TIFF_BYTE:
1317 case TIFF_UNDEFINED:
1318 return TIFF_SETGET_C32_UINT8;
1319 case TIFF_ASCII:
1320 return TIFF_SETGET_C32_ASCII;
1321 case TIFF_SHORT:
1322 return TIFF_SETGET_C32_UINT16;
1323 case TIFF_LONG:
1324 return TIFF_SETGET_C32_UINT32;
1325 case TIFF_RATIONAL:
1326 case TIFF_SRATIONAL:
1327 case TIFF_FLOAT:
1328 return TIFF_SETGET_C32_FLOAT;
1329 case TIFF_SBYTE:
1330 return TIFF_SETGET_C32_SINT8;
1331 case TIFF_SSHORT:
1332 return TIFF_SETGET_C32_SINT16;
1333 case TIFF_SLONG:
1334 return TIFF_SETGET_C32_SINT32;
1335 case TIFF_DOUBLE:
1336 return TIFF_SETGET_C32_DOUBLE;
1337 case TIFF_IFD:
1338 case TIFF_IFD8:
1339 return TIFF_SETGET_C32_IFD8;
1340 case TIFF_LONG8:
1341 return TIFF_SETGET_C32_UINT64;
1342 case TIFF_SLONG8:
1343 return TIFF_SETGET_C32_SINT64;
1344 default:
1345 return TIFF_SETGET_UNDEFINED;
1346 }
1347 }
1348
1349 return TIFF_SETGET_UNDEFINED;
1350 }
1351
TIFFMergeFieldInfo(TIFF * tif,const TIFFFieldInfo info[],uint32_t n)1352 int TIFFMergeFieldInfo(TIFF *tif, const TIFFFieldInfo info[], uint32_t n)
1353 {
1354 static const char module[] = "TIFFMergeFieldInfo";
1355 static const char reason[] = "for fields array";
1356 TIFFField *tp;
1357 size_t nfields;
1358 uint32_t i;
1359
1360 if (tif->tif_nfieldscompat > 0)
1361 {
1362 tif->tif_fieldscompat = (TIFFFieldArray *)_TIFFCheckRealloc(
1363 tif, tif->tif_fieldscompat, tif->tif_nfieldscompat + 1,
1364 sizeof(TIFFFieldArray), reason);
1365 }
1366 else
1367 {
1368 tif->tif_fieldscompat = (TIFFFieldArray *)_TIFFCheckMalloc(
1369 tif, 1, sizeof(TIFFFieldArray), reason);
1370 }
1371 if (!tif->tif_fieldscompat)
1372 {
1373 TIFFErrorExtR(tif, module, "Failed to allocate fields array");
1374 return -1;
1375 }
1376 nfields = tif->tif_nfieldscompat++;
1377
1378 tif->tif_fieldscompat[nfields].type = tfiatOther;
1379 tif->tif_fieldscompat[nfields].allocated_size = n;
1380 tif->tif_fieldscompat[nfields].count = n;
1381 tif->tif_fieldscompat[nfields].fields =
1382 (TIFFField *)_TIFFCheckMalloc(tif, n, sizeof(TIFFField), reason);
1383 if (!tif->tif_fieldscompat[nfields].fields)
1384 {
1385 TIFFErrorExtR(tif, module, "Failed to allocate fields array");
1386 return -1;
1387 }
1388
1389 tp = tif->tif_fieldscompat[nfields].fields;
1390 for (i = 0; i < n; i++)
1391 {
1392 tp->field_tag = info[i].field_tag;
1393 tp->field_readcount = info[i].field_readcount;
1394 tp->field_writecount = info[i].field_writecount;
1395 tp->field_type = info[i].field_type;
1396 tp->field_anonymous = 0;
1397 tp->set_field_type =
1398 _TIFFSetGetType(info[i].field_type, info[i].field_readcount,
1399 info[i].field_passcount);
1400 tp->get_field_type =
1401 _TIFFSetGetType(info[i].field_type, info[i].field_readcount,
1402 info[i].field_passcount);
1403 tp->field_bit = info[i].field_bit;
1404 tp->field_oktochange = info[i].field_oktochange;
1405 tp->field_passcount = info[i].field_passcount;
1406 if (info[i].field_name == NULL)
1407 {
1408 TIFFErrorExtR(tif, module,
1409 "Field_name of %d.th allocation tag %d is NULL", i,
1410 info[i].field_tag);
1411 return -1;
1412 }
1413 tp->field_name = info[i].field_name;
1414 tp->field_subfields = NULL;
1415 tp++;
1416 }
1417
1418 if (!_TIFFMergeFields(tif, tif->tif_fieldscompat[nfields].fields, n))
1419 {
1420 TIFFErrorExtR(tif, module, "Setting up field info failed");
1421 return -1;
1422 }
1423
1424 return 0;
1425 }
1426
_TIFFCheckFieldIsValidForCodec(TIFF * tif,ttag_t tag)1427 int _TIFFCheckFieldIsValidForCodec(TIFF *tif, ttag_t tag)
1428 {
1429 /* Filter out non-codec specific tags */
1430 switch (tag)
1431 {
1432 /* Shared tags */
1433 case TIFFTAG_PREDICTOR:
1434 /* JPEG tags */
1435 case TIFFTAG_JPEGTABLES:
1436 /* OJPEG tags */
1437 case TIFFTAG_JPEGIFOFFSET:
1438 case TIFFTAG_JPEGIFBYTECOUNT:
1439 case TIFFTAG_JPEGQTABLES:
1440 case TIFFTAG_JPEGDCTABLES:
1441 case TIFFTAG_JPEGACTABLES:
1442 case TIFFTAG_JPEGPROC:
1443 case TIFFTAG_JPEGRESTARTINTERVAL:
1444 /* CCITT* */
1445 case TIFFTAG_BADFAXLINES:
1446 case TIFFTAG_CLEANFAXDATA:
1447 case TIFFTAG_CONSECUTIVEBADFAXLINES:
1448 case TIFFTAG_GROUP3OPTIONS:
1449 case TIFFTAG_GROUP4OPTIONS:
1450 /* LERC */
1451 case TIFFTAG_LERC_PARAMETERS:
1452 break;
1453 default:
1454 return 1;
1455 }
1456 if (!TIFFIsCODECConfigured(tif->tif_dir.td_compression))
1457 {
1458 return 0;
1459 }
1460 /* Check if codec specific tags are allowed for the current
1461 * compression scheme (codec) */
1462 switch (tif->tif_dir.td_compression)
1463 {
1464 case COMPRESSION_LZW:
1465 if (tag == TIFFTAG_PREDICTOR)
1466 return 1;
1467 break;
1468 case COMPRESSION_PACKBITS:
1469 /* No codec-specific tags */
1470 break;
1471 case COMPRESSION_THUNDERSCAN:
1472 /* No codec-specific tags */
1473 break;
1474 case COMPRESSION_NEXT:
1475 /* No codec-specific tags */
1476 break;
1477 case COMPRESSION_JPEG:
1478 if (tag == TIFFTAG_JPEGTABLES)
1479 return 1;
1480 break;
1481 case COMPRESSION_OJPEG:
1482 switch (tag)
1483 {
1484 case TIFFTAG_JPEGIFOFFSET:
1485 case TIFFTAG_JPEGIFBYTECOUNT:
1486 case TIFFTAG_JPEGQTABLES:
1487 case TIFFTAG_JPEGDCTABLES:
1488 case TIFFTAG_JPEGACTABLES:
1489 case TIFFTAG_JPEGPROC:
1490 case TIFFTAG_JPEGRESTARTINTERVAL:
1491 return 1;
1492 }
1493 break;
1494 case COMPRESSION_CCITTRLE:
1495 case COMPRESSION_CCITTRLEW:
1496 case COMPRESSION_CCITTFAX3:
1497 case COMPRESSION_CCITTFAX4:
1498 switch (tag)
1499 {
1500 case TIFFTAG_BADFAXLINES:
1501 case TIFFTAG_CLEANFAXDATA:
1502 case TIFFTAG_CONSECUTIVEBADFAXLINES:
1503 return 1;
1504 case TIFFTAG_GROUP3OPTIONS:
1505 if (tif->tif_dir.td_compression == COMPRESSION_CCITTFAX3)
1506 return 1;
1507 break;
1508 case TIFFTAG_GROUP4OPTIONS:
1509 if (tif->tif_dir.td_compression == COMPRESSION_CCITTFAX4)
1510 return 1;
1511 break;
1512 }
1513 break;
1514 case COMPRESSION_JBIG:
1515 /* No codec-specific tags */
1516 break;
1517 case COMPRESSION_DEFLATE:
1518 case COMPRESSION_ADOBE_DEFLATE:
1519 if (tag == TIFFTAG_PREDICTOR)
1520 return 1;
1521 break;
1522 case COMPRESSION_PIXARLOG:
1523 if (tag == TIFFTAG_PREDICTOR)
1524 return 1;
1525 break;
1526 case COMPRESSION_SGILOG:
1527 case COMPRESSION_SGILOG24:
1528 /* No codec-specific tags */
1529 break;
1530 case COMPRESSION_LZMA:
1531 if (tag == TIFFTAG_PREDICTOR)
1532 return 1;
1533 break;
1534 case COMPRESSION_ZSTD:
1535 if (tag == TIFFTAG_PREDICTOR)
1536 return 1;
1537 break;
1538 case COMPRESSION_LERC:
1539 if (tag == TIFFTAG_LERC_PARAMETERS)
1540 return 1;
1541 break;
1542 }
1543 return 0;
1544 }
1545