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