• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* $Id: tif_dirinfo.c,v 1.126 2016-11-18 02:52:13 bfriesen Exp $ */
2 
3 /*
4  * Copyright (c) 1988-1997 Sam Leffler
5  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
6  *
7  * Permission to use, copy, modify, distribute, and sell this software and
8  * its documentation for any purpose is hereby granted without fee, provided
9  * that (i) the above copyright notices and this permission notice appear in
10  * all copies of the software and related documentation, and (ii) the names of
11  * Sam Leffler and Silicon Graphics may not be used in any advertising or
12  * publicity relating to the software without the specific, prior written
13  * permission of Sam Leffler and Silicon Graphics.
14  *
15  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
16  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
17  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
18  *
19  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
20  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
21  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
22  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
23  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
24  * OF THIS SOFTWARE.
25  */
26 
27 /*
28  * TIFF Library.
29  *
30  * Core Directory Tag Support.
31  */
32 #include "tiffiop.h"
33 #include <stdlib.h>
34 
35 /*
36  * NOTE: THIS ARRAY IS ASSUMED TO BE SORTED BY TAG.
37  *
38  * NOTE: The second field (field_readcount) and third field (field_writecount)
39  *       sometimes use the values TIFF_VARIABLE (-1), TIFF_VARIABLE2 (-3)
40  *       and TIFF_SPP (-2). The macros should be used but would throw off
41  *       the formatting of the code, so please interpret the -1, -2 and -3
42  *       values accordingly.
43  */
44 
45 /* const object should be initialized */
46 #ifdef _MSC_VER
47 #pragma warning( push )
48 #pragma warning( disable : 4132 )
49 #endif
50 static const TIFFFieldArray tiffFieldArray;
51 static const TIFFFieldArray exifFieldArray;
52 #ifdef _MSC_VER
53 #pragma warning( pop )
54 #endif
55 
56 static const TIFFField
57 tiffFields[] = {
58 	{ TIFFTAG_SUBFILETYPE, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_SUBFILETYPE, 1, 0, "SubfileType", NULL },
59 	{ TIFFTAG_OSUBFILETYPE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_SUBFILETYPE, 1, 0, "OldSubfileType", NULL },
60 	{ TIFFTAG_IMAGEWIDTH, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_IMAGEDIMENSIONS, 0, 0, "ImageWidth", NULL },
61 	{ TIFFTAG_IMAGELENGTH, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_IMAGEDIMENSIONS, 1, 0, "ImageLength", NULL },
62 	{ TIFFTAG_BITSPERSAMPLE, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_BITSPERSAMPLE, 0, 0, "BitsPerSample", NULL },
63 	{ TIFFTAG_COMPRESSION, -1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_COMPRESSION, 0, 0, "Compression", NULL },
64 	{ TIFFTAG_PHOTOMETRIC, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_PHOTOMETRIC, 0, 0, "PhotometricInterpretation", NULL },
65 	{ TIFFTAG_THRESHHOLDING, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_THRESHHOLDING, 1, 0, "Threshholding", NULL },
66 	{ TIFFTAG_CELLWIDTH, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_IGNORE, 1, 0, "CellWidth", NULL },
67 	{ TIFFTAG_CELLLENGTH, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_IGNORE, 1, 0, "CellLength", NULL },
68 	{ TIFFTAG_FILLORDER, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_FILLORDER, 0, 0, "FillOrder", NULL },
69 	{ TIFFTAG_DOCUMENTNAME, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "DocumentName", NULL },
70 	{ TIFFTAG_IMAGEDESCRIPTION, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ImageDescription", NULL },
71 	{ TIFFTAG_MAKE, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Make", NULL },
72 	{ TIFFTAG_MODEL, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Model", NULL },
73 	{ TIFFTAG_STRIPOFFSETS, -1, -1, TIFF_LONG8, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_STRIPOFFSETS, 0, 0, "StripOffsets", NULL },
74 	{ TIFFTAG_ORIENTATION, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_ORIENTATION, 0, 0, "Orientation", NULL },
75 	{ TIFFTAG_SAMPLESPERPIXEL, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_SAMPLESPERPIXEL, 0, 0, "SamplesPerPixel", NULL },
76 	{ TIFFTAG_ROWSPERSTRIP, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_ROWSPERSTRIP, 0, 0, "RowsPerStrip", NULL },
77 	{ TIFFTAG_STRIPBYTECOUNTS, -1, -1, TIFF_LONG8, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_STRIPBYTECOUNTS, 0, 0, "StripByteCounts", NULL },
78 	{ TIFFTAG_MINSAMPLEVALUE, -2, -1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_MINSAMPLEVALUE, 1, 0, "MinSampleValue", NULL },
79 	{ TIFFTAG_MAXSAMPLEVALUE, -2, -1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_MAXSAMPLEVALUE, 1, 0, "MaxSampleValue", NULL },
80 	{ TIFFTAG_XRESOLUTION, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_RESOLUTION, 1, 0, "XResolution", NULL },
81 	{ TIFFTAG_YRESOLUTION, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_RESOLUTION, 1, 0, "YResolution", NULL },
82 	{ TIFFTAG_PLANARCONFIG, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_PLANARCONFIG, 0, 0, "PlanarConfiguration", NULL },
83 	{ TIFFTAG_PAGENAME, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "PageName", NULL },
84 	{ TIFFTAG_XPOSITION, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_POSITION, 1, 0, "XPosition", NULL },
85 	{ TIFFTAG_YPOSITION, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_POSITION, 1, 0, "YPosition", NULL },
86 	{ TIFFTAG_FREEOFFSETS, -1, -1, TIFF_LONG8, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_IGNORE, 0, 0, "FreeOffsets", NULL },
87 	{ TIFFTAG_FREEBYTECOUNTS, -1, -1, TIFF_LONG8, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_IGNORE, 0, 0, "FreeByteCounts", NULL },
88 	{ TIFFTAG_GRAYRESPONSEUNIT, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_IGNORE, 1, 0, "GrayResponseUnit", NULL },
89 	{ TIFFTAG_GRAYRESPONSECURVE, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_IGNORE, 1, 0, "GrayResponseCurve", NULL },
90 	{ TIFFTAG_RESOLUTIONUNIT, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_RESOLUTIONUNIT, 1, 0, "ResolutionUnit", NULL },
91 	{ TIFFTAG_PAGENUMBER, 2, 2, TIFF_SHORT, 0, TIFF_SETGET_UINT16_PAIR, TIFF_SETGET_UNDEFINED, FIELD_PAGENUMBER, 1, 0, "PageNumber", NULL },
92 	{ TIFFTAG_COLORRESPONSEUNIT, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_IGNORE, 1, 0, "ColorResponseUnit", NULL },
93 	{ TIFFTAG_TRANSFERFUNCTION, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_OTHER, TIFF_SETGET_UNDEFINED, FIELD_TRANSFERFUNCTION, 1, 0, "TransferFunction", NULL },
94 	{ TIFFTAG_SOFTWARE, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Software", NULL },
95 	{ TIFFTAG_DATETIME, 20, 20, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "DateTime", NULL },
96 	{ TIFFTAG_ARTIST, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Artist", NULL },
97 	{ TIFFTAG_HOSTCOMPUTER, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "HostComputer", NULL },
98 	{ TIFFTAG_WHITEPOINT, 2, 2, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "WhitePoint", NULL },
99 	{ TIFFTAG_PRIMARYCHROMATICITIES, 6, 6, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "PrimaryChromaticities", NULL },
100 	{ TIFFTAG_COLORMAP, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_OTHER, TIFF_SETGET_UNDEFINED, FIELD_COLORMAP, 1, 0, "ColorMap", NULL },
101 	{ TIFFTAG_HALFTONEHINTS, 2, 2, TIFF_SHORT, 0, TIFF_SETGET_UINT16_PAIR, TIFF_SETGET_UNDEFINED, FIELD_HALFTONEHINTS, 1, 0, "HalftoneHints", NULL },
102 	{ TIFFTAG_TILEWIDTH, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_TILEDIMENSIONS, 0, 0, "TileWidth", NULL },
103 	{ TIFFTAG_TILELENGTH, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_TILEDIMENSIONS, 0, 0, "TileLength", NULL },
104 	{ TIFFTAG_TILEOFFSETS, -1, 1, TIFF_LONG8, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_STRIPOFFSETS, 0, 0, "TileOffsets", NULL },
105 	{ TIFFTAG_TILEBYTECOUNTS, -1, 1, TIFF_LONG8, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_STRIPBYTECOUNTS, 0, 0, "TileByteCounts", NULL },
106 	{ TIFFTAG_SUBIFD, -1, -1, TIFF_IFD8, 0, TIFF_SETGET_C16_IFD8, TIFF_SETGET_UNDEFINED, FIELD_SUBIFD, 1, 1, "SubIFD", (TIFFFieldArray*) &tiffFieldArray },
107 	{ TIFFTAG_INKSET, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "InkSet", NULL },
108 	{ TIFFTAG_INKNAMES, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_C16_ASCII, TIFF_SETGET_UNDEFINED, FIELD_INKNAMES, 1, 1, "InkNames", NULL },
109 	{ TIFFTAG_NUMBEROFINKS, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "NumberOfInks", NULL },
110 	{ TIFFTAG_DOTRANGE, 2, 2, TIFF_SHORT, 0, TIFF_SETGET_UINT16_PAIR, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "DotRange", NULL },
111 	{ TIFFTAG_TARGETPRINTER, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "TargetPrinter", NULL },
112 	{ TIFFTAG_EXTRASAMPLES, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_C16_UINT16, TIFF_SETGET_UNDEFINED, FIELD_EXTRASAMPLES, 0, 1, "ExtraSamples", NULL },
113 	{ TIFFTAG_SAMPLEFORMAT, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_SAMPLEFORMAT, 0, 0, "SampleFormat", NULL },
114 	{ TIFFTAG_SMINSAMPLEVALUE, -2, -1, TIFF_ANY, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_SMINSAMPLEVALUE, 1, 0, "SMinSampleValue", NULL },
115 	{ TIFFTAG_SMAXSAMPLEVALUE, -2, -1, TIFF_ANY, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_SMAXSAMPLEVALUE, 1, 0, "SMaxSampleValue", NULL },
116 	{ TIFFTAG_CLIPPATH, -1, -3, TIFF_BYTE, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "ClipPath", NULL },
117 	{ TIFFTAG_XCLIPPATHUNITS, 1, 1, TIFF_SLONG, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "XClipPathUnits", NULL },
118 	{ TIFFTAG_XCLIPPATHUNITS, 1, 1, TIFF_SBYTE, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "XClipPathUnits", NULL },
119 	{ TIFFTAG_YCLIPPATHUNITS, 1, 1, TIFF_SLONG, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "YClipPathUnits", NULL },
120 	{ TIFFTAG_YCBCRCOEFFICIENTS, 3, 3, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "YCbCrCoefficients", NULL },
121 	{ TIFFTAG_YCBCRSUBSAMPLING, 2, 2, TIFF_SHORT, 0, TIFF_SETGET_UINT16_PAIR, TIFF_SETGET_UNDEFINED, FIELD_YCBCRSUBSAMPLING, 0, 0, "YCbCrSubsampling", NULL },
122 	{ TIFFTAG_YCBCRPOSITIONING, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_YCBCRPOSITIONING, 0, 0, "YCbCrPositioning", NULL },
123 	{ TIFFTAG_REFERENCEBLACKWHITE, 6, 6, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_REFBLACKWHITE, 1, 0, "ReferenceBlackWhite", NULL },
124 	{ TIFFTAG_XMLPACKET, -3, -3, TIFF_BYTE, 0, TIFF_SETGET_C32_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "XMLPacket", NULL },
125 	/* begin SGI tags */
126 	{ TIFFTAG_MATTEING, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_EXTRASAMPLES, 0, 0, "Matteing", NULL },
127 	{ TIFFTAG_DATATYPE, -2, -1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_SAMPLEFORMAT, 0, 0, "DataType", NULL },
128 	{ TIFFTAG_IMAGEDEPTH, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_IMAGEDEPTH, 0, 0, "ImageDepth", NULL },
129 	{ TIFFTAG_TILEDEPTH, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_TILEDEPTH, 0, 0, "TileDepth", NULL },
130 	/* end SGI tags */
131 	/* begin Pixar tags */
132 	{ TIFFTAG_PIXAR_IMAGEFULLWIDTH, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ImageFullWidth", NULL },
133 	{ TIFFTAG_PIXAR_IMAGEFULLLENGTH, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ImageFullLength", NULL },
134 	{ TIFFTAG_PIXAR_TEXTUREFORMAT, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "TextureFormat", NULL },
135 	{ TIFFTAG_PIXAR_WRAPMODES, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "TextureWrapModes", NULL },
136 	{ TIFFTAG_PIXAR_FOVCOT, 1, 1, TIFF_FLOAT, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FieldOfViewCotangent", NULL },
137 	{ TIFFTAG_PIXAR_MATRIX_WORLDTOSCREEN, 16, 16, TIFF_FLOAT, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "MatrixWorldToScreen", NULL },
138 	{ TIFFTAG_PIXAR_MATRIX_WORLDTOCAMERA, 16, 16, TIFF_FLOAT, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "MatrixWorldToCamera", NULL },
139 	{ TIFFTAG_CFAREPEATPATTERNDIM, 2, 2, TIFF_SHORT, 0, TIFF_SETGET_C0_UINT16, TIFF_SETGET_UNDEFINED,	FIELD_CUSTOM, 0,	0,	"CFARepeatPatternDim", NULL },
140 	{ TIFFTAG_CFAPATTERN,	4, 4,	TIFF_BYTE, 0, TIFF_SETGET_C0_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0,	0,	"CFAPattern" , NULL},
141 	{ TIFFTAG_COPYRIGHT, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Copyright", NULL },
142 	/* end Pixar tags */
143 	{ TIFFTAG_RICHTIFFIPTC, -3, -3, TIFF_LONG, 0, TIFF_SETGET_C32_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "RichTIFFIPTC", NULL },
144 	{ TIFFTAG_PHOTOSHOP, -3, -3, TIFF_BYTE, 0, TIFF_SETGET_C32_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "Photoshop", NULL },
145 	{ TIFFTAG_EXIFIFD, 1, 1, TIFF_IFD8, 0, TIFF_SETGET_IFD8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "EXIFIFDOffset", (TIFFFieldArray*) &exifFieldArray },
146 	{ TIFFTAG_ICCPROFILE, -3, -3, TIFF_UNDEFINED, 0, TIFF_SETGET_C32_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "ICC Profile", NULL },
147 	{ TIFFTAG_GPSIFD, 1, 1, TIFF_IFD8, 0, TIFF_SETGET_IFD8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "GPSIFDOffset", NULL },
148 	{ TIFFTAG_FAXRECVPARAMS, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UINT32, FIELD_CUSTOM, TRUE, FALSE, "FaxRecvParams", NULL },
149 	{ TIFFTAG_FAXSUBADDRESS, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_ASCII, FIELD_CUSTOM, TRUE, FALSE, "FaxSubAddress", NULL },
150 	{ TIFFTAG_FAXRECVTIME, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UINT32, FIELD_CUSTOM, TRUE, FALSE, "FaxRecvTime", NULL },
151 	{ TIFFTAG_FAXDCS, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_ASCII, FIELD_CUSTOM, TRUE, FALSE, "FaxDcs", NULL },
152 	{ TIFFTAG_STONITS, 1, 1, TIFF_DOUBLE, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "StoNits", NULL },
153 	{ TIFFTAG_INTEROPERABILITYIFD, 1, 1, TIFF_IFD8, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "InteroperabilityIFDOffset", NULL },
154 	/* begin DNG tags */
155 	{ TIFFTAG_DNGVERSION, 4, 4, TIFF_BYTE, 0, TIFF_SETGET_C0_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "DNGVersion", NULL },
156 	{ TIFFTAG_DNGBACKWARDVERSION, 4, 4, TIFF_BYTE, 0, TIFF_SETGET_C0_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "DNGBackwardVersion", NULL },
157 	{ TIFFTAG_UNIQUECAMERAMODEL, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "UniqueCameraModel", NULL },
158 	{ TIFFTAG_LOCALIZEDCAMERAMODEL, -1, -1, TIFF_BYTE, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "LocalizedCameraModel", NULL },
159 	{ TIFFTAG_CFAPLANECOLOR, -1, -1, TIFF_BYTE, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "CFAPlaneColor", NULL },
160 	{ TIFFTAG_CFALAYOUT, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "CFALayout", NULL },
161 	{ TIFFTAG_LINEARIZATIONTABLE, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_C16_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "LinearizationTable", NULL },
162 	{ TIFFTAG_BLACKLEVELREPEATDIM, 2, 2, TIFF_SHORT, 0, TIFF_SETGET_C0_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "BlackLevelRepeatDim", NULL },
163 	{ TIFFTAG_BLACKLEVEL, -1, -1, TIFF_RATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "BlackLevel", NULL },
164 	{ TIFFTAG_BLACKLEVELDELTAH, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "BlackLevelDeltaH", NULL },
165 	{ TIFFTAG_BLACKLEVELDELTAV, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "BlackLevelDeltaV", NULL },
166 	{ TIFFTAG_WHITELEVEL, -1, -1, TIFF_LONG, 0, TIFF_SETGET_C16_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "WhiteLevel", NULL },
167 	{ TIFFTAG_DEFAULTSCALE, 2, 2, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "DefaultScale", NULL },
168 	{ TIFFTAG_BESTQUALITYSCALE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "BestQualityScale", NULL },
169 	{ TIFFTAG_DEFAULTCROPORIGIN, 2, 2, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "DefaultCropOrigin", NULL },
170 	{ TIFFTAG_DEFAULTCROPSIZE, 2, 2, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "DefaultCropSize", NULL },
171 	{ TIFFTAG_COLORMATRIX1, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "ColorMatrix1", NULL },
172 	{ TIFFTAG_COLORMATRIX2, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "ColorMatrix2", NULL },
173 	{ TIFFTAG_CAMERACALIBRATION1, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "CameraCalibration1", NULL },
174 	{ TIFFTAG_CAMERACALIBRATION2, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "CameraCalibration2", NULL },
175 	{ TIFFTAG_REDUCTIONMATRIX1, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "ReductionMatrix1", NULL },
176 	{ TIFFTAG_REDUCTIONMATRIX2, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "ReductionMatrix2", NULL },
177 	{ TIFFTAG_ANALOGBALANCE, -1, -1, TIFF_RATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "AnalogBalance", NULL },
178 	{ TIFFTAG_ASSHOTNEUTRAL, -1, -1, TIFF_RATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "AsShotNeutral", NULL },
179 	{ TIFFTAG_ASSHOTWHITEXY, 2, 2, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "AsShotWhiteXY", NULL },
180 	{ TIFFTAG_BASELINEEXPOSURE, 1, 1, TIFF_SRATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "BaselineExposure", NULL },
181 	{ TIFFTAG_BASELINENOISE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "BaselineNoise", NULL },
182 	{ TIFFTAG_BASELINESHARPNESS, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "BaselineSharpness", NULL },
183 	{ TIFFTAG_BAYERGREENSPLIT, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "BayerGreenSplit", NULL },
184 	{ TIFFTAG_LINEARRESPONSELIMIT, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "LinearResponseLimit", NULL },
185 	{ TIFFTAG_CAMERASERIALNUMBER, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "CameraSerialNumber", NULL },
186 	{ TIFFTAG_LENSINFO, 4, 4, TIFF_RATIONAL, 0, TIFF_SETGET_C0_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "LensInfo", NULL },
187 	{ TIFFTAG_CHROMABLURRADIUS, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "ChromaBlurRadius", NULL },
188 	{ TIFFTAG_ANTIALIASSTRENGTH, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "AntiAliasStrength", NULL },
189 	{ TIFFTAG_SHADOWSCALE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "ShadowScale", NULL },
190 	{ TIFFTAG_DNGPRIVATEDATA, -1, -1, TIFF_BYTE, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "DNGPrivateData", NULL },
191 	{ TIFFTAG_MAKERNOTESAFETY, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "MakerNoteSafety", NULL },
192 	{ TIFFTAG_CALIBRATIONILLUMINANT1, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "CalibrationIlluminant1", NULL },
193 	{ TIFFTAG_CALIBRATIONILLUMINANT2, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "CalibrationIlluminant2", NULL },
194 	{ TIFFTAG_RAWDATAUNIQUEID, 16, 16, TIFF_BYTE, 0, TIFF_SETGET_C0_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "RawDataUniqueID", NULL },
195 	{ TIFFTAG_ORIGINALRAWFILENAME, -1, -1, TIFF_BYTE, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "OriginalRawFileName", NULL },
196 	{ TIFFTAG_ORIGINALRAWFILEDATA, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "OriginalRawFileData", NULL },
197 	{ TIFFTAG_ACTIVEAREA, 4, 4, TIFF_LONG, 0, TIFF_SETGET_C0_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "ActiveArea", NULL },
198 	{ TIFFTAG_MASKEDAREAS, -1, -1, TIFF_LONG, 0, TIFF_SETGET_C16_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "MaskedAreas", NULL },
199 	{ TIFFTAG_ASSHOTICCPROFILE, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "AsShotICCProfile", NULL },
200 	{ TIFFTAG_ASSHOTPREPROFILEMATRIX, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "AsShotPreProfileMatrix", NULL },
201 	{ TIFFTAG_CURRENTICCPROFILE, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "CurrentICCProfile", NULL },
202 	{ TIFFTAG_CURRENTPREPROFILEMATRIX, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "CurrentPreProfileMatrix", NULL },
203 	{ TIFFTAG_PERSAMPLE, 0, 0, TIFF_SHORT, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, TRUE, FALSE, "PerSample", NULL},
204 	/* end DNG tags */
205 	/* begin TIFF/FX tags */
206         { TIFFTAG_INDEXED, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "Indexed", NULL },
207         { TIFFTAG_GLOBALPARAMETERSIFD, 1, 1, TIFF_IFD8, 0, TIFF_SETGET_IFD8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "GlobalParametersIFD", NULL },
208         { TIFFTAG_PROFILETYPE, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "ProfileType", NULL },
209         { TIFFTAG_FAXPROFILE, 1, 1, TIFF_BYTE, 0, TIFF_SETGET_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "FaxProfile", NULL },
210         { TIFFTAG_CODINGMETHODS, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "CodingMethods", NULL },
211         { TIFFTAG_VERSIONYEAR, 4, 4, TIFF_BYTE, 0, TIFF_SETGET_C0_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "VersionYear", NULL },
212         { TIFFTAG_MODENUMBER, 1, 1, TIFF_BYTE, 0, TIFF_SETGET_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "ModeNumber", NULL },
213         { TIFFTAG_DECODE, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "Decode", NULL },
214         { TIFFTAG_IMAGEBASECOLOR, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_C16_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "ImageBaseColor", NULL },
215         { TIFFTAG_T82OPTIONS, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "T82Options", NULL },
216         { TIFFTAG_STRIPROWCOUNTS, -1, -1, TIFF_LONG, 0, TIFF_SETGET_C16_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "StripRowCounts", NULL },
217         { TIFFTAG_IMAGELAYER, 2, 2, TIFF_LONG, 0, TIFF_SETGET_C0_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "ImageLayer", NULL },
218 	/* end TIFF/FX tags */
219 	/* begin pseudo tags */
220 };
221 
222 static const TIFFField
223 exifFields[] = {
224 	{ EXIFTAG_EXPOSURETIME, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ExposureTime", NULL },
225 	{ EXIFTAG_FNUMBER, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FNumber", NULL },
226 	{ EXIFTAG_EXPOSUREPROGRAM, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ExposureProgram", NULL },
227 	{ EXIFTAG_SPECTRALSENSITIVITY, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SpectralSensitivity", NULL },
228 	{ EXIFTAG_ISOSPEEDRATINGS, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_C16_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "ISOSpeedRatings", NULL },
229 	{ EXIFTAG_OECF, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "OptoelectricConversionFactor", NULL },
230 	{ EXIFTAG_EXIFVERSION, 4, 4, TIFF_UNDEFINED, 0, TIFF_SETGET_C0_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ExifVersion", NULL },
231 	{ EXIFTAG_DATETIMEORIGINAL, 20, 20, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "DateTimeOriginal", NULL },
232 	{ EXIFTAG_DATETIMEDIGITIZED, 20, 20, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "DateTimeDigitized", NULL },
233 	{ EXIFTAG_COMPONENTSCONFIGURATION, 4, 4, TIFF_UNDEFINED, 0, TIFF_SETGET_C0_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ComponentsConfiguration", NULL },
234 	{ EXIFTAG_COMPRESSEDBITSPERPIXEL, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "CompressedBitsPerPixel", NULL },
235 	{ EXIFTAG_SHUTTERSPEEDVALUE, 1, 1, TIFF_SRATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ShutterSpeedValue", NULL },
236 	{ EXIFTAG_APERTUREVALUE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ApertureValue", NULL },
237 	{ EXIFTAG_BRIGHTNESSVALUE, 1, 1, TIFF_SRATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "BrightnessValue", NULL },
238 	{ EXIFTAG_EXPOSUREBIASVALUE, 1, 1, TIFF_SRATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ExposureBiasValue", NULL },
239 	{ EXIFTAG_MAXAPERTUREVALUE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "MaxApertureValue", NULL },
240 	{ EXIFTAG_SUBJECTDISTANCE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SubjectDistance", NULL },
241 	{ EXIFTAG_METERINGMODE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "MeteringMode", NULL },
242 	{ EXIFTAG_LIGHTSOURCE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "LightSource", NULL },
243 	{ EXIFTAG_FLASH, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Flash", NULL },
244 	{ EXIFTAG_FOCALLENGTH, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FocalLength", NULL },
245 	{ EXIFTAG_SUBJECTAREA, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_C16_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "SubjectArea", NULL },
246 	{ EXIFTAG_MAKERNOTE, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "MakerNote", NULL },
247 	{ EXIFTAG_USERCOMMENT, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "UserComment", NULL },
248 	{ EXIFTAG_SUBSECTIME, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SubSecTime", NULL },
249 	{ EXIFTAG_SUBSECTIMEORIGINAL, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SubSecTimeOriginal", NULL },
250 	{ EXIFTAG_SUBSECTIMEDIGITIZED, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SubSecTimeDigitized", NULL },
251 	{ EXIFTAG_FLASHPIXVERSION, 4, 4, TIFF_UNDEFINED, 0, TIFF_SETGET_C0_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FlashpixVersion", NULL },
252 	{ EXIFTAG_COLORSPACE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ColorSpace", NULL },
253 	{ EXIFTAG_PIXELXDIMENSION, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "PixelXDimension", NULL },
254 	{ EXIFTAG_PIXELYDIMENSION, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "PixelYDimension", NULL },
255 	{ EXIFTAG_RELATEDSOUNDFILE, 13, 13, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "RelatedSoundFile", NULL },
256 	{ EXIFTAG_FLASHENERGY, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FlashEnergy", NULL },
257 	{ EXIFTAG_SPATIALFREQUENCYRESPONSE, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "SpatialFrequencyResponse", NULL },
258 	{ EXIFTAG_FOCALPLANEXRESOLUTION, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FocalPlaneXResolution", NULL },
259 	{ EXIFTAG_FOCALPLANEYRESOLUTION, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FocalPlaneYResolution", NULL },
260 	{ EXIFTAG_FOCALPLANERESOLUTIONUNIT, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FocalPlaneResolutionUnit", NULL },
261 	{ EXIFTAG_SUBJECTLOCATION, 2, 2, TIFF_SHORT, 0, TIFF_SETGET_C0_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SubjectLocation", NULL },
262 	{ EXIFTAG_EXPOSUREINDEX, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ExposureIndex", NULL },
263 	{ EXIFTAG_SENSINGMETHOD, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SensingMethod", NULL },
264 	{ EXIFTAG_FILESOURCE, 1, 1, TIFF_UNDEFINED, 0, TIFF_SETGET_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FileSource", NULL },
265 	{ EXIFTAG_SCENETYPE, 1, 1, TIFF_UNDEFINED, 0, TIFF_SETGET_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SceneType", NULL },
266 	{ EXIFTAG_CFAPATTERN, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "CFAPattern", NULL },
267 	{ EXIFTAG_CUSTOMRENDERED, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "CustomRendered", NULL },
268 	{ EXIFTAG_EXPOSUREMODE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ExposureMode", NULL },
269 	{ EXIFTAG_WHITEBALANCE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "WhiteBalance", NULL },
270 	{ EXIFTAG_DIGITALZOOMRATIO, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "DigitalZoomRatio", NULL },
271 	{ EXIFTAG_FOCALLENGTHIN35MMFILM, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FocalLengthIn35mmFilm", NULL },
272 	{ EXIFTAG_SCENECAPTURETYPE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SceneCaptureType", NULL },
273 	{ EXIFTAG_GAINCONTROL, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "GainControl", NULL },
274 	{ EXIFTAG_CONTRAST, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Contrast", NULL },
275 	{ EXIFTAG_SATURATION, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Saturation", NULL },
276 	{ EXIFTAG_SHARPNESS, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "Sharpness", NULL },
277 	{ EXIFTAG_DEVICESETTINGDESCRIPTION, -1, -1, TIFF_UNDEFINED, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "DeviceSettingDescription", NULL },
278 	{ EXIFTAG_SUBJECTDISTANCERANGE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SubjectDistanceRange", NULL },
279 	{ EXIFTAG_IMAGEUNIQUEID, 33, 33, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ImageUniqueID", NULL }
280 };
281 
282 static const TIFFFieldArray
283 tiffFieldArray = { tfiatImage, 0, TIFFArrayCount(tiffFields), (TIFFField*) tiffFields };
284 static const TIFFFieldArray
285 exifFieldArray = { tfiatExif, 0, TIFFArrayCount(exifFields), (TIFFField*) exifFields };
286 
287 /*
288  *  We have our own local lfind() equivalent to avoid subtle differences
289  *  in types passed to lfind() on different systems.
290  */
291 
292 static void *
td_lfind(const void * key,const void * base,size_t * nmemb,size_t size,int (* compar)(const void *,const void *))293 td_lfind(const void *key, const void *base, size_t *nmemb, size_t size,
294          int(*compar)(const void *, const void *))
295 {
296     char *element, *end;
297 
298     end = (char *)base + *nmemb * size;
299     for (element = (char *)base; element < end; element += size)
300         if (!compar(key, element))		/* key found */
301             return element;
302 
303     return NULL;
304 }
305 
306 const TIFFFieldArray*
_TIFFGetFields(void)307 _TIFFGetFields(void)
308 {
309 	return(&tiffFieldArray);
310 }
311 
312 const TIFFFieldArray*
_TIFFGetExifFields(void)313 _TIFFGetExifFields(void)
314 {
315 	return(&exifFieldArray);
316 }
317 
318 void
_TIFFSetupFields(TIFF * tif,const TIFFFieldArray * fieldarray)319 _TIFFSetupFields(TIFF* tif, const TIFFFieldArray* fieldarray)
320 {
321 	if (tif->tif_fields && tif->tif_nfields > 0) {
322 		uint32 i;
323 
324 		for (i = 0; i < tif->tif_nfields; i++) {
325 			TIFFField *fld = tif->tif_fields[i];
326 			if (fld->field_bit == FIELD_CUSTOM &&
327 				strncmp("Tag ", fld->field_name, 4) == 0) {
328 					_TIFFfree(fld->field_name);
329 					_TIFFfree(fld);
330 				}
331 		}
332 
333 		_TIFFfree(tif->tif_fields);
334 		tif->tif_fields = NULL;
335 		tif->tif_nfields = 0;
336 	}
337 	if (!_TIFFMergeFields(tif, fieldarray->fields, fieldarray->count)) {
338 		TIFFErrorExt(tif->tif_clientdata, "_TIFFSetupFields",
339 			     "Setting up field info failed");
340 	}
341 }
342 
343 static int
tagCompare(const void * a,const void * b)344 tagCompare(const void* a, const void* b)
345 {
346 	const TIFFField* ta = *(const TIFFField**) a;
347 	const TIFFField* tb = *(const TIFFField**) b;
348 	/* NB: be careful of return values for 16-bit platforms */
349 	if (ta->field_tag != tb->field_tag)
350 		return (int)ta->field_tag - (int)tb->field_tag;
351 	else
352 		return (ta->field_type == TIFF_ANY) ?
353 			0 : ((int)tb->field_type - (int)ta->field_type);
354 }
355 
356 static int
tagNameCompare(const void * a,const void * b)357 tagNameCompare(const void* a, const void* b)
358 {
359 	const TIFFField* ta = *(const TIFFField**) a;
360 	const TIFFField* tb = *(const TIFFField**) b;
361 	int ret = strcmp(ta->field_name, tb->field_name);
362 
363 	if (ret)
364 		return ret;
365 	else
366 		return (ta->field_type == TIFF_ANY) ?
367 			0 : ((int)tb->field_type - (int)ta->field_type);
368 }
369 
370 int
_TIFFMergeFields(TIFF * tif,const TIFFField info[],uint32 n)371 _TIFFMergeFields(TIFF* tif, const TIFFField info[], uint32 n)
372 {
373 	static const char module[] = "_TIFFMergeFields";
374 	static const char reason[] = "for fields array";
375 	/* TIFFField** tp; */
376 	uint32 i;
377 
378         tif->tif_foundfield = NULL;
379 
380 	if (tif->tif_fields && tif->tif_nfields > 0) {
381 		tif->tif_fields = (TIFFField**)
382 			_TIFFCheckRealloc(tif, tif->tif_fields,
383 					  (tif->tif_nfields + n),
384 					  sizeof(TIFFField *), reason);
385 	} else {
386 		tif->tif_fields = (TIFFField **)
387 			_TIFFCheckMalloc(tif, n, sizeof(TIFFField *),
388 					 reason);
389 	}
390 	if (!tif->tif_fields) {
391 		TIFFErrorExt(tif->tif_clientdata, module,
392 			     "Failed to allocate fields array");
393 		return 0;
394 	}
395 
396 	/* tp = tif->tif_fields + tif->tif_nfields; */
397 	for (i = 0; i < n; i++) {
398 		const TIFFField *fip =
399 			TIFFFindField(tif, info[i].field_tag, TIFF_ANY);
400 
401                 /* only add definitions that aren't already present */
402 		if (!fip) {
403                         tif->tif_fields[tif->tif_nfields] = (TIFFField *) (info+i);
404                         tif->tif_nfields++;
405                 }
406 	}
407 
408         /* Sort the field info by tag number */
409 	qsort(tif->tif_fields, tif->tif_nfields,
410 	      sizeof(TIFFField *), tagCompare);
411 
412 	return n;
413 }
414 
415 void
_TIFFPrintFieldInfo(TIFF * tif,FILE * fd)416 _TIFFPrintFieldInfo(TIFF* tif, FILE* fd)
417 {
418 	uint32 i;
419 
420 	fprintf(fd, "%s: \n", tif->tif_name);
421 	for (i = 0; i < tif->tif_nfields; i++) {
422 		const TIFFField* fip = tif->tif_fields[i];
423 		fprintf(fd, "field[%2d] %5lu, %2d, %2d, %d, %2d, %5s, %5s, %s\n"
424 			, (int)i
425 			, (unsigned long) fip->field_tag
426 			, fip->field_readcount, fip->field_writecount
427 			, fip->field_type
428 			, fip->field_bit
429 			, fip->field_oktochange ? "TRUE" : "FALSE"
430 			, fip->field_passcount ? "TRUE" : "FALSE"
431 			, fip->field_name
432 		);
433 	}
434 }
435 
436 /*
437  * Return size of TIFFDataType in bytes
438  */
439 int
TIFFDataWidth(TIFFDataType type)440 TIFFDataWidth(TIFFDataType type)
441 {
442 	switch(type)
443 	{
444 		case 0:  /* nothing */
445 		case TIFF_BYTE:
446 		case TIFF_ASCII:
447 		case TIFF_SBYTE:
448 		case TIFF_UNDEFINED:
449 			return 1;
450 		case TIFF_SHORT:
451 		case TIFF_SSHORT:
452 			return 2;
453 		case TIFF_LONG:
454 		case TIFF_SLONG:
455 		case TIFF_FLOAT:
456 		case TIFF_IFD:
457 			return 4;
458 		case TIFF_RATIONAL:
459 		case TIFF_SRATIONAL:
460 		case TIFF_DOUBLE:
461 		case TIFF_LONG8:
462 		case TIFF_SLONG8:
463 		case TIFF_IFD8:
464 			return 8;
465 		default:
466 			return 0; /* will return 0 for unknown types */
467 	}
468 }
469 
470 /*
471  * Return size of TIFFDataType in bytes.
472  *
473  * XXX: We need a separate function to determine the space needed
474  * to store the value. For TIFF_RATIONAL values TIFFDataWidth() returns 8,
475  * but we use 4-byte float to represent rationals.
476  */
477 int
_TIFFDataSize(TIFFDataType type)478 _TIFFDataSize(TIFFDataType type)
479 {
480 	switch (type)
481 	{
482 		case TIFF_BYTE:
483 		case TIFF_SBYTE:
484 		case TIFF_ASCII:
485 		case TIFF_UNDEFINED:
486 		    return 1;
487 		case TIFF_SHORT:
488 		case TIFF_SSHORT:
489 		    return 2;
490 		case TIFF_LONG:
491 		case TIFF_SLONG:
492 		case TIFF_FLOAT:
493 		case TIFF_IFD:
494 		case TIFF_RATIONAL:
495 		case TIFF_SRATIONAL:
496 		    return 4;
497 		case TIFF_DOUBLE:
498 		case TIFF_LONG8:
499 		case TIFF_SLONG8:
500 		case TIFF_IFD8:
501 		    return 8;
502 		default:
503 		    return 0;
504 	}
505 }
506 
507 const TIFFField*
TIFFFindField(TIFF * tif,uint32 tag,TIFFDataType dt)508 TIFFFindField(TIFF* tif, uint32 tag, TIFFDataType dt)
509 {
510 	TIFFField key = {0, 0, 0, TIFF_NOTYPE, 0, 0, 0, 0, 0, 0, NULL, NULL};
511 	TIFFField* pkey = &key;
512 	const TIFFField **ret;
513 	if (tif->tif_foundfield && tif->tif_foundfield->field_tag == tag &&
514 	    (dt == TIFF_ANY || dt == tif->tif_foundfield->field_type))
515 		return tif->tif_foundfield;
516 
517 	/* If we are invoked with no field information, then just return. */
518 	if (!tif->tif_fields)
519 		return NULL;
520 
521 	/* NB: use sorted search (e.g. binary search) */
522 
523 	key.field_tag = tag;
524 	key.field_type = dt;
525 
526 	ret = (const TIFFField **) bsearch(&pkey, tif->tif_fields,
527 					   tif->tif_nfields,
528 					   sizeof(TIFFField *), tagCompare);
529 	return tif->tif_foundfield = (ret ? *ret : NULL);
530 }
531 
532 static const TIFFField*
_TIFFFindFieldByName(TIFF * tif,const char * field_name,TIFFDataType dt)533 _TIFFFindFieldByName(TIFF* tif, const char *field_name, TIFFDataType dt)
534 {
535 	TIFFField key = {0, 0, 0, TIFF_NOTYPE, 0, 0, 0, 0, 0, 0, NULL, NULL};
536 	TIFFField* pkey = &key;
537 	const TIFFField **ret;
538 	if (tif->tif_foundfield
539 	    && streq(tif->tif_foundfield->field_name, field_name)
540 	    && (dt == TIFF_ANY || dt == tif->tif_foundfield->field_type))
541 		return (tif->tif_foundfield);
542 
543 	/* If we are invoked with no field information, then just return. */
544 	if (!tif->tif_fields)
545 		return NULL;
546 
547 	/* NB: use linear search since list is sorted by key#, not name */
548 
549 	key.field_name = (char *)field_name;
550 	key.field_type = dt;
551 
552 	ret = (const TIFFField **)
553             td_lfind(&pkey, tif->tif_fields, &tif->tif_nfields,
554                      sizeof(TIFFField *), tagNameCompare);
555 
556 	return tif->tif_foundfield = (ret ? *ret : NULL);
557 }
558 
559 const TIFFField*
TIFFFieldWithTag(TIFF * tif,uint32 tag)560 TIFFFieldWithTag(TIFF* tif, uint32 tag)
561 {
562 	const TIFFField* fip = TIFFFindField(tif, tag, TIFF_ANY);
563 	if (!fip) {
564 		TIFFErrorExt(tif->tif_clientdata, "TIFFFieldWithTag",
565 			     "Internal error, unknown tag 0x%x",
566 			     (unsigned int) tag);
567 	}
568 	return (fip);
569 }
570 
571 const TIFFField*
TIFFFieldWithName(TIFF * tif,const char * field_name)572 TIFFFieldWithName(TIFF* tif, const char *field_name)
573 {
574 	const TIFFField* fip =
575 		_TIFFFindFieldByName(tif, field_name, TIFF_ANY);
576 	if (!fip) {
577 		TIFFErrorExt(tif->tif_clientdata, "TIFFFieldWithName",
578 			     "Internal error, unknown tag %s", field_name);
579 	}
580 	return (fip);
581 }
582 
583 uint32
TIFFFieldTag(const TIFFField * fip)584 TIFFFieldTag(const TIFFField* fip)
585 {
586 	return fip->field_tag;
587 }
588 
589 const char *
TIFFFieldName(const TIFFField * fip)590 TIFFFieldName(const TIFFField* fip)
591 {
592 	return fip->field_name;
593 }
594 
595 TIFFDataType
TIFFFieldDataType(const TIFFField * fip)596 TIFFFieldDataType(const TIFFField* fip)
597 {
598 	return fip->field_type;
599 }
600 
601 int
TIFFFieldPassCount(const TIFFField * fip)602 TIFFFieldPassCount(const TIFFField* fip)
603 {
604 	return fip->field_passcount;
605 }
606 
607 int
TIFFFieldReadCount(const TIFFField * fip)608 TIFFFieldReadCount(const TIFFField* fip)
609 {
610 	return fip->field_readcount;
611 }
612 
613 int
TIFFFieldWriteCount(const TIFFField * fip)614 TIFFFieldWriteCount(const TIFFField* fip)
615 {
616 	return fip->field_writecount;
617 }
618 
619 const TIFFField*
_TIFFFindOrRegisterField(TIFF * tif,uint32 tag,TIFFDataType dt)620 _TIFFFindOrRegisterField(TIFF *tif, uint32 tag, TIFFDataType dt)
621 
622 {
623 	const TIFFField *fld;
624 
625 	fld = TIFFFindField(tif, tag, dt);
626 	if (fld == NULL) {
627 		fld = _TIFFCreateAnonField(tif, tag, dt);
628 		if (!_TIFFMergeFields(tif, fld, 1))
629 			return NULL;
630 	}
631 
632 	return fld;
633 }
634 
635 TIFFField*
_TIFFCreateAnonField(TIFF * tif,uint32 tag,TIFFDataType field_type)636 _TIFFCreateAnonField(TIFF *tif, uint32 tag, TIFFDataType field_type)
637 {
638 	TIFFField *fld;
639 	(void) tif;
640 
641 	fld = (TIFFField *) _TIFFmalloc(sizeof (TIFFField));
642 	if (fld == NULL)
643 	    return NULL;
644 	_TIFFmemset(fld, 0, sizeof(TIFFField));
645 
646 	fld->field_tag = tag;
647 	fld->field_readcount = TIFF_VARIABLE2;
648 	fld->field_writecount = TIFF_VARIABLE2;
649 	fld->field_type = field_type;
650 	fld->reserved = 0;
651 	switch (field_type)
652 	{
653 		case TIFF_BYTE:
654 		case TIFF_UNDEFINED:
655 			fld->set_field_type = TIFF_SETGET_C32_UINT8;
656 			fld->get_field_type = TIFF_SETGET_C32_UINT8;
657 			break;
658 		case TIFF_ASCII:
659 			fld->set_field_type = TIFF_SETGET_C32_ASCII;
660 			fld->get_field_type = TIFF_SETGET_C32_ASCII;
661 			break;
662 		case TIFF_SHORT:
663 			fld->set_field_type = TIFF_SETGET_C32_UINT16;
664 			fld->get_field_type = TIFF_SETGET_C32_UINT16;
665 			break;
666 		case TIFF_LONG:
667 			fld->set_field_type = TIFF_SETGET_C32_UINT32;
668 			fld->get_field_type = TIFF_SETGET_C32_UINT32;
669 			break;
670 		case TIFF_RATIONAL:
671 		case TIFF_SRATIONAL:
672 		case TIFF_FLOAT:
673 			fld->set_field_type = TIFF_SETGET_C32_FLOAT;
674 			fld->get_field_type = TIFF_SETGET_C32_FLOAT;
675 			break;
676 		case TIFF_SBYTE:
677 			fld->set_field_type = TIFF_SETGET_C32_SINT8;
678 			fld->get_field_type = TIFF_SETGET_C32_SINT8;
679 			break;
680 		case TIFF_SSHORT:
681 			fld->set_field_type = TIFF_SETGET_C32_SINT16;
682 			fld->get_field_type = TIFF_SETGET_C32_SINT16;
683 			break;
684 		case TIFF_SLONG:
685 			fld->set_field_type = TIFF_SETGET_C32_SINT32;
686 			fld->get_field_type = TIFF_SETGET_C32_SINT32;
687 			break;
688 		case TIFF_DOUBLE:
689 			fld->set_field_type = TIFF_SETGET_C32_DOUBLE;
690 			fld->get_field_type = TIFF_SETGET_C32_DOUBLE;
691 			break;
692 		case TIFF_IFD:
693 		case TIFF_IFD8:
694 			fld->set_field_type = TIFF_SETGET_C32_IFD8;
695 			fld->get_field_type = TIFF_SETGET_C32_IFD8;
696 			break;
697 		case TIFF_LONG8:
698 			fld->set_field_type = TIFF_SETGET_C32_UINT64;
699 			fld->get_field_type = TIFF_SETGET_C32_UINT64;
700 			break;
701 		case TIFF_SLONG8:
702 			fld->set_field_type = TIFF_SETGET_C32_SINT64;
703 			fld->get_field_type = TIFF_SETGET_C32_SINT64;
704 			break;
705 		default:
706 			fld->set_field_type = TIFF_SETGET_UNDEFINED;
707 			fld->get_field_type = TIFF_SETGET_UNDEFINED;
708 			break;
709 	}
710 	fld->field_bit = FIELD_CUSTOM;
711 	fld->field_oktochange = TRUE;
712 	fld->field_passcount = TRUE;
713 	fld->field_name = (char *) _TIFFmalloc(32);
714 	if (fld->field_name == NULL) {
715 	    _TIFFfree(fld);
716 	    return NULL;
717 	}
718 	fld->field_subfields = NULL;
719 
720 	/*
721 	 * note that this name is a special sign to TIFFClose() and
722 	 * _TIFFSetupFields() to free the field
723 	 */
724 	(void) snprintf(fld->field_name, 32, "Tag %d", (int) tag);
725 
726 	return fld;
727 }
728 
729 /****************************************************************************
730  *               O B S O L E T E D    I N T E R F A C E S
731  *
732  * Don't use this stuff in your applications, it may be removed in the future
733  * libtiff versions.
734  ****************************************************************************/
735 
736 static TIFFSetGetFieldType
_TIFFSetGetType(TIFFDataType type,short count,unsigned char passcount)737 _TIFFSetGetType(TIFFDataType type, short count, unsigned char passcount)
738 {
739 	if (type == TIFF_ASCII && count == TIFF_VARIABLE && passcount == 0)
740 		return TIFF_SETGET_ASCII;
741 
742 	else if (count == 1 && passcount == 0) {
743 		switch (type)
744 		{
745 			case TIFF_BYTE:
746 			case TIFF_UNDEFINED:
747 				return TIFF_SETGET_UINT8;
748 			case TIFF_ASCII:
749 				return TIFF_SETGET_ASCII;
750 			case TIFF_SHORT:
751 				return TIFF_SETGET_UINT16;
752 			case TIFF_LONG:
753 				return TIFF_SETGET_UINT32;
754 			case TIFF_RATIONAL:
755 			case TIFF_SRATIONAL:
756 			case TIFF_FLOAT:
757 				return TIFF_SETGET_FLOAT;
758 			case TIFF_SBYTE:
759 				return TIFF_SETGET_SINT8;
760 			case TIFF_SSHORT:
761 				return TIFF_SETGET_SINT16;
762 			case TIFF_SLONG:
763 				return TIFF_SETGET_SINT32;
764 			case TIFF_DOUBLE:
765 				return TIFF_SETGET_DOUBLE;
766 			case TIFF_IFD:
767 			case TIFF_IFD8:
768 				return TIFF_SETGET_IFD8;
769 			case TIFF_LONG8:
770 				return TIFF_SETGET_UINT64;
771 			case TIFF_SLONG8:
772 				return TIFF_SETGET_SINT64;
773 			default:
774 				return TIFF_SETGET_UNDEFINED;
775 		}
776 	}
777 
778 	else if (count >= 1 && passcount == 0) {
779 		switch (type)
780 		{
781 			case TIFF_BYTE:
782 			case TIFF_UNDEFINED:
783 				return TIFF_SETGET_C0_UINT8;
784 			case TIFF_ASCII:
785 				return TIFF_SETGET_C0_ASCII;
786 			case TIFF_SHORT:
787 				return TIFF_SETGET_C0_UINT16;
788 			case TIFF_LONG:
789 				return TIFF_SETGET_C0_UINT32;
790 			case TIFF_RATIONAL:
791 			case TIFF_SRATIONAL:
792 			case TIFF_FLOAT:
793 				return TIFF_SETGET_C0_FLOAT;
794 			case TIFF_SBYTE:
795 				return TIFF_SETGET_C0_SINT8;
796 			case TIFF_SSHORT:
797 				return TIFF_SETGET_C0_SINT16;
798 			case TIFF_SLONG:
799 				return TIFF_SETGET_C0_SINT32;
800 			case TIFF_DOUBLE:
801 				return TIFF_SETGET_C0_DOUBLE;
802 			case TIFF_IFD:
803 			case TIFF_IFD8:
804 				return TIFF_SETGET_C0_IFD8;
805 			case TIFF_LONG8:
806 				return TIFF_SETGET_C0_UINT64;
807 			case TIFF_SLONG8:
808 				return TIFF_SETGET_C0_SINT64;
809 			default:
810 				return TIFF_SETGET_UNDEFINED;
811 		}
812 	}
813 
814 	else if (count == TIFF_VARIABLE && passcount == 1) {
815 		switch (type)
816 		{
817 			case TIFF_BYTE:
818 			case TIFF_UNDEFINED:
819 				return TIFF_SETGET_C16_UINT8;
820 			case TIFF_ASCII:
821 				return TIFF_SETGET_C16_ASCII;
822 			case TIFF_SHORT:
823 				return TIFF_SETGET_C16_UINT16;
824 			case TIFF_LONG:
825 				return TIFF_SETGET_C16_UINT32;
826 			case TIFF_RATIONAL:
827 			case TIFF_SRATIONAL:
828 			case TIFF_FLOAT:
829 				return TIFF_SETGET_C16_FLOAT;
830 			case TIFF_SBYTE:
831 				return TIFF_SETGET_C16_SINT8;
832 			case TIFF_SSHORT:
833 				return TIFF_SETGET_C16_SINT16;
834 			case TIFF_SLONG:
835 				return TIFF_SETGET_C16_SINT32;
836 			case TIFF_DOUBLE:
837 				return TIFF_SETGET_C16_DOUBLE;
838 			case TIFF_IFD:
839 			case TIFF_IFD8:
840 				return TIFF_SETGET_C16_IFD8;
841 			case TIFF_LONG8:
842 				return TIFF_SETGET_C16_UINT64;
843 			case TIFF_SLONG8:
844 				return TIFF_SETGET_C16_SINT64;
845 			default:
846 				return TIFF_SETGET_UNDEFINED;
847 		}
848 	}
849 
850 	else if (count == TIFF_VARIABLE2 && passcount == 1) {
851 		switch (type)
852 		{
853 			case TIFF_BYTE:
854 			case TIFF_UNDEFINED:
855 				return TIFF_SETGET_C32_UINT8;
856 			case TIFF_ASCII:
857 				return TIFF_SETGET_C32_ASCII;
858 			case TIFF_SHORT:
859 				return TIFF_SETGET_C32_UINT16;
860 			case TIFF_LONG:
861 				return TIFF_SETGET_C32_UINT32;
862 			case TIFF_RATIONAL:
863 			case TIFF_SRATIONAL:
864 			case TIFF_FLOAT:
865 				return TIFF_SETGET_C32_FLOAT;
866 			case TIFF_SBYTE:
867 				return TIFF_SETGET_C32_SINT8;
868 			case TIFF_SSHORT:
869 				return TIFF_SETGET_C32_SINT16;
870 			case TIFF_SLONG:
871 				return TIFF_SETGET_C32_SINT32;
872 			case TIFF_DOUBLE:
873 				return TIFF_SETGET_C32_DOUBLE;
874 			case TIFF_IFD:
875 			case TIFF_IFD8:
876 				return TIFF_SETGET_C32_IFD8;
877 			case TIFF_LONG8:
878 				return TIFF_SETGET_C32_UINT64;
879 			case TIFF_SLONG8:
880 				return TIFF_SETGET_C32_SINT64;
881 			default:
882 				return TIFF_SETGET_UNDEFINED;
883 		}
884 	}
885 
886 	return TIFF_SETGET_UNDEFINED;
887 }
888 
889 int
TIFFMergeFieldInfo(TIFF * tif,const TIFFFieldInfo info[],uint32 n)890 TIFFMergeFieldInfo(TIFF* tif, const TIFFFieldInfo info[], uint32 n)
891 {
892 	static const char module[] = "TIFFMergeFieldInfo";
893 	static const char reason[] = "for fields array";
894 	TIFFField *tp;
895 	size_t nfields;
896 	uint32 i;
897 
898 	if (tif->tif_nfieldscompat > 0) {
899 		tif->tif_fieldscompat = (TIFFFieldArray *)
900 			_TIFFCheckRealloc(tif, tif->tif_fieldscompat,
901 					  tif->tif_nfieldscompat + 1,
902 					  sizeof(TIFFFieldArray), reason);
903 	} else {
904 		tif->tif_fieldscompat = (TIFFFieldArray *)
905 			_TIFFCheckMalloc(tif, 1, sizeof(TIFFFieldArray),
906 					 reason);
907 	}
908 	if (!tif->tif_fieldscompat) {
909 		TIFFErrorExt(tif->tif_clientdata, module,
910 			     "Failed to allocate fields array");
911 		return -1;
912 	}
913 	nfields = tif->tif_nfieldscompat++;
914 
915 	tif->tif_fieldscompat[nfields].type = tfiatOther;
916 	tif->tif_fieldscompat[nfields].allocated_size = n;
917 	tif->tif_fieldscompat[nfields].count = n;
918 	tif->tif_fieldscompat[nfields].fields =
919 		(TIFFField *)_TIFFCheckMalloc(tif, n, sizeof(TIFFField),
920 					      reason);
921 	if (!tif->tif_fieldscompat[nfields].fields) {
922 		TIFFErrorExt(tif->tif_clientdata, module,
923 			     "Failed to allocate fields array");
924 		return -1;
925 	}
926 
927 	tp = tif->tif_fieldscompat[nfields].fields;
928 	for (i = 0; i < n; i++) {
929 		tp->field_tag = info[i].field_tag;
930 		tp->field_readcount = info[i].field_readcount;
931 		tp->field_writecount = info[i].field_writecount;
932 		tp->field_type = info[i].field_type;
933 		tp->reserved = 0;
934 		tp->set_field_type =
935 		     _TIFFSetGetType(info[i].field_type,
936 				info[i].field_readcount,
937 				info[i].field_passcount);
938 		tp->get_field_type =
939 		     _TIFFSetGetType(info[i].field_type,
940 				info[i].field_readcount,
941 				info[i].field_passcount);
942 		tp->field_bit = info[i].field_bit;
943 		tp->field_oktochange = info[i].field_oktochange;
944 		tp->field_passcount = info[i].field_passcount;
945 		tp->field_name = info[i].field_name;
946 		tp->field_subfields = NULL;
947 		tp++;
948 	}
949 
950 	if (!_TIFFMergeFields(tif, tif->tif_fieldscompat[nfields].fields, n)) {
951 		TIFFErrorExt(tif->tif_clientdata, module,
952 			     "Setting up field info failed");
953 		return -1;
954 	}
955 
956 	return 0;
957 }
958 
959 /* vim: set ts=8 sts=8 sw=8 noet: */
960 
961 /*
962  * Local Variables:
963  * mode: c
964  * c-basic-offset: 8
965  * fill-column: 78
966  * End:
967  */
968