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 : long l, n;
252 :
253 0 : fprintf(fd, "TIFF Directory at offset 0x%" PRIx64 " (%" PRIu64 ")\n",
254 : tif->tif_diroff, tif->tif_diroff);
255 0 : if (TIFFFieldSet(tif, FIELD_SUBFILETYPE))
256 : {
257 0 : fprintf(fd, " Subfile Type:");
258 0 : sep = " ";
259 0 : if (td->td_subfiletype & FILETYPE_REDUCEDIMAGE)
260 : {
261 0 : fprintf(fd, "%sreduced-resolution image", sep);
262 0 : sep = "/";
263 : }
264 0 : if (td->td_subfiletype & FILETYPE_PAGE)
265 : {
266 0 : fprintf(fd, "%smulti-page document", sep);
267 0 : sep = "/";
268 : }
269 0 : if (td->td_subfiletype & FILETYPE_MASK)
270 0 : fprintf(fd, "%stransparency mask", sep);
271 0 : fprintf(fd, " (%" PRIu32 " = 0x%" PRIx32 ")\n", td->td_subfiletype,
272 : td->td_subfiletype);
273 : }
274 0 : if (TIFFFieldSet(tif, FIELD_IMAGEDIMENSIONS))
275 : {
276 0 : fprintf(fd, " Image Width: %" PRIu32 " Image Length: %" PRIu32,
277 : td->td_imagewidth, td->td_imagelength);
278 0 : if (TIFFFieldSet(tif, FIELD_IMAGEDEPTH))
279 0 : fprintf(fd, " Image Depth: %" PRIu32, td->td_imagedepth);
280 0 : fprintf(fd, "\n");
281 : }
282 0 : if (TIFFFieldSet(tif, FIELD_TILEDIMENSIONS))
283 : {
284 0 : fprintf(fd, " Tile Width: %" PRIu32 " Tile Length: %" PRIu32,
285 : td->td_tilewidth, td->td_tilelength);
286 0 : if (TIFFFieldSet(tif, FIELD_TILEDEPTH))
287 0 : fprintf(fd, " Tile Depth: %" PRIu32, td->td_tiledepth);
288 0 : fprintf(fd, "\n");
289 : }
290 0 : if (TIFFFieldSet(tif, FIELD_RESOLUTION))
291 : {
292 0 : fprintf(fd, " Resolution: %g, %g", td->td_xresolution,
293 0 : td->td_yresolution);
294 0 : if (TIFFFieldSet(tif, FIELD_RESOLUTIONUNIT))
295 : {
296 0 : switch (td->td_resolutionunit)
297 : {
298 0 : case RESUNIT_NONE:
299 0 : fprintf(fd, " (unitless)");
300 0 : break;
301 0 : case RESUNIT_INCH:
302 0 : fprintf(fd, " pixels/inch");
303 0 : break;
304 0 : case RESUNIT_CENTIMETER:
305 0 : fprintf(fd, " pixels/cm");
306 0 : break;
307 0 : default:
308 0 : fprintf(fd, " (unit %" PRIu16 " = 0x%" PRIx16 ")",
309 0 : td->td_resolutionunit, td->td_resolutionunit);
310 0 : break;
311 : }
312 0 : }
313 0 : fprintf(fd, "\n");
314 : }
315 0 : if (TIFFFieldSet(tif, FIELD_POSITION))
316 0 : fprintf(fd, " Position: %g, %g\n", td->td_xposition, td->td_yposition);
317 0 : if (TIFFFieldSet(tif, FIELD_BITSPERSAMPLE))
318 0 : fprintf(fd, " Bits/Sample: %" PRIu16 "\n", td->td_bitspersample);
319 0 : if (TIFFFieldSet(tif, FIELD_SAMPLEFORMAT))
320 : {
321 0 : fprintf(fd, " Sample Format: ");
322 0 : switch (td->td_sampleformat)
323 : {
324 0 : case SAMPLEFORMAT_VOID:
325 0 : fprintf(fd, "void\n");
326 0 : break;
327 0 : case SAMPLEFORMAT_INT:
328 0 : fprintf(fd, "signed integer\n");
329 0 : break;
330 0 : case SAMPLEFORMAT_UINT:
331 0 : fprintf(fd, "unsigned integer\n");
332 0 : break;
333 0 : case SAMPLEFORMAT_IEEEFP:
334 0 : fprintf(fd, "IEEE floating point\n");
335 0 : break;
336 0 : case SAMPLEFORMAT_COMPLEXINT:
337 0 : fprintf(fd, "complex signed integer\n");
338 0 : break;
339 0 : case SAMPLEFORMAT_COMPLEXIEEEFP:
340 0 : fprintf(fd, "complex IEEE floating point\n");
341 0 : break;
342 0 : default:
343 0 : fprintf(fd, "%" PRIu16 " (0x%" PRIx16 ")\n",
344 0 : td->td_sampleformat, td->td_sampleformat);
345 0 : break;
346 : }
347 0 : }
348 0 : if (TIFFFieldSet(tif, FIELD_COMPRESSION))
349 : {
350 0 : const TIFFCodec *c = TIFFFindCODEC(td->td_compression);
351 0 : fprintf(fd, " Compression Scheme: ");
352 0 : if (c)
353 0 : fprintf(fd, "%s\n", c->name);
354 : else
355 0 : fprintf(fd, "%" PRIu16 " (0x%" PRIx16 ")\n", td->td_compression,
356 0 : td->td_compression);
357 : }
358 0 : if (TIFFFieldSet(tif, FIELD_PHOTOMETRIC))
359 : {
360 0 : fprintf(fd, " Photometric Interpretation: ");
361 0 : if (td->td_photometric < NPHOTONAMES)
362 0 : fprintf(fd, "%s\n", photoNames[td->td_photometric]);
363 : else
364 : {
365 0 : switch (td->td_photometric)
366 : {
367 0 : case PHOTOMETRIC_LOGL:
368 0 : fprintf(fd, "CIE Log2(L)\n");
369 0 : break;
370 0 : case PHOTOMETRIC_LOGLUV:
371 0 : fprintf(fd, "CIE Log2(L) (u',v')\n");
372 0 : break;
373 0 : default:
374 0 : fprintf(fd, "%" PRIu16 " (0x%" PRIx16 ")\n",
375 0 : td->td_photometric, td->td_photometric);
376 0 : break;
377 : }
378 0 : }
379 : }
380 0 : if (TIFFFieldSet(tif, FIELD_EXTRASAMPLES) && td->td_extrasamples &&
381 0 : td->td_sampleinfo)
382 : {
383 : uint16_t i;
384 0 : fprintf(fd, " Extra Samples: %" PRIu16 "<", td->td_extrasamples);
385 0 : sep = "";
386 0 : for (i = 0; i < td->td_extrasamples; i++)
387 : {
388 0 : switch (td->td_sampleinfo[i])
389 : {
390 0 : case EXTRASAMPLE_UNSPECIFIED:
391 0 : fprintf(fd, "%sunspecified", sep);
392 0 : break;
393 0 : case EXTRASAMPLE_ASSOCALPHA:
394 0 : fprintf(fd, "%sassoc-alpha", sep);
395 0 : break;
396 0 : case EXTRASAMPLE_UNASSALPHA:
397 0 : fprintf(fd, "%sunassoc-alpha", sep);
398 0 : break;
399 0 : default:
400 0 : fprintf(fd, "%s%" PRIu16 " (0x%" PRIx16 ")", sep,
401 0 : td->td_sampleinfo[i], td->td_sampleinfo[i]);
402 0 : break;
403 : }
404 0 : sep = ", ";
405 : }
406 0 : fprintf(fd, ">\n");
407 : }
408 0 : if (TIFFFieldSet(tif, FIELD_INKNAMES))
409 : {
410 : char *cp;
411 : uint16_t i;
412 0 : fprintf(fd, " Ink Names: ");
413 0 : i = td->td_samplesperpixel;
414 0 : sep = "";
415 0 : for (cp = td->td_inknames;
416 0 : i > 0 && cp < td->td_inknames + td->td_inknameslen;
417 0 : cp = strchr(cp, '\0') + 1, i--)
418 : {
419 0 : size_t max_chars = 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 : n = 1L << td->td_bitspersample;
563 0 : for (l = 0; l < n; l++)
564 0 : fprintf(fd, " %5ld: %5" PRIu16 " %5" PRIu16 " %5" PRIu16 "\n",
565 0 : l, td->td_colormap[0][l], td->td_colormap[1][l],
566 0 : td->td_colormap[2][l]);
567 : }
568 : else
569 0 : fprintf(fd, "(present)\n");
570 : }
571 0 : if (TIFFFieldSet(tif, FIELD_REFBLACKWHITE))
572 : {
573 : int i;
574 0 : fprintf(fd, " Reference Black/White:\n");
575 0 : for (i = 0; i < 3; i++)
576 0 : fprintf(fd, " %2d: %5g %5g\n", i,
577 0 : td->td_refblackwhite[2 * i + 0],
578 0 : td->td_refblackwhite[2 * i + 1]);
579 : }
580 0 : if (TIFFFieldSet(tif, FIELD_TRANSFERFUNCTION) &&
581 0 : td->td_transferfunction[0] &&
582 0 : ((td->td_samplesperpixel - td->td_extrasamples > 1 &&
583 0 : td->td_transferfunction[1] && td->td_transferfunction[2]) ||
584 0 : td->td_samplesperpixel - td->td_extrasamples <= 1))
585 : {
586 0 : fprintf(fd, " Transfer Function: ");
587 0 : if (flags & TIFFPRINT_CURVES)
588 : {
589 0 : fprintf(fd, "\n");
590 0 : n = 1L << td->td_bitspersample;
591 0 : for (l = 0; l < n; l++)
592 : {
593 : uint16_t i;
594 0 : fprintf(fd, " %2ld: %5" PRIu16, l,
595 0 : td->td_transferfunction[0][l]);
596 0 : for (i = 1;
597 0 : i < td->td_samplesperpixel - td->td_extrasamples && i < 3;
598 0 : i++)
599 0 : fprintf(fd, " %5" PRIu16, td->td_transferfunction[i][l]);
600 0 : fputc('\n', fd);
601 : }
602 : }
603 : else
604 0 : fprintf(fd, "(present)\n");
605 : }
606 0 : if (TIFFFieldSet(tif, FIELD_SUBIFD) && (td->td_subifd))
607 : {
608 : uint16_t i;
609 0 : fprintf(fd, " SubIFD Offsets:");
610 0 : for (i = 0; i < td->td_nsubifd; i++)
611 0 : fprintf(fd, " %5" PRIu64, td->td_subifd[i]);
612 0 : fputc('\n', fd);
613 : }
614 :
615 : /*
616 : ** Custom tag support.
617 : */
618 : {
619 : int i;
620 : short count;
621 :
622 0 : count = (short)TIFFGetTagListCount(tif);
623 0 : for (i = 0; i < count; i++)
624 : {
625 0 : uint32_t tag = TIFFGetTagListEntry(tif, i);
626 : const TIFFField *fip;
627 : uint32_t value_count;
628 0 : int mem_alloc = 0;
629 0 : void *raw_data = NULL;
630 : uint16_t dotrange[2]; /* must be kept in that scope and not moved in
631 : the below TIFFTAG_DOTRANGE specific case */
632 :
633 0 : fip = TIFFFieldWithTag(tif, tag);
634 0 : if (fip == NULL)
635 0 : continue;
636 :
637 0 : if (fip->field_passcount)
638 : {
639 0 : if (fip->field_readcount == TIFF_VARIABLE2)
640 : {
641 0 : if (TIFFGetField(tif, tag, &value_count, &raw_data) != 1)
642 0 : continue;
643 : }
644 0 : else if (fip->field_readcount == TIFF_VARIABLE)
645 : {
646 : uint16_t small_value_count;
647 0 : if (TIFFGetField(tif, tag, &small_value_count, &raw_data) !=
648 : 1)
649 0 : continue;
650 0 : value_count = small_value_count;
651 : }
652 : else
653 : {
654 0 : assert(fip->field_readcount == TIFF_VARIABLE ||
655 : fip->field_readcount == TIFF_VARIABLE2);
656 0 : continue;
657 : }
658 : }
659 : else
660 : {
661 0 : if (fip->field_readcount == TIFF_VARIABLE ||
662 0 : fip->field_readcount == TIFF_VARIABLE2)
663 0 : value_count = 1;
664 0 : else if (fip->field_readcount == TIFF_SPP)
665 0 : value_count = td->td_samplesperpixel;
666 : else
667 0 : value_count = fip->field_readcount;
668 0 : if (fip->field_tag == TIFFTAG_DOTRANGE &&
669 0 : strcmp(fip->field_name, "DotRange") == 0)
670 : {
671 : /* TODO: This is an evil exception and should not have been
672 : handled this way ... likely best if we move it into
673 : the directory structure with an explicit field in
674 : libtiff 4.1 and assign it a FIELD_ value */
675 0 : raw_data = dotrange;
676 0 : TIFFGetField(tif, tag, dotrange + 0, dotrange + 1);
677 : }
678 0 : else if (fip->field_type == TIFF_ASCII ||
679 0 : fip->field_readcount == TIFF_VARIABLE ||
680 0 : fip->field_readcount == TIFF_VARIABLE2 ||
681 0 : fip->field_readcount == TIFF_SPP || value_count > 1)
682 : {
683 0 : if (TIFFGetField(tif, tag, &raw_data) != 1)
684 0 : continue;
685 : }
686 : else
687 : {
688 : /*--: Rational2Double: For Rationals evaluate
689 : * "set_get_field_type" to determine internal storage size.
690 : */
691 0 : int tv_size = TIFFFieldSetGetSize(fip);
692 0 : raw_data = _TIFFmallocExt(tif, tv_size * value_count);
693 0 : mem_alloc = 1;
694 0 : if (TIFFGetField(tif, tag, raw_data) != 1)
695 : {
696 0 : _TIFFfreeExt(tif, raw_data);
697 0 : continue;
698 : }
699 : }
700 : }
701 :
702 : /*
703 : * Catch the tags which needs to be specially handled
704 : * and pretty print them. If tag not handled in
705 : * _TIFFPrettyPrintField() fall down and print it as
706 : * any other tag.
707 : */
708 0 : if (raw_data != NULL &&
709 0 : !_TIFFPrettyPrintField(tif, fip, fd, tag, value_count,
710 : raw_data))
711 0 : _TIFFPrintField(fd, fip, value_count, raw_data);
712 :
713 0 : if (mem_alloc)
714 0 : _TIFFfreeExt(tif, raw_data);
715 : }
716 : }
717 :
718 0 : if (tif->tif_tagmethods.printdir)
719 0 : (*tif->tif_tagmethods.printdir)(tif, fd, flags);
720 :
721 0 : if ((flags & TIFFPRINT_STRIPS) && TIFFFieldSet(tif, FIELD_STRIPOFFSETS))
722 : {
723 : uint32_t s;
724 :
725 0 : fprintf(fd, " %" PRIu32 " %s:\n", td->td_nstrips,
726 0 : isTiled(tif) ? "Tiles" : "Strips");
727 0 : for (s = 0; s < td->td_nstrips; s++)
728 0 : fprintf(fd, " %3" PRIu32 ": [%8" PRIu64 ", %8" PRIu64 "]\n", s,
729 : TIFFGetStrileOffset(tif, s),
730 : TIFFGetStrileByteCount(tif, s));
731 : }
732 0 : }
733 :
734 0 : void _TIFFprintAscii(FILE *fd, const char *cp)
735 : {
736 0 : _TIFFprintAsciiBounded(fd, cp, strlen(cp));
737 0 : }
738 :
739 0 : static void _TIFFprintAsciiBounded(FILE *fd, const char *cp, size_t max_chars)
740 : {
741 0 : for (; max_chars > 0 && *cp != '\0'; cp++, max_chars--)
742 : {
743 : const char *tp;
744 :
745 0 : if (isprint((int)*cp))
746 : {
747 0 : fputc(*cp, fd);
748 0 : continue;
749 : }
750 0 : for (tp = "\tt\bb\rr\nn\vv"; *tp; tp++)
751 0 : if (*tp++ == *cp)
752 0 : break;
753 0 : if (*tp)
754 0 : fprintf(fd, "\\%c", *tp);
755 : else
756 0 : fprintf(fd, "\\%03o", (unsigned int)(*cp & 0xff));
757 : }
758 0 : }
759 :
760 0 : void _TIFFprintAsciiTag(FILE *fd, const char *name, const char *value)
761 : {
762 0 : fprintf(fd, " %s: \"", name);
763 0 : _TIFFprintAscii(fd, value);
764 0 : fprintf(fd, "\"\n");
765 0 : }
|