1 | /* $Header: /afs/dev.mit.edu/source/repository/third/tiff/libtiff/tif_dirinfo.c,v 1.1.1.1 2002-12-26 02:38:53 ghudson 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 | * NB: NB: THIS ARRAY IS ASSUMED TO BE SORTED BY TAG. |
---|
37 | * If a tag can have both LONG and SHORT types |
---|
38 | * then the LONG must be placed before the SHORT for |
---|
39 | * writing to work properly. |
---|
40 | * |
---|
41 | * NOTE: The second field (field_readcount) and third field (field_writecount) |
---|
42 | * sometimes use the values TIFF_VARIABLE (-1), TIFF_VARIABLE2 (-3) |
---|
43 | * and TIFFTAG_SPP (-2). The macros should be used but would throw off |
---|
44 | * the formatting of the code, so please interprete the -1, -2 and -3 |
---|
45 | * values accordingly. |
---|
46 | */ |
---|
47 | #ifndef VMS |
---|
48 | static |
---|
49 | #endif |
---|
50 | const TIFFFieldInfo tiffFieldInfo[] = { |
---|
51 | { TIFFTAG_SUBFILETYPE, 1, 1, TIFF_LONG, FIELD_SUBFILETYPE, |
---|
52 | TRUE, FALSE, "SubfileType" }, |
---|
53 | /* XXX SHORT for compatibility w/ old versions of the library */ |
---|
54 | { TIFFTAG_SUBFILETYPE, 1, 1, TIFF_SHORT, FIELD_SUBFILETYPE, |
---|
55 | TRUE, FALSE, "SubfileType" }, |
---|
56 | { TIFFTAG_OSUBFILETYPE, 1, 1, TIFF_SHORT, FIELD_SUBFILETYPE, |
---|
57 | TRUE, FALSE, "OldSubfileType" }, |
---|
58 | { TIFFTAG_IMAGEWIDTH, 1, 1, TIFF_LONG, FIELD_IMAGEDIMENSIONS, |
---|
59 | FALSE, FALSE, "ImageWidth" }, |
---|
60 | { TIFFTAG_IMAGEWIDTH, 1, 1, TIFF_SHORT, FIELD_IMAGEDIMENSIONS, |
---|
61 | FALSE, FALSE, "ImageWidth" }, |
---|
62 | { TIFFTAG_IMAGELENGTH, 1, 1, TIFF_LONG, FIELD_IMAGEDIMENSIONS, |
---|
63 | TRUE, FALSE, "ImageLength" }, |
---|
64 | { TIFFTAG_IMAGELENGTH, 1, 1, TIFF_SHORT, FIELD_IMAGEDIMENSIONS, |
---|
65 | TRUE, FALSE, "ImageLength" }, |
---|
66 | { TIFFTAG_BITSPERSAMPLE, -1,-1, TIFF_SHORT, FIELD_BITSPERSAMPLE, |
---|
67 | FALSE, FALSE, "BitsPerSample" }, |
---|
68 | { TIFFTAG_COMPRESSION, -1, 1, TIFF_SHORT, FIELD_COMPRESSION, |
---|
69 | FALSE, FALSE, "Compression" }, |
---|
70 | { TIFFTAG_PHOTOMETRIC, 1, 1, TIFF_SHORT, FIELD_PHOTOMETRIC, |
---|
71 | FALSE, FALSE, "PhotometricInterpretation" }, |
---|
72 | { TIFFTAG_THRESHHOLDING, 1, 1, TIFF_SHORT, FIELD_THRESHHOLDING, |
---|
73 | TRUE, FALSE, "Threshholding" }, |
---|
74 | { TIFFTAG_CELLWIDTH, 1, 1, TIFF_SHORT, FIELD_IGNORE, |
---|
75 | TRUE, FALSE, "CellWidth" }, |
---|
76 | { TIFFTAG_CELLLENGTH, 1, 1, TIFF_SHORT, FIELD_IGNORE, |
---|
77 | TRUE, FALSE, "CellLength" }, |
---|
78 | { TIFFTAG_FILLORDER, 1, 1, TIFF_SHORT, FIELD_FILLORDER, |
---|
79 | FALSE, FALSE, "FillOrder" }, |
---|
80 | { TIFFTAG_DOCUMENTNAME, -1,-1, TIFF_ASCII, FIELD_DOCUMENTNAME, |
---|
81 | TRUE, FALSE, "DocumentName" }, |
---|
82 | { TIFFTAG_IMAGEDESCRIPTION, -1,-1, TIFF_ASCII, FIELD_IMAGEDESCRIPTION, |
---|
83 | TRUE, FALSE, "ImageDescription" }, |
---|
84 | { TIFFTAG_MAKE, -1,-1, TIFF_ASCII, FIELD_MAKE, |
---|
85 | TRUE, FALSE, "Make" }, |
---|
86 | { TIFFTAG_MODEL, -1,-1, TIFF_ASCII, FIELD_MODEL, |
---|
87 | TRUE, FALSE, "Model" }, |
---|
88 | { TIFFTAG_STRIPOFFSETS, -1,-1, TIFF_LONG, FIELD_STRIPOFFSETS, |
---|
89 | FALSE, FALSE, "StripOffsets" }, |
---|
90 | { TIFFTAG_STRIPOFFSETS, -1,-1, TIFF_SHORT, FIELD_STRIPOFFSETS, |
---|
91 | FALSE, FALSE, "StripOffsets" }, |
---|
92 | { TIFFTAG_ORIENTATION, 1, 1, TIFF_SHORT, FIELD_ORIENTATION, |
---|
93 | FALSE, FALSE, "Orientation" }, |
---|
94 | { TIFFTAG_SAMPLESPERPIXEL, 1, 1, TIFF_SHORT, FIELD_SAMPLESPERPIXEL, |
---|
95 | FALSE, FALSE, "SamplesPerPixel" }, |
---|
96 | { TIFFTAG_ROWSPERSTRIP, 1, 1, TIFF_LONG, FIELD_ROWSPERSTRIP, |
---|
97 | FALSE, FALSE, "RowsPerStrip" }, |
---|
98 | { TIFFTAG_ROWSPERSTRIP, 1, 1, TIFF_SHORT, FIELD_ROWSPERSTRIP, |
---|
99 | FALSE, FALSE, "RowsPerStrip" }, |
---|
100 | { TIFFTAG_STRIPBYTECOUNTS, -1,-1, TIFF_LONG, FIELD_STRIPBYTECOUNTS, |
---|
101 | FALSE, FALSE, "StripByteCounts" }, |
---|
102 | { TIFFTAG_STRIPBYTECOUNTS, -1,-1, TIFF_SHORT, FIELD_STRIPBYTECOUNTS, |
---|
103 | FALSE, FALSE, "StripByteCounts" }, |
---|
104 | { TIFFTAG_MINSAMPLEVALUE, -2,-1, TIFF_SHORT, FIELD_MINSAMPLEVALUE, |
---|
105 | TRUE, FALSE, "MinSampleValue" }, |
---|
106 | { TIFFTAG_MAXSAMPLEVALUE, -2,-1, TIFF_SHORT, FIELD_MAXSAMPLEVALUE, |
---|
107 | TRUE, FALSE, "MaxSampleValue" }, |
---|
108 | { TIFFTAG_XRESOLUTION, 1, 1, TIFF_RATIONAL, FIELD_RESOLUTION, |
---|
109 | FALSE, FALSE, "XResolution" }, |
---|
110 | { TIFFTAG_YRESOLUTION, 1, 1, TIFF_RATIONAL, FIELD_RESOLUTION, |
---|
111 | FALSE, FALSE, "YResolution" }, |
---|
112 | { TIFFTAG_PLANARCONFIG, 1, 1, TIFF_SHORT, FIELD_PLANARCONFIG, |
---|
113 | FALSE, FALSE, "PlanarConfiguration" }, |
---|
114 | { TIFFTAG_PAGENAME, -1,-1, TIFF_ASCII, FIELD_PAGENAME, |
---|
115 | TRUE, FALSE, "PageName" }, |
---|
116 | { TIFFTAG_XPOSITION, 1, 1, TIFF_RATIONAL, FIELD_POSITION, |
---|
117 | TRUE, FALSE, "XPosition" }, |
---|
118 | { TIFFTAG_YPOSITION, 1, 1, TIFF_RATIONAL, FIELD_POSITION, |
---|
119 | TRUE, FALSE, "YPosition" }, |
---|
120 | { TIFFTAG_FREEOFFSETS, -1,-1, TIFF_LONG, FIELD_IGNORE, |
---|
121 | FALSE, FALSE, "FreeOffsets" }, |
---|
122 | { TIFFTAG_FREEBYTECOUNTS, -1,-1, TIFF_LONG, FIELD_IGNORE, |
---|
123 | FALSE, FALSE, "FreeByteCounts" }, |
---|
124 | { TIFFTAG_GRAYRESPONSEUNIT, 1, 1, TIFF_SHORT, FIELD_IGNORE, |
---|
125 | TRUE, FALSE, "GrayResponseUnit" }, |
---|
126 | { TIFFTAG_GRAYRESPONSECURVE,-1,-1, TIFF_SHORT, FIELD_IGNORE, |
---|
127 | TRUE, FALSE, "GrayResponseCurve" }, |
---|
128 | { TIFFTAG_RESOLUTIONUNIT, 1, 1, TIFF_SHORT, FIELD_RESOLUTIONUNIT, |
---|
129 | FALSE, FALSE, "ResolutionUnit" }, |
---|
130 | { TIFFTAG_PAGENUMBER, 2, 2, TIFF_SHORT, FIELD_PAGENUMBER, |
---|
131 | TRUE, FALSE, "PageNumber" }, |
---|
132 | { TIFFTAG_COLORRESPONSEUNIT, 1, 1, TIFF_SHORT, FIELD_IGNORE, |
---|
133 | TRUE, FALSE, "ColorResponseUnit" }, |
---|
134 | #ifdef COLORIMETRY_SUPPORT |
---|
135 | { TIFFTAG_TRANSFERFUNCTION, -1,-1, TIFF_SHORT, FIELD_TRANSFERFUNCTION, |
---|
136 | TRUE, FALSE, "TransferFunction" }, |
---|
137 | #endif |
---|
138 | { TIFFTAG_SOFTWARE, -1,-1, TIFF_ASCII, FIELD_SOFTWARE, |
---|
139 | TRUE, FALSE, "Software" }, |
---|
140 | { TIFFTAG_DATETIME, 20,20, TIFF_ASCII, FIELD_DATETIME, |
---|
141 | TRUE, FALSE, "DateTime" }, |
---|
142 | { TIFFTAG_ARTIST, -1,-1, TIFF_ASCII, FIELD_ARTIST, |
---|
143 | TRUE, FALSE, "Artist" }, |
---|
144 | { TIFFTAG_HOSTCOMPUTER, -1,-1, TIFF_ASCII, FIELD_HOSTCOMPUTER, |
---|
145 | TRUE, FALSE, "HostComputer" }, |
---|
146 | #ifdef COLORIMETRY_SUPPORT |
---|
147 | { TIFFTAG_WHITEPOINT, 2, 2, TIFF_RATIONAL,FIELD_WHITEPOINT, |
---|
148 | TRUE, FALSE, "WhitePoint" }, |
---|
149 | { TIFFTAG_PRIMARYCHROMATICITIES,6,6,TIFF_RATIONAL,FIELD_PRIMARYCHROMAS, |
---|
150 | TRUE, FALSE, "PrimaryChromaticities" }, |
---|
151 | #endif |
---|
152 | { TIFFTAG_COLORMAP, -1,-1, TIFF_SHORT, FIELD_COLORMAP, |
---|
153 | TRUE, FALSE, "ColorMap" }, |
---|
154 | { TIFFTAG_HALFTONEHINTS, 2, 2, TIFF_SHORT, FIELD_HALFTONEHINTS, |
---|
155 | TRUE, FALSE, "HalftoneHints" }, |
---|
156 | { TIFFTAG_TILEWIDTH, 1, 1, TIFF_LONG, FIELD_TILEDIMENSIONS, |
---|
157 | FALSE, FALSE, "TileWidth" }, |
---|
158 | { TIFFTAG_TILEWIDTH, 1, 1, TIFF_SHORT, FIELD_TILEDIMENSIONS, |
---|
159 | FALSE, FALSE, "TileWidth" }, |
---|
160 | { TIFFTAG_TILELENGTH, 1, 1, TIFF_LONG, FIELD_TILEDIMENSIONS, |
---|
161 | FALSE, FALSE, "TileLength" }, |
---|
162 | { TIFFTAG_TILELENGTH, 1, 1, TIFF_SHORT, FIELD_TILEDIMENSIONS, |
---|
163 | FALSE, FALSE, "TileLength" }, |
---|
164 | { TIFFTAG_TILEOFFSETS, -1, 1, TIFF_LONG, FIELD_STRIPOFFSETS, |
---|
165 | FALSE, FALSE, "TileOffsets" }, |
---|
166 | { TIFFTAG_TILEBYTECOUNTS, -1, 1, TIFF_LONG, FIELD_STRIPBYTECOUNTS, |
---|
167 | FALSE, FALSE, "TileByteCounts" }, |
---|
168 | { TIFFTAG_TILEBYTECOUNTS, -1, 1, TIFF_SHORT, FIELD_STRIPBYTECOUNTS, |
---|
169 | FALSE, FALSE, "TileByteCounts" }, |
---|
170 | #ifdef TIFFTAG_SUBIFD |
---|
171 | { TIFFTAG_SUBIFD, -1,-1, TIFF_LONG, FIELD_SUBIFD, |
---|
172 | TRUE, TRUE, "SubIFD" }, |
---|
173 | #endif |
---|
174 | #ifdef CMYK_SUPPORT /* 6.0 CMYK tags */ |
---|
175 | { TIFFTAG_INKSET, 1, 1, TIFF_SHORT, FIELD_INKSET, |
---|
176 | FALSE, FALSE, "InkSet" }, |
---|
177 | { TIFFTAG_INKNAMES, -1,-1, TIFF_ASCII, FIELD_INKNAMES, |
---|
178 | TRUE, TRUE, "InkNames" }, |
---|
179 | { TIFFTAG_NUMBEROFINKS, 1, 1, TIFF_SHORT, FIELD_NUMBEROFINKS, |
---|
180 | TRUE, FALSE, "NumberOfInks" }, |
---|
181 | { TIFFTAG_DOTRANGE, 2, 2, TIFF_SHORT, FIELD_DOTRANGE, |
---|
182 | FALSE, FALSE, "DotRange" }, |
---|
183 | { TIFFTAG_DOTRANGE, 2, 2, TIFF_BYTE, FIELD_DOTRANGE, |
---|
184 | FALSE, FALSE, "DotRange" }, |
---|
185 | { TIFFTAG_TARGETPRINTER, -1,-1, TIFF_ASCII, FIELD_TARGETPRINTER, |
---|
186 | TRUE, FALSE, "TargetPrinter" }, |
---|
187 | #endif |
---|
188 | { TIFFTAG_EXTRASAMPLES, -1,-1, TIFF_SHORT, FIELD_EXTRASAMPLES, |
---|
189 | FALSE, FALSE, "ExtraSamples" }, |
---|
190 | /* XXX for bogus Adobe Photoshop v2.5 files */ |
---|
191 | { TIFFTAG_EXTRASAMPLES, -1,-1, TIFF_BYTE, FIELD_EXTRASAMPLES, |
---|
192 | FALSE, FALSE, "ExtraSamples" }, |
---|
193 | { TIFFTAG_SAMPLEFORMAT, -1,-1, TIFF_SHORT, FIELD_SAMPLEFORMAT, |
---|
194 | FALSE, FALSE, "SampleFormat" }, |
---|
195 | { TIFFTAG_SMINSAMPLEVALUE, -2,-1, TIFF_ANY, FIELD_SMINSAMPLEVALUE, |
---|
196 | TRUE, FALSE, "SMinSampleValue" }, |
---|
197 | { TIFFTAG_SMAXSAMPLEVALUE, -2,-1, TIFF_ANY, FIELD_SMAXSAMPLEVALUE, |
---|
198 | TRUE, FALSE, "SMaxSampleValue" }, |
---|
199 | #ifdef YCBCR_SUPPORT /* 6.0 YCbCr tags */ |
---|
200 | { TIFFTAG_YCBCRCOEFFICIENTS, 3, 3, TIFF_RATIONAL, FIELD_YCBCRCOEFFICIENTS, |
---|
201 | FALSE, FALSE, "YCbCrCoefficients" }, |
---|
202 | { TIFFTAG_YCBCRSUBSAMPLING, 2, 2, TIFF_SHORT, FIELD_YCBCRSUBSAMPLING, |
---|
203 | FALSE, FALSE, "YCbCrSubsampling" }, |
---|
204 | { TIFFTAG_YCBCRPOSITIONING, 1, 1, TIFF_SHORT, FIELD_YCBCRPOSITIONING, |
---|
205 | FALSE, FALSE, "YCbCrPositioning" }, |
---|
206 | #endif |
---|
207 | #ifdef COLORIMETRY_SUPPORT |
---|
208 | { TIFFTAG_REFERENCEBLACKWHITE,6,6,TIFF_RATIONAL, FIELD_REFBLACKWHITE, |
---|
209 | TRUE, FALSE, "ReferenceBlackWhite" }, |
---|
210 | /* XXX temporarily accept LONG for backwards compatibility */ |
---|
211 | { TIFFTAG_REFERENCEBLACKWHITE,6,6,TIFF_LONG, FIELD_REFBLACKWHITE, |
---|
212 | TRUE, FALSE, "ReferenceBlackWhite" }, |
---|
213 | #endif |
---|
214 | /* begin SGI tags */ |
---|
215 | { TIFFTAG_MATTEING, 1, 1, TIFF_SHORT, FIELD_EXTRASAMPLES, |
---|
216 | FALSE, FALSE, "Matteing" }, |
---|
217 | { TIFFTAG_DATATYPE, -2,-1, TIFF_SHORT, FIELD_SAMPLEFORMAT, |
---|
218 | FALSE, FALSE, "DataType" }, |
---|
219 | { TIFFTAG_IMAGEDEPTH, 1, 1, TIFF_LONG, FIELD_IMAGEDEPTH, |
---|
220 | FALSE, FALSE, "ImageDepth" }, |
---|
221 | { TIFFTAG_IMAGEDEPTH, 1, 1, TIFF_SHORT, FIELD_IMAGEDEPTH, |
---|
222 | FALSE, FALSE, "ImageDepth" }, |
---|
223 | { TIFFTAG_TILEDEPTH, 1, 1, TIFF_LONG, FIELD_TILEDEPTH, |
---|
224 | FALSE, FALSE, "TileDepth" }, |
---|
225 | { TIFFTAG_TILEDEPTH, 1, 1, TIFF_SHORT, FIELD_TILEDEPTH, |
---|
226 | FALSE, FALSE, "TileDepth" }, |
---|
227 | /* end SGI tags */ |
---|
228 | /* begin Pixar tags */ |
---|
229 | { TIFFTAG_PIXAR_IMAGEFULLWIDTH, 1, 1, TIFF_LONG, FIELD_IMAGEFULLWIDTH, |
---|
230 | TRUE, FALSE, "ImageFullWidth" }, |
---|
231 | { TIFFTAG_PIXAR_IMAGEFULLLENGTH, 1, 1, TIFF_LONG, FIELD_IMAGEFULLLENGTH, |
---|
232 | TRUE, FALSE, "ImageFullLength" }, |
---|
233 | { TIFFTAG_PIXAR_TEXTUREFORMAT, -1,-1, TIFF_ASCII, FIELD_TEXTUREFORMAT, |
---|
234 | TRUE, FALSE, "TextureFormat" }, |
---|
235 | { TIFFTAG_PIXAR_WRAPMODES, -1,-1, TIFF_ASCII, FIELD_WRAPMODES, |
---|
236 | TRUE, FALSE, "TextureWrapModes" }, |
---|
237 | { TIFFTAG_PIXAR_FOVCOT, 1, 1, TIFF_FLOAT, FIELD_FOVCOT, |
---|
238 | TRUE, FALSE, "FieldOfViewCotan" }, |
---|
239 | { TIFFTAG_PIXAR_MATRIX_WORLDTOSCREEN, 16,16, TIFF_FLOAT, |
---|
240 | FIELD_MATRIX_WORLDTOSCREEN, TRUE, FALSE, "MatrixWorldToScreen" }, |
---|
241 | { TIFFTAG_PIXAR_MATRIX_WORLDTOCAMERA, 16,16, TIFF_FLOAT, |
---|
242 | FIELD_MATRIX_WORLDTOCAMERA, TRUE, FALSE, "MatrixWorldToCamera" }, |
---|
243 | { TIFFTAG_COPYRIGHT, -1,-1, TIFF_ASCII, FIELD_COPYRIGHT, |
---|
244 | TRUE, FALSE, "Copyright" }, |
---|
245 | /* end Pixar tags */ |
---|
246 | #ifdef IPTC_SUPPORT |
---|
247 | #ifdef PHOTOSHOP_SUPPORT |
---|
248 | { TIFFTAG_RICHTIFFIPTC, -1,-1, TIFF_LONG, FIELD_RICHTIFFIPTC, |
---|
249 | FALSE, TRUE, "RichTIFFIPTC" }, |
---|
250 | #else |
---|
251 | { TIFFTAG_RICHTIFFIPTC, -1,-3, TIFF_UNDEFINED, FIELD_RICHTIFFIPTC, |
---|
252 | FALSE, TRUE, "RichTIFFIPTC" }, |
---|
253 | #endif |
---|
254 | #endif |
---|
255 | #ifdef PHOTOSHOP_SUPPORT |
---|
256 | { TIFFTAG_PHOTOSHOP, -1,-3, TIFF_BYTE, FIELD_PHOTOSHOP, |
---|
257 | FALSE, TRUE, "Photoshop" }, |
---|
258 | #endif |
---|
259 | #ifdef ICC_SUPPORT |
---|
260 | { TIFFTAG_ICCPROFILE, -1,-3, TIFF_UNDEFINED, FIELD_ICCPROFILE, |
---|
261 | FALSE, TRUE, "ICC Profile" }, |
---|
262 | #endif |
---|
263 | { TIFFTAG_STONITS, 1, 1, TIFF_DOUBLE, FIELD_STONITS, |
---|
264 | FALSE, FALSE, "StoNits" }, |
---|
265 | }; |
---|
266 | #define N(a) (sizeof (a) / sizeof (a[0])) |
---|
267 | |
---|
268 | void |
---|
269 | _TIFFSetupFieldInfo(TIFF* tif) |
---|
270 | { |
---|
271 | if (tif->tif_fieldinfo) { |
---|
272 | _TIFFfree(tif->tif_fieldinfo); |
---|
273 | tif->tif_nfields = 0; |
---|
274 | } |
---|
275 | _TIFFMergeFieldInfo(tif, tiffFieldInfo, N(tiffFieldInfo)); |
---|
276 | } |
---|
277 | |
---|
278 | static int |
---|
279 | tagCompare(const void* a, const void* b) |
---|
280 | { |
---|
281 | const TIFFFieldInfo* ta = *(const TIFFFieldInfo**) a; |
---|
282 | const TIFFFieldInfo* tb = *(const TIFFFieldInfo**) b; |
---|
283 | /* NB: be careful of return values for 16-bit platforms */ |
---|
284 | if (ta->field_tag != tb->field_tag) |
---|
285 | return (ta->field_tag < tb->field_tag ? -1 : 1); |
---|
286 | else |
---|
287 | return (tb->field_type < ta->field_type ? -1 : 1); |
---|
288 | } |
---|
289 | |
---|
290 | void |
---|
291 | _TIFFMergeFieldInfo(TIFF* tif, const TIFFFieldInfo info[], int n) |
---|
292 | { |
---|
293 | TIFFFieldInfo** tp; |
---|
294 | int i; |
---|
295 | |
---|
296 | if (tif->tif_nfields > 0) { |
---|
297 | tif->tif_fieldinfo = (TIFFFieldInfo**) |
---|
298 | _TIFFrealloc(tif->tif_fieldinfo, |
---|
299 | (tif->tif_nfields+n) * sizeof (TIFFFieldInfo*)); |
---|
300 | } else { |
---|
301 | tif->tif_fieldinfo = (TIFFFieldInfo**) |
---|
302 | _TIFFmalloc(n * sizeof (TIFFFieldInfo*)); |
---|
303 | } |
---|
304 | tp = &tif->tif_fieldinfo[tif->tif_nfields]; |
---|
305 | for (i = 0; i < n; i++) |
---|
306 | tp[i] = (TIFFFieldInfo*) &info[i]; /* XXX */ |
---|
307 | /* |
---|
308 | * NB: the core tags are presumed sorted correctly. |
---|
309 | */ |
---|
310 | if (tif->tif_nfields > 0) |
---|
311 | qsort(tif->tif_fieldinfo, (size_t) (tif->tif_nfields += n), |
---|
312 | sizeof (TIFFFieldInfo*), tagCompare); |
---|
313 | else |
---|
314 | tif->tif_nfields += n; |
---|
315 | } |
---|
316 | |
---|
317 | void |
---|
318 | _TIFFPrintFieldInfo(TIFF* tif, FILE* fd) |
---|
319 | { |
---|
320 | int i; |
---|
321 | |
---|
322 | fprintf(fd, "%s: \n", tif->tif_name); |
---|
323 | for (i = 0; i < tif->tif_nfields; i++) { |
---|
324 | const TIFFFieldInfo* fip = tif->tif_fieldinfo[i]; |
---|
325 | fprintf(fd, "field[%2d] %5lu, %2d, %2d, %d, %2d, %5s, %5s, %s\n" |
---|
326 | , i |
---|
327 | , (unsigned long) fip->field_tag |
---|
328 | , fip->field_readcount, fip->field_writecount |
---|
329 | , fip->field_type |
---|
330 | , fip->field_bit |
---|
331 | , fip->field_oktochange ? "TRUE" : "FALSE" |
---|
332 | , fip->field_passcount ? "TRUE" : "FALSE" |
---|
333 | , fip->field_name |
---|
334 | ); |
---|
335 | } |
---|
336 | } |
---|
337 | |
---|
338 | const int tiffDataWidth[] = { |
---|
339 | 1, /* nothing */ |
---|
340 | 1, /* TIFF_BYTE */ |
---|
341 | 1, /* TIFF_ASCII */ |
---|
342 | 2, /* TIFF_SHORT */ |
---|
343 | 4, /* TIFF_LONG */ |
---|
344 | 8, /* TIFF_RATIONAL */ |
---|
345 | 1, /* TIFF_SBYTE */ |
---|
346 | 1, /* TIFF_UNDEFINED */ |
---|
347 | 2, /* TIFF_SSHORT */ |
---|
348 | 4, /* TIFF_SLONG */ |
---|
349 | 8, /* TIFF_SRATIONAL */ |
---|
350 | 4, /* TIFF_FLOAT */ |
---|
351 | 8, /* TIFF_DOUBLE */ |
---|
352 | }; |
---|
353 | |
---|
354 | /* |
---|
355 | * Return nearest TIFFDataType to the sample type of an image. |
---|
356 | */ |
---|
357 | TIFFDataType |
---|
358 | _TIFFSampleToTagType(TIFF* tif) |
---|
359 | { |
---|
360 | int bps = (int) TIFFhowmany(tif->tif_dir.td_bitspersample, 8); |
---|
361 | |
---|
362 | switch (tif->tif_dir.td_sampleformat) { |
---|
363 | case SAMPLEFORMAT_IEEEFP: |
---|
364 | return (bps == 4 ? TIFF_FLOAT : TIFF_DOUBLE); |
---|
365 | case SAMPLEFORMAT_INT: |
---|
366 | return (bps <= 1 ? TIFF_SBYTE : |
---|
367 | bps <= 2 ? TIFF_SSHORT : TIFF_SLONG); |
---|
368 | case SAMPLEFORMAT_UINT: |
---|
369 | return (bps <= 1 ? TIFF_BYTE : |
---|
370 | bps <= 2 ? TIFF_SHORT : TIFF_LONG); |
---|
371 | case SAMPLEFORMAT_VOID: |
---|
372 | return (TIFF_UNDEFINED); |
---|
373 | } |
---|
374 | /*NOTREACHED*/ |
---|
375 | return (TIFF_UNDEFINED); |
---|
376 | } |
---|
377 | |
---|
378 | const TIFFFieldInfo* |
---|
379 | _TIFFFindFieldInfo(TIFF* tif, ttag_t tag, TIFFDataType dt) |
---|
380 | { |
---|
381 | static const TIFFFieldInfo *last = NULL; |
---|
382 | int i, n; |
---|
383 | |
---|
384 | if (last && last->field_tag == tag && |
---|
385 | (dt == TIFF_ANY || dt == last->field_type)) |
---|
386 | return (last); |
---|
387 | /* NB: if table gets big, use sorted search (e.g. binary search) */ |
---|
388 | for (i = 0, n = tif->tif_nfields; i < n; i++) { |
---|
389 | const TIFFFieldInfo* fip = tif->tif_fieldinfo[i]; |
---|
390 | if (fip->field_tag == tag && |
---|
391 | (dt == TIFF_ANY || fip->field_type == dt)) |
---|
392 | return (last = fip); |
---|
393 | } |
---|
394 | return ((const TIFFFieldInfo *)0); |
---|
395 | } |
---|
396 | |
---|
397 | #include <assert.h> |
---|
398 | #include <stdio.h> |
---|
399 | |
---|
400 | const TIFFFieldInfo* |
---|
401 | _TIFFFieldWithTag(TIFF* tif, ttag_t tag) |
---|
402 | { |
---|
403 | const TIFFFieldInfo* fip = _TIFFFindFieldInfo(tif, tag, TIFF_ANY); |
---|
404 | if (!fip) { |
---|
405 | TIFFError("TIFFFieldWithTag", |
---|
406 | "Internal error, unknown tag 0x%x", (u_int) tag); |
---|
407 | assert(fip != NULL); |
---|
408 | /*NOTREACHED*/ |
---|
409 | } |
---|
410 | return (fip); |
---|
411 | } |
---|