/src/libtiff/libtiff/tif_print.c
Line | Count | Source (jump to first uncovered line) |
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 | | * Directory Printing Support |
29 | | */ |
30 | | #include "tiffiop.h" |
31 | | #include <stdio.h> |
32 | | |
33 | | #include <ctype.h> |
34 | | |
35 | | static void _TIFFprintAsciiBounded(FILE *fd, const char *cp, size_t max_chars); |
36 | | |
37 | | static const char *const photoNames[] = { |
38 | | "min-is-white", /* PHOTOMETRIC_MINISWHITE */ |
39 | | "min-is-black", /* PHOTOMETRIC_MINISBLACK */ |
40 | | "RGB color", /* PHOTOMETRIC_RGB */ |
41 | | "palette color (RGB from colormap)", /* PHOTOMETRIC_PALETTE */ |
42 | | "transparency mask", /* PHOTOMETRIC_MASK */ |
43 | | "separated", /* PHOTOMETRIC_SEPARATED */ |
44 | | "YCbCr", /* PHOTOMETRIC_YCBCR */ |
45 | | "7 (0x7)", |
46 | | "CIE L*a*b*", /* PHOTOMETRIC_CIELAB */ |
47 | | "ICC L*a*b*", /* PHOTOMETRIC_ICCLAB */ |
48 | | "ITU L*a*b*" /* PHOTOMETRIC_ITULAB */ |
49 | | }; |
50 | 0 | #define NPHOTONAMES (sizeof(photoNames) / sizeof(photoNames[0])) |
51 | | |
52 | | static const char *const orientNames[] = { |
53 | | "0 (0x0)", |
54 | | "row 0 top, col 0 lhs", /* ORIENTATION_TOPLEFT */ |
55 | | "row 0 top, col 0 rhs", /* ORIENTATION_TOPRIGHT */ |
56 | | "row 0 bottom, col 0 rhs", /* ORIENTATION_BOTRIGHT */ |
57 | | "row 0 bottom, col 0 lhs", /* ORIENTATION_BOTLEFT */ |
58 | | "row 0 lhs, col 0 top", /* ORIENTATION_LEFTTOP */ |
59 | | "row 0 rhs, col 0 top", /* ORIENTATION_RIGHTTOP */ |
60 | | "row 0 rhs, col 0 bottom", /* ORIENTATION_RIGHTBOT */ |
61 | | "row 0 lhs, col 0 bottom", /* ORIENTATION_LEFTBOT */ |
62 | | }; |
63 | 0 | #define NORIENTNAMES (sizeof(orientNames) / sizeof(orientNames[0])) |
64 | | |
65 | | static const struct tagname |
66 | | { |
67 | | uint16_t tag; |
68 | | const char *name; |
69 | | } tagnames[] = { |
70 | | {TIFFTAG_GDAL_METADATA, "GDAL Metadata"}, |
71 | | {TIFFTAG_GDAL_NODATA, "GDAL NoDataValue"}, |
72 | | }; |
73 | 0 | #define NTAGS (sizeof(tagnames) / sizeof(tagnames[0])) |
74 | | |
75 | | static void _TIFFPrintField(FILE *fd, const TIFFField *fip, |
76 | | uint32_t value_count, void *raw_data) |
77 | 0 | { |
78 | 0 | uint32_t j; |
79 | | |
80 | | /* Print a user-friendly name for tags of relatively common use, but */ |
81 | | /* which aren't registered by libtiff itself. */ |
82 | 0 | const char *field_name = fip->field_name; |
83 | 0 | if (TIFFFieldIsAnonymous(fip)) |
84 | 0 | { |
85 | 0 | for (size_t i = 0; i < NTAGS; ++i) |
86 | 0 | { |
87 | 0 | if (fip->field_tag == tagnames[i].tag) |
88 | 0 | { |
89 | 0 | field_name = tagnames[i].name; |
90 | 0 | break; |
91 | 0 | } |
92 | 0 | } |
93 | 0 | } |
94 | 0 | fprintf(fd, " %s: ", field_name); |
95 | |
|
96 | 0 | for (j = 0; j < value_count; j++) |
97 | 0 | { |
98 | 0 | if (fip->field_type == TIFF_BYTE) |
99 | 0 | fprintf(fd, "%" PRIu8, ((uint8_t *)raw_data)[j]); |
100 | 0 | else if (fip->field_type == TIFF_UNDEFINED) |
101 | 0 | fprintf(fd, "0x%" PRIx8, ((uint8_t *)raw_data)[j]); |
102 | 0 | else if (fip->field_type == TIFF_SBYTE) |
103 | 0 | fprintf(fd, "%" PRId8, ((int8_t *)raw_data)[j]); |
104 | 0 | else if (fip->field_type == TIFF_SHORT) |
105 | 0 | fprintf(fd, "%" PRIu16, ((uint16_t *)raw_data)[j]); |
106 | 0 | else if (fip->field_type == TIFF_SSHORT) |
107 | 0 | fprintf(fd, "%" PRId16, ((int16_t *)raw_data)[j]); |
108 | 0 | else if (fip->field_type == TIFF_LONG) |
109 | 0 | fprintf(fd, "%" PRIu32, ((uint32_t *)raw_data)[j]); |
110 | 0 | else if (fip->field_type == TIFF_SLONG) |
111 | 0 | fprintf(fd, "%" PRId32, ((int32_t *)raw_data)[j]); |
112 | 0 | else if (fip->field_type == TIFF_IFD) |
113 | 0 | fprintf(fd, "0x%" PRIx32, ((uint32_t *)raw_data)[j]); |
114 | 0 | else if (fip->field_type == TIFF_RATIONAL || |
115 | 0 | fip->field_type == TIFF_SRATIONAL) |
116 | 0 | { |
117 | 0 | int tv_size = TIFFFieldSetGetSize(fip); |
118 | 0 | if (tv_size == 8) |
119 | 0 | fprintf(fd, "%lf", ((double *)raw_data)[j]); |
120 | 0 | else |
121 | 0 | fprintf(fd, "%f", ((float *)raw_data)[j]); |
122 | 0 | } |
123 | 0 | else if (fip->field_type == TIFF_FLOAT) |
124 | 0 | fprintf(fd, "%f", ((float *)raw_data)[j]); |
125 | 0 | else if (fip->field_type == TIFF_LONG8) |
126 | 0 | fprintf(fd, "%" PRIu64, ((uint64_t *)raw_data)[j]); |
127 | 0 | else if (fip->field_type == TIFF_SLONG8) |
128 | 0 | fprintf(fd, "%" PRId64, ((int64_t *)raw_data)[j]); |
129 | 0 | else if (fip->field_type == TIFF_IFD8) |
130 | 0 | fprintf(fd, "0x%" PRIx64, ((uint64_t *)raw_data)[j]); |
131 | 0 | else if (fip->field_type == TIFF_DOUBLE) |
132 | 0 | fprintf(fd, "%lf", ((double *)raw_data)[j]); |
133 | 0 | else if (fip->field_type == TIFF_ASCII) |
134 | 0 | { |
135 | 0 | fprintf(fd, "%s", (char *)raw_data); |
136 | 0 | break; |
137 | 0 | } |
138 | 0 | else |
139 | 0 | { |
140 | 0 | fprintf(fd, "<unsupported data type in TIFFPrint>"); |
141 | 0 | break; |
142 | 0 | } |
143 | | |
144 | 0 | if (j < value_count - 1) |
145 | 0 | fprintf(fd, ","); |
146 | 0 | } |
147 | |
|
148 | 0 | fprintf(fd, "\n"); |
149 | 0 | } |
150 | | |
151 | | static int _TIFFPrettyPrintField(TIFF *tif, const TIFFField *fip, FILE *fd, |
152 | | uint32_t tag, uint32_t value_count, |
153 | | void *raw_data) |
154 | 0 | { |
155 | 0 | (void)tif; |
156 | | |
157 | | /* do not try to pretty print auto-defined fields */ |
158 | 0 | if (TIFFFieldIsAnonymous(fip)) |
159 | 0 | { |
160 | 0 | return 0; |
161 | 0 | } |
162 | | |
163 | 0 | switch (tag) |
164 | 0 | { |
165 | 0 | case TIFFTAG_INKSET: |
166 | 0 | if (value_count == 2 && fip->field_type == TIFF_SHORT) |
167 | 0 | { |
168 | 0 | fprintf(fd, " Ink Set: "); |
169 | 0 | switch (*((uint16_t *)raw_data)) |
170 | 0 | { |
171 | 0 | case INKSET_CMYK: |
172 | 0 | fprintf(fd, "CMYK\n"); |
173 | 0 | break; |
174 | 0 | default: |
175 | 0 | fprintf(fd, "%" PRIu16 " (0x%" PRIx16 ")\n", |
176 | 0 | *((uint16_t *)raw_data), |
177 | 0 | *((uint16_t *)raw_data)); |
178 | 0 | break; |
179 | 0 | } |
180 | 0 | return 1; |
181 | 0 | } |
182 | 0 | return 0; |
183 | | |
184 | 0 | case TIFFTAG_DOTRANGE: |
185 | 0 | if (value_count == 2 && fip->field_type == TIFF_SHORT) |
186 | 0 | { |
187 | 0 | fprintf(fd, " Dot Range: %" PRIu16 "-%" PRIu16 "\n", |
188 | 0 | ((uint16_t *)raw_data)[0], ((uint16_t *)raw_data)[1]); |
189 | 0 | return 1; |
190 | 0 | } |
191 | 0 | return 0; |
192 | | |
193 | 0 | case TIFFTAG_WHITEPOINT: |
194 | 0 | if (value_count == 2 && fip->field_type == TIFF_RATIONAL) |
195 | 0 | { |
196 | 0 | fprintf(fd, " White Point: %g-%g\n", ((float *)raw_data)[0], |
197 | 0 | ((float *)raw_data)[1]); |
198 | 0 | return 1; |
199 | 0 | } |
200 | 0 | return 0; |
201 | | |
202 | 0 | case TIFFTAG_XMLPACKET: |
203 | 0 | { |
204 | 0 | uint32_t i; |
205 | |
|
206 | 0 | fprintf(fd, " XMLPacket (XMP Metadata):\n"); |
207 | 0 | for (i = 0; i < value_count; i++) |
208 | 0 | fputc(((char *)raw_data)[i], fd); |
209 | 0 | fprintf(fd, "\n"); |
210 | 0 | return 1; |
211 | 0 | } |
212 | 0 | case TIFFTAG_RICHTIFFIPTC: |
213 | 0 | fprintf(fd, " RichTIFFIPTC Data: <present>, %" PRIu32 " bytes\n", |
214 | 0 | value_count); |
215 | 0 | return 1; |
216 | | |
217 | 0 | case TIFFTAG_PHOTOSHOP: |
218 | 0 | fprintf(fd, " Photoshop Data: <present>, %" PRIu32 " bytes\n", |
219 | 0 | value_count); |
220 | 0 | return 1; |
221 | | |
222 | 0 | case TIFFTAG_ICCPROFILE: |
223 | 0 | fprintf(fd, " ICC Profile: <present>, %" PRIu32 " bytes\n", |
224 | 0 | value_count); |
225 | 0 | return 1; |
226 | | |
227 | 0 | case TIFFTAG_STONITS: |
228 | 0 | if (value_count == 1 && fip->field_type == TIFF_DOUBLE) |
229 | 0 | { |
230 | 0 | fprintf(fd, " Sample to Nits conversion factor: %.4e\n", |
231 | 0 | *((double *)raw_data)); |
232 | 0 | return 1; |
233 | 0 | } |
234 | 0 | return 0; |
235 | 0 | } |
236 | | |
237 | 0 | return 0; |
238 | 0 | } |
239 | | |
240 | | /* |
241 | | * Print the contents of the current directory |
242 | | * to the specified stdio file stream. |
243 | | */ |
244 | | void TIFFPrintDirectory(TIFF *tif, FILE *fd, long flags) |
245 | 0 | { |
246 | 0 | TIFFDirectory *td = &tif->tif_dir; |
247 | 0 | char *sep; |
248 | 0 | long l, n; |
249 | |
|
250 | 0 | fprintf(fd, "TIFF Directory at offset 0x%" PRIx64 " (%" PRIu64 ")\n", |
251 | 0 | tif->tif_diroff, tif->tif_diroff); |
252 | 0 | if (TIFFFieldSet(tif, FIELD_SUBFILETYPE)) |
253 | 0 | { |
254 | 0 | fprintf(fd, " Subfile Type:"); |
255 | 0 | sep = " "; |
256 | 0 | if (td->td_subfiletype & FILETYPE_REDUCEDIMAGE) |
257 | 0 | { |
258 | 0 | fprintf(fd, "%sreduced-resolution image", sep); |
259 | 0 | sep = "/"; |
260 | 0 | } |
261 | 0 | if (td->td_subfiletype & FILETYPE_PAGE) |
262 | 0 | { |
263 | 0 | fprintf(fd, "%smulti-page document", sep); |
264 | 0 | sep = "/"; |
265 | 0 | } |
266 | 0 | if (td->td_subfiletype & FILETYPE_MASK) |
267 | 0 | fprintf(fd, "%stransparency mask", sep); |
268 | 0 | fprintf(fd, " (%" PRIu32 " = 0x%" PRIx32 ")\n", td->td_subfiletype, |
269 | 0 | td->td_subfiletype); |
270 | 0 | } |
271 | 0 | if (TIFFFieldSet(tif, FIELD_IMAGEDIMENSIONS)) |
272 | 0 | { |
273 | 0 | fprintf(fd, " Image Width: %" PRIu32 " Image Length: %" PRIu32, |
274 | 0 | td->td_imagewidth, td->td_imagelength); |
275 | 0 | if (TIFFFieldSet(tif, FIELD_IMAGEDEPTH)) |
276 | 0 | fprintf(fd, " Image Depth: %" PRIu32, td->td_imagedepth); |
277 | 0 | fprintf(fd, "\n"); |
278 | 0 | } |
279 | 0 | if (TIFFFieldSet(tif, FIELD_TILEDIMENSIONS)) |
280 | 0 | { |
281 | 0 | fprintf(fd, " Tile Width: %" PRIu32 " Tile Length: %" PRIu32, |
282 | 0 | td->td_tilewidth, td->td_tilelength); |
283 | 0 | if (TIFFFieldSet(tif, FIELD_TILEDEPTH)) |
284 | 0 | fprintf(fd, " Tile Depth: %" PRIu32, td->td_tiledepth); |
285 | 0 | fprintf(fd, "\n"); |
286 | 0 | } |
287 | 0 | if (TIFFFieldSet(tif, FIELD_RESOLUTION)) |
288 | 0 | { |
289 | 0 | fprintf(fd, " Resolution: %g, %g", td->td_xresolution, |
290 | 0 | td->td_yresolution); |
291 | 0 | if (TIFFFieldSet(tif, FIELD_RESOLUTIONUNIT)) |
292 | 0 | { |
293 | 0 | switch (td->td_resolutionunit) |
294 | 0 | { |
295 | 0 | case RESUNIT_NONE: |
296 | 0 | fprintf(fd, " (unitless)"); |
297 | 0 | break; |
298 | 0 | case RESUNIT_INCH: |
299 | 0 | fprintf(fd, " pixels/inch"); |
300 | 0 | break; |
301 | 0 | case RESUNIT_CENTIMETER: |
302 | 0 | fprintf(fd, " pixels/cm"); |
303 | 0 | break; |
304 | 0 | default: |
305 | 0 | fprintf(fd, " (unit %" PRIu16 " = 0x%" PRIx16 ")", |
306 | 0 | td->td_resolutionunit, td->td_resolutionunit); |
307 | 0 | break; |
308 | 0 | } |
309 | 0 | } |
310 | 0 | fprintf(fd, "\n"); |
311 | 0 | } |
312 | 0 | if (TIFFFieldSet(tif, FIELD_POSITION)) |
313 | 0 | fprintf(fd, " Position: %g, %g\n", td->td_xposition, td->td_yposition); |
314 | 0 | if (TIFFFieldSet(tif, FIELD_BITSPERSAMPLE)) |
315 | 0 | fprintf(fd, " Bits/Sample: %" PRIu16 "\n", td->td_bitspersample); |
316 | 0 | if (TIFFFieldSet(tif, FIELD_SAMPLEFORMAT)) |
317 | 0 | { |
318 | 0 | fprintf(fd, " Sample Format: "); |
319 | 0 | switch (td->td_sampleformat) |
320 | 0 | { |
321 | 0 | case SAMPLEFORMAT_VOID: |
322 | 0 | fprintf(fd, "void\n"); |
323 | 0 | break; |
324 | 0 | case SAMPLEFORMAT_INT: |
325 | 0 | fprintf(fd, "signed integer\n"); |
326 | 0 | break; |
327 | 0 | case SAMPLEFORMAT_UINT: |
328 | 0 | fprintf(fd, "unsigned integer\n"); |
329 | 0 | break; |
330 | 0 | case SAMPLEFORMAT_IEEEFP: |
331 | 0 | fprintf(fd, "IEEE floating point\n"); |
332 | 0 | break; |
333 | 0 | case SAMPLEFORMAT_COMPLEXINT: |
334 | 0 | fprintf(fd, "complex signed integer\n"); |
335 | 0 | break; |
336 | 0 | case SAMPLEFORMAT_COMPLEXIEEEFP: |
337 | 0 | fprintf(fd, "complex IEEE floating point\n"); |
338 | 0 | break; |
339 | 0 | default: |
340 | 0 | fprintf(fd, "%" PRIu16 " (0x%" PRIx16 ")\n", |
341 | 0 | td->td_sampleformat, td->td_sampleformat); |
342 | 0 | break; |
343 | 0 | } |
344 | 0 | } |
345 | 0 | if (TIFFFieldSet(tif, FIELD_COMPRESSION)) |
346 | 0 | { |
347 | 0 | const TIFFCodec *c = TIFFFindCODEC(td->td_compression); |
348 | 0 | fprintf(fd, " Compression Scheme: "); |
349 | 0 | if (c) |
350 | 0 | fprintf(fd, "%s\n", c->name); |
351 | 0 | else |
352 | 0 | fprintf(fd, "%" PRIu16 " (0x%" PRIx16 ")\n", td->td_compression, |
353 | 0 | td->td_compression); |
354 | 0 | } |
355 | 0 | if (TIFFFieldSet(tif, FIELD_PHOTOMETRIC)) |
356 | 0 | { |
357 | 0 | fprintf(fd, " Photometric Interpretation: "); |
358 | 0 | if (td->td_photometric < NPHOTONAMES) |
359 | 0 | fprintf(fd, "%s\n", photoNames[td->td_photometric]); |
360 | 0 | else |
361 | 0 | { |
362 | 0 | switch (td->td_photometric) |
363 | 0 | { |
364 | 0 | case PHOTOMETRIC_LOGL: |
365 | 0 | fprintf(fd, "CIE Log2(L)\n"); |
366 | 0 | break; |
367 | 0 | case PHOTOMETRIC_LOGLUV: |
368 | 0 | fprintf(fd, "CIE Log2(L) (u',v')\n"); |
369 | 0 | break; |
370 | 0 | default: |
371 | 0 | fprintf(fd, "%" PRIu16 " (0x%" PRIx16 ")\n", |
372 | 0 | td->td_photometric, td->td_photometric); |
373 | 0 | break; |
374 | 0 | } |
375 | 0 | } |
376 | 0 | } |
377 | 0 | if (TIFFFieldSet(tif, FIELD_EXTRASAMPLES) && td->td_extrasamples) |
378 | 0 | { |
379 | 0 | uint16_t i; |
380 | 0 | fprintf(fd, " Extra Samples: %" PRIu16 "<", td->td_extrasamples); |
381 | 0 | sep = ""; |
382 | 0 | for (i = 0; i < td->td_extrasamples; i++) |
383 | 0 | { |
384 | 0 | switch (td->td_sampleinfo[i]) |
385 | 0 | { |
386 | 0 | case EXTRASAMPLE_UNSPECIFIED: |
387 | 0 | fprintf(fd, "%sunspecified", sep); |
388 | 0 | break; |
389 | 0 | case EXTRASAMPLE_ASSOCALPHA: |
390 | 0 | fprintf(fd, "%sassoc-alpha", sep); |
391 | 0 | break; |
392 | 0 | case EXTRASAMPLE_UNASSALPHA: |
393 | 0 | fprintf(fd, "%sunassoc-alpha", sep); |
394 | 0 | break; |
395 | 0 | default: |
396 | 0 | fprintf(fd, "%s%" PRIu16 " (0x%" PRIx16 ")", sep, |
397 | 0 | td->td_sampleinfo[i], td->td_sampleinfo[i]); |
398 | 0 | break; |
399 | 0 | } |
400 | 0 | sep = ", "; |
401 | 0 | } |
402 | 0 | fprintf(fd, ">\n"); |
403 | 0 | } |
404 | 0 | if (TIFFFieldSet(tif, FIELD_INKNAMES)) |
405 | 0 | { |
406 | 0 | char *cp; |
407 | 0 | uint16_t i; |
408 | 0 | fprintf(fd, " Ink Names: "); |
409 | 0 | i = td->td_samplesperpixel; |
410 | 0 | sep = ""; |
411 | 0 | for (cp = td->td_inknames; |
412 | 0 | i > 0 && cp < td->td_inknames + td->td_inknameslen; |
413 | 0 | cp = strchr(cp, '\0') + 1, i--) |
414 | 0 | { |
415 | 0 | size_t max_chars = td->td_inknameslen - (cp - td->td_inknames); |
416 | 0 | fputs(sep, fd); |
417 | 0 | _TIFFprintAsciiBounded(fd, cp, max_chars); |
418 | 0 | sep = ", "; |
419 | 0 | } |
420 | 0 | fputs("\n", fd); |
421 | 0 | } |
422 | 0 | if (TIFFFieldSet(tif, FIELD_NUMBEROFINKS)) |
423 | 0 | { |
424 | 0 | fprintf(fd, " NumberOfInks: %d\n", td->td_numberofinks); |
425 | 0 | } |
426 | 0 | if (TIFFFieldSet(tif, FIELD_THRESHHOLDING)) |
427 | 0 | { |
428 | 0 | fprintf(fd, " Thresholding: "); |
429 | 0 | switch (td->td_threshholding) |
430 | 0 | { |
431 | 0 | case THRESHHOLD_BILEVEL: |
432 | 0 | fprintf(fd, "bilevel art scan\n"); |
433 | 0 | break; |
434 | 0 | case THRESHHOLD_HALFTONE: |
435 | 0 | fprintf(fd, "halftone or dithered scan\n"); |
436 | 0 | break; |
437 | 0 | case THRESHHOLD_ERRORDIFFUSE: |
438 | 0 | fprintf(fd, "error diffused\n"); |
439 | 0 | break; |
440 | 0 | default: |
441 | 0 | fprintf(fd, "%" PRIu16 " (0x%" PRIx16 ")\n", |
442 | 0 | td->td_threshholding, td->td_threshholding); |
443 | 0 | break; |
444 | 0 | } |
445 | 0 | } |
446 | 0 | if (TIFFFieldSet(tif, FIELD_FILLORDER)) |
447 | 0 | { |
448 | 0 | fprintf(fd, " FillOrder: "); |
449 | 0 | switch (td->td_fillorder) |
450 | 0 | { |
451 | 0 | case FILLORDER_MSB2LSB: |
452 | 0 | fprintf(fd, "msb-to-lsb\n"); |
453 | 0 | break; |
454 | 0 | case FILLORDER_LSB2MSB: |
455 | 0 | fprintf(fd, "lsb-to-msb\n"); |
456 | 0 | break; |
457 | 0 | default: |
458 | 0 | fprintf(fd, "%" PRIu16 " (0x%" PRIx16 ")\n", td->td_fillorder, |
459 | 0 | td->td_fillorder); |
460 | 0 | break; |
461 | 0 | } |
462 | 0 | } |
463 | 0 | if (TIFFFieldSet(tif, FIELD_YCBCRSUBSAMPLING)) |
464 | 0 | { |
465 | 0 | fprintf(fd, " YCbCr Subsampling: %" PRIu16 ", %" PRIu16 "\n", |
466 | 0 | td->td_ycbcrsubsampling[0], td->td_ycbcrsubsampling[1]); |
467 | 0 | } |
468 | 0 | if (TIFFFieldSet(tif, FIELD_YCBCRPOSITIONING)) |
469 | 0 | { |
470 | 0 | fprintf(fd, " YCbCr Positioning: "); |
471 | 0 | switch (td->td_ycbcrpositioning) |
472 | 0 | { |
473 | 0 | case YCBCRPOSITION_CENTERED: |
474 | 0 | fprintf(fd, "centered\n"); |
475 | 0 | break; |
476 | 0 | case YCBCRPOSITION_COSITED: |
477 | 0 | fprintf(fd, "cosited\n"); |
478 | 0 | break; |
479 | 0 | default: |
480 | 0 | fprintf(fd, "%" PRIu16 " (0x%" PRIx16 ")\n", |
481 | 0 | td->td_ycbcrpositioning, td->td_ycbcrpositioning); |
482 | 0 | break; |
483 | 0 | } |
484 | 0 | } |
485 | 0 | if (TIFFFieldSet(tif, FIELD_HALFTONEHINTS)) |
486 | 0 | fprintf(fd, " Halftone Hints: light %" PRIu16 " dark %" PRIu16 "\n", |
487 | 0 | td->td_halftonehints[0], td->td_halftonehints[1]); |
488 | 0 | if (TIFFFieldSet(tif, FIELD_ORIENTATION)) |
489 | 0 | { |
490 | 0 | fprintf(fd, " Orientation: "); |
491 | 0 | if (td->td_orientation < NORIENTNAMES) |
492 | 0 | fprintf(fd, "%s\n", orientNames[td->td_orientation]); |
493 | 0 | else |
494 | 0 | fprintf(fd, "%" PRIu16 " (0x%" PRIx16 ")\n", td->td_orientation, |
495 | 0 | td->td_orientation); |
496 | 0 | } |
497 | 0 | if (TIFFFieldSet(tif, FIELD_SAMPLESPERPIXEL)) |
498 | 0 | fprintf(fd, " Samples/Pixel: %" PRIx16 "\n", td->td_samplesperpixel); |
499 | 0 | if (TIFFFieldSet(tif, FIELD_ROWSPERSTRIP)) |
500 | 0 | { |
501 | 0 | fprintf(fd, " Rows/Strip: "); |
502 | 0 | if (td->td_rowsperstrip == (uint32_t)-1) |
503 | 0 | fprintf(fd, "(infinite)\n"); |
504 | 0 | else |
505 | 0 | fprintf(fd, "%" PRIu32 "\n", td->td_rowsperstrip); |
506 | 0 | } |
507 | 0 | if (TIFFFieldSet(tif, FIELD_MINSAMPLEVALUE)) |
508 | 0 | fprintf(fd, " Min Sample Value: %" PRIu16 "\n", td->td_minsamplevalue); |
509 | 0 | if (TIFFFieldSet(tif, FIELD_MAXSAMPLEVALUE)) |
510 | 0 | fprintf(fd, " Max Sample Value: %" PRIu16 "\n", td->td_maxsamplevalue); |
511 | 0 | if (TIFFFieldSet(tif, FIELD_SMINSAMPLEVALUE)) |
512 | 0 | { |
513 | 0 | int i; |
514 | 0 | int count = |
515 | 0 | (tif->tif_flags & TIFF_PERSAMPLE) ? td->td_samplesperpixel : 1; |
516 | 0 | fprintf(fd, " SMin Sample Value:"); |
517 | 0 | for (i = 0; i < count; ++i) |
518 | 0 | fprintf(fd, " %g", td->td_sminsamplevalue[i]); |
519 | 0 | fprintf(fd, "\n"); |
520 | 0 | } |
521 | 0 | if (TIFFFieldSet(tif, FIELD_SMAXSAMPLEVALUE)) |
522 | 0 | { |
523 | 0 | int i; |
524 | 0 | int count = |
525 | 0 | (tif->tif_flags & TIFF_PERSAMPLE) ? td->td_samplesperpixel : 1; |
526 | 0 | fprintf(fd, " SMax Sample Value:"); |
527 | 0 | for (i = 0; i < count; ++i) |
528 | 0 | fprintf(fd, " %g", td->td_smaxsamplevalue[i]); |
529 | 0 | fprintf(fd, "\n"); |
530 | 0 | } |
531 | 0 | if (TIFFFieldSet(tif, FIELD_PLANARCONFIG)) |
532 | 0 | { |
533 | 0 | fprintf(fd, " Planar Configuration: "); |
534 | 0 | switch (td->td_planarconfig) |
535 | 0 | { |
536 | 0 | case PLANARCONFIG_CONTIG: |
537 | 0 | fprintf(fd, "single image plane\n"); |
538 | 0 | break; |
539 | 0 | case PLANARCONFIG_SEPARATE: |
540 | 0 | fprintf(fd, "separate image planes\n"); |
541 | 0 | break; |
542 | 0 | default: |
543 | 0 | fprintf(fd, "%" PRIu16 " (0x%" PRIx16 ")\n", |
544 | 0 | td->td_planarconfig, td->td_planarconfig); |
545 | 0 | break; |
546 | 0 | } |
547 | 0 | } |
548 | 0 | if (TIFFFieldSet(tif, FIELD_PAGENUMBER)) |
549 | 0 | fprintf(fd, " Page Number: %" PRIu16 "-%" PRIu16 "\n", |
550 | 0 | td->td_pagenumber[0], td->td_pagenumber[1]); |
551 | 0 | if (TIFFFieldSet(tif, FIELD_COLORMAP)) |
552 | 0 | { |
553 | 0 | fprintf(fd, " Color Map: "); |
554 | 0 | if (flags & TIFFPRINT_COLORMAP) |
555 | 0 | { |
556 | 0 | fprintf(fd, "\n"); |
557 | 0 | n = 1L << td->td_bitspersample; |
558 | 0 | for (l = 0; l < n; l++) |
559 | 0 | fprintf(fd, " %5ld: %5" PRIu16 " %5" PRIu16 " %5" PRIu16 "\n", |
560 | 0 | l, td->td_colormap[0][l], td->td_colormap[1][l], |
561 | 0 | td->td_colormap[2][l]); |
562 | 0 | } |
563 | 0 | else |
564 | 0 | fprintf(fd, "(present)\n"); |
565 | 0 | } |
566 | 0 | if (TIFFFieldSet(tif, FIELD_REFBLACKWHITE)) |
567 | 0 | { |
568 | 0 | int i; |
569 | 0 | fprintf(fd, " Reference Black/White:\n"); |
570 | 0 | for (i = 0; i < 3; i++) |
571 | 0 | fprintf(fd, " %2d: %5g %5g\n", i, |
572 | 0 | td->td_refblackwhite[2 * i + 0], |
573 | 0 | td->td_refblackwhite[2 * i + 1]); |
574 | 0 | } |
575 | 0 | if (TIFFFieldSet(tif, FIELD_TRANSFERFUNCTION)) |
576 | 0 | { |
577 | 0 | fprintf(fd, " Transfer Function: "); |
578 | 0 | if (flags & TIFFPRINT_CURVES) |
579 | 0 | { |
580 | 0 | fprintf(fd, "\n"); |
581 | 0 | n = 1L << td->td_bitspersample; |
582 | 0 | for (l = 0; l < n; l++) |
583 | 0 | { |
584 | 0 | uint16_t i; |
585 | 0 | fprintf(fd, " %2ld: %5" PRIu16, l, |
586 | 0 | td->td_transferfunction[0][l]); |
587 | 0 | for (i = 1; |
588 | 0 | i < td->td_samplesperpixel - td->td_extrasamples && i < 3; |
589 | 0 | i++) |
590 | 0 | fprintf(fd, " %5" PRIu16, td->td_transferfunction[i][l]); |
591 | 0 | fputc('\n', fd); |
592 | 0 | } |
593 | 0 | } |
594 | 0 | else |
595 | 0 | fprintf(fd, "(present)\n"); |
596 | 0 | } |
597 | 0 | if (TIFFFieldSet(tif, FIELD_SUBIFD) && (td->td_subifd)) |
598 | 0 | { |
599 | 0 | uint16_t i; |
600 | 0 | fprintf(fd, " SubIFD Offsets:"); |
601 | 0 | for (i = 0; i < td->td_nsubifd; i++) |
602 | 0 | fprintf(fd, " %5" PRIu64, td->td_subifd[i]); |
603 | 0 | fputc('\n', fd); |
604 | 0 | } |
605 | | |
606 | | /* |
607 | | ** Custom tag support. |
608 | | */ |
609 | 0 | { |
610 | 0 | int i; |
611 | 0 | short count; |
612 | |
|
613 | 0 | count = (short)TIFFGetTagListCount(tif); |
614 | 0 | for (i = 0; i < count; i++) |
615 | 0 | { |
616 | 0 | uint32_t tag = TIFFGetTagListEntry(tif, i); |
617 | 0 | const TIFFField *fip; |
618 | 0 | uint32_t value_count; |
619 | 0 | int mem_alloc = 0; |
620 | 0 | void *raw_data = NULL; |
621 | 0 | uint16_t dotrange[2]; /* must be kept in that scope and not moved in |
622 | | the below TIFFTAG_DOTRANGE specific case */ |
623 | |
|
624 | 0 | fip = TIFFFieldWithTag(tif, tag); |
625 | 0 | if (fip == NULL) |
626 | 0 | continue; |
627 | | |
628 | 0 | if (fip->field_passcount) |
629 | 0 | { |
630 | 0 | if (fip->field_readcount == TIFF_VARIABLE2) |
631 | 0 | { |
632 | 0 | if (TIFFGetField(tif, tag, &value_count, &raw_data) != 1) |
633 | 0 | continue; |
634 | 0 | } |
635 | 0 | else if (fip->field_readcount == TIFF_VARIABLE) |
636 | 0 | { |
637 | 0 | uint16_t small_value_count; |
638 | 0 | if (TIFFGetField(tif, tag, &small_value_count, &raw_data) != |
639 | 0 | 1) |
640 | 0 | continue; |
641 | 0 | value_count = small_value_count; |
642 | 0 | } |
643 | 0 | else |
644 | 0 | { |
645 | 0 | assert(fip->field_readcount == TIFF_VARIABLE || |
646 | 0 | fip->field_readcount == TIFF_VARIABLE2); |
647 | 0 | continue; |
648 | 0 | } |
649 | 0 | } |
650 | 0 | else |
651 | 0 | { |
652 | 0 | if (fip->field_readcount == TIFF_VARIABLE || |
653 | 0 | fip->field_readcount == TIFF_VARIABLE2) |
654 | 0 | value_count = 1; |
655 | 0 | else if (fip->field_readcount == TIFF_SPP) |
656 | 0 | value_count = td->td_samplesperpixel; |
657 | 0 | else |
658 | 0 | value_count = fip->field_readcount; |
659 | 0 | if (fip->field_tag == TIFFTAG_DOTRANGE && |
660 | 0 | strcmp(fip->field_name, "DotRange") == 0) |
661 | 0 | { |
662 | | /* TODO: This is an evil exception and should not have been |
663 | | handled this way ... likely best if we move it into |
664 | | the directory structure with an explicit field in |
665 | | libtiff 4.1 and assign it a FIELD_ value */ |
666 | 0 | raw_data = dotrange; |
667 | 0 | TIFFGetField(tif, tag, dotrange + 0, dotrange + 1); |
668 | 0 | } |
669 | 0 | else if (fip->field_type == TIFF_ASCII || |
670 | 0 | fip->field_readcount == TIFF_VARIABLE || |
671 | 0 | fip->field_readcount == TIFF_VARIABLE2 || |
672 | 0 | fip->field_readcount == TIFF_SPP || value_count > 1) |
673 | 0 | { |
674 | 0 | if (TIFFGetField(tif, tag, &raw_data) != 1) |
675 | 0 | continue; |
676 | 0 | } |
677 | 0 | else |
678 | 0 | { |
679 | | /*--: Rational2Double: For Rationals evaluate |
680 | | * "set_field_type" to determine internal storage size. */ |
681 | 0 | int tv_size = TIFFFieldSetGetSize(fip); |
682 | 0 | raw_data = _TIFFmallocExt(tif, tv_size * value_count); |
683 | 0 | mem_alloc = 1; |
684 | 0 | if (TIFFGetField(tif, tag, raw_data) != 1) |
685 | 0 | { |
686 | 0 | _TIFFfreeExt(tif, raw_data); |
687 | 0 | continue; |
688 | 0 | } |
689 | 0 | } |
690 | 0 | } |
691 | | |
692 | | /* |
693 | | * Catch the tags which needs to be specially handled |
694 | | * and pretty print them. If tag not handled in |
695 | | * _TIFFPrettyPrintField() fall down and print it as |
696 | | * any other tag. |
697 | | */ |
698 | 0 | if (raw_data != NULL && |
699 | 0 | !_TIFFPrettyPrintField(tif, fip, fd, tag, value_count, |
700 | 0 | raw_data)) |
701 | 0 | _TIFFPrintField(fd, fip, value_count, raw_data); |
702 | |
|
703 | 0 | if (mem_alloc) |
704 | 0 | _TIFFfreeExt(tif, raw_data); |
705 | 0 | } |
706 | 0 | } |
707 | | |
708 | 0 | if (tif->tif_tagmethods.printdir) |
709 | 0 | (*tif->tif_tagmethods.printdir)(tif, fd, flags); |
710 | |
|
711 | 0 | if ((flags & TIFFPRINT_STRIPS) && TIFFFieldSet(tif, FIELD_STRIPOFFSETS)) |
712 | 0 | { |
713 | 0 | uint32_t s; |
714 | |
|
715 | 0 | fprintf(fd, " %" PRIu32 " %s:\n", td->td_nstrips, |
716 | 0 | isTiled(tif) ? "Tiles" : "Strips"); |
717 | 0 | for (s = 0; s < td->td_nstrips; s++) |
718 | 0 | fprintf(fd, " %3" PRIu32 ": [%8" PRIu64 ", %8" PRIu64 "]\n", s, |
719 | 0 | TIFFGetStrileOffset(tif, s), |
720 | 0 | TIFFGetStrileByteCount(tif, s)); |
721 | 0 | } |
722 | 0 | } |
723 | | |
724 | | void _TIFFprintAscii(FILE *fd, const char *cp) |
725 | 0 | { |
726 | 0 | _TIFFprintAsciiBounded(fd, cp, strlen(cp)); |
727 | 0 | } |
728 | | |
729 | | static void _TIFFprintAsciiBounded(FILE *fd, const char *cp, size_t max_chars) |
730 | 0 | { |
731 | 0 | for (; max_chars > 0 && *cp != '\0'; cp++, max_chars--) |
732 | 0 | { |
733 | 0 | const char *tp; |
734 | |
|
735 | 0 | if (isprint((int)*cp)) |
736 | 0 | { |
737 | 0 | fputc(*cp, fd); |
738 | 0 | continue; |
739 | 0 | } |
740 | 0 | for (tp = "\tt\bb\rr\nn\vv"; *tp; tp++) |
741 | 0 | if (*tp++ == *cp) |
742 | 0 | break; |
743 | 0 | if (*tp) |
744 | 0 | fprintf(fd, "\\%c", *tp); |
745 | 0 | else |
746 | 0 | fprintf(fd, "\\%03o", *cp & 0xff); |
747 | 0 | } |
748 | 0 | } |
749 | | |
750 | | void _TIFFprintAsciiTag(FILE *fd, const char *name, const char *value) |
751 | 0 | { |
752 | 0 | fprintf(fd, " %s: \"", name); |
753 | 0 | _TIFFprintAscii(fd, value); |
754 | 0 | fprintf(fd, "\"\n"); |
755 | 0 | } |