LibTIFF 4.7.2
TIFF library public API and implementation reference
Loading...
Searching...
No Matches
tif_print.c
Go to the documentation of this file.
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 */
35#include "tiffiop.h"
36#include <stdio.h>
37
38#include <ctype.h>
39
40static void _TIFFprintAsciiBounded(FILE *fd, const char *cp, size_t max_chars);
41
50static const char *const photoNames[] = {
51 "min-is-white", /* PHOTOMETRIC_MINISWHITE */
52 "min-is-black", /* PHOTOMETRIC_MINISBLACK */
53 "RGB color", /* PHOTOMETRIC_RGB */
54 "palette color (RGB from colormap)", /* PHOTOMETRIC_PALETTE */
55 "transparency mask", /* PHOTOMETRIC_MASK */
56 "separated", /* PHOTOMETRIC_SEPARATED */
57 "YCbCr", /* PHOTOMETRIC_YCBCR */
58 "7 (0x7)",
59 "CIE L*a*b*", /* PHOTOMETRIC_CIELAB */
60 "ICC L*a*b*", /* PHOTOMETRIC_ICCLAB */
61 "ITU L*a*b*" /* PHOTOMETRIC_ITULAB */
62};
69#define NPHOTONAMES (sizeof(photoNames) / sizeof(photoNames[0]))
70
78static const char *const orientNames[] = {
79 "0 (0x0)",
80 "row 0 top, col 0 lhs", /* ORIENTATION_TOPLEFT */
81 "row 0 top, col 0 rhs", /* ORIENTATION_TOPRIGHT */
82 "row 0 bottom, col 0 rhs", /* ORIENTATION_BOTRIGHT */
83 "row 0 bottom, col 0 lhs", /* ORIENTATION_BOTLEFT */
84 "row 0 lhs, col 0 top", /* ORIENTATION_LEFTTOP */
85 "row 0 rhs, col 0 top", /* ORIENTATION_RIGHTTOP */
86 "row 0 rhs, col 0 bottom", /* ORIENTATION_RIGHTBOT */
87 "row 0 lhs, col 0 bottom", /* ORIENTATION_LEFTBOT */
88};
95#define NORIENTNAMES (sizeof(orientNames) / sizeof(orientNames[0]))
96
106{
108 uint16_t tag;
110 const char *name;
111};
112
120static const struct tagname tagnames[] = {
121 {TIFFTAG_GDAL_METADATA, "GDAL Metadata"},
122 {TIFFTAG_GDAL_NODATA, "GDAL NoDataValue"},
123};
124
131#define NTAGS (sizeof(tagnames) / sizeof(tagnames[0]))
132
160static void _TIFFPrintField(FILE *fd, const TIFFField *fip,
161 uint32_t value_count, void *raw_data)
162{
163 uint32_t j;
164
165 /* Print a user-friendly name for tags of relatively common use, but */
166 /* which aren't registered by libtiff itself. */
167 const char *field_name = fip->field_name;
168 if (TIFFFieldIsAnonymous(fip))
169 {
170 for (size_t i = 0; i < NTAGS; ++i)
171 {
172 if (fip->field_tag == tagnames[i].tag)
173 {
174 field_name = tagnames[i].name;
175 break;
176 }
177 }
178 }
179 fprintf(fd, " %s: ", field_name);
180
181 for (j = 0; j < value_count; j++)
182 {
183 if (fip->field_type == TIFF_BYTE)
184 fprintf(fd, "%" PRIu8, ((uint8_t *)raw_data)[j]);
185 else if (fip->field_type == TIFF_UNDEFINED)
186 fprintf(fd, "0x%" PRIx8, ((uint8_t *)raw_data)[j]);
187 else if (fip->field_type == TIFF_SBYTE)
188 fprintf(fd, "%" PRId8, ((int8_t *)raw_data)[j]);
189 else if (fip->field_type == TIFF_SHORT)
190 fprintf(fd, "%" PRIu16, ((uint16_t *)raw_data)[j]);
191 else if (fip->field_type == TIFF_SSHORT)
192 fprintf(fd, "%" PRId16, ((int16_t *)raw_data)[j]);
193 else if (fip->field_type == TIFF_LONG)
194 fprintf(fd, "%" PRIu32, ((uint32_t *)raw_data)[j]);
195 else if (fip->field_type == TIFF_SLONG)
196 fprintf(fd, "%" PRId32, ((int32_t *)raw_data)[j]);
197 else if (fip->field_type == TIFF_IFD)
198 fprintf(fd, "0x%" PRIx32, ((uint32_t *)raw_data)[j]);
199 else if (fip->field_type == TIFF_RATIONAL ||
201 {
202 int tv_size = TIFFFieldSetGetSize(fip);
203 if (tv_size == 8)
204 fprintf(fd, "%lf", ((double *)raw_data)[j]);
205 else
206 fprintf(fd, "%f", (double)((float *)raw_data)[j]);
207 }
208 else if (fip->field_type == TIFF_FLOAT)
209 fprintf(fd, "%f", (double)((float *)raw_data)[j]);
210 else if (fip->field_type == TIFF_LONG8)
211 fprintf(fd, "%" PRIu64, ((uint64_t *)raw_data)[j]);
212 else if (fip->field_type == TIFF_SLONG8)
213 fprintf(fd, "%" PRId64, ((int64_t *)raw_data)[j]);
214 else if (fip->field_type == TIFF_IFD8)
215 fprintf(fd, "0x%" PRIx64, ((uint64_t *)raw_data)[j]);
216 else if (fip->field_type == TIFF_DOUBLE)
217 fprintf(fd, "%lf", ((double *)raw_data)[j]);
218 else if (fip->field_type == TIFF_ASCII)
219 {
220 fprintf(fd, "%s", (char *)raw_data);
221 break;
222 }
223 else
224 {
225 fprintf(fd, "<unsupported data type in TIFFPrint>");
226 break;
227 }
228
229 if (j < value_count - 1)
230 fprintf(fd, ",");
231 }
232
233 fprintf(fd, "\n");
234}
235
268static int _TIFFPrettyPrintField(TIFF *tif, const TIFFField *fip, FILE *fd,
269 uint32_t tag, uint32_t value_count,
270 void *raw_data)
271{
272 (void)tif;
273
274 /* do not try to pretty print auto-defined fields */
275 if (TIFFFieldIsAnonymous(fip))
276 {
277 return 0;
278 }
279
280 switch (tag)
281 {
282 case TIFFTAG_INKSET:
283 if (value_count == 2 && fip->field_type == TIFF_SHORT)
284 {
285 fprintf(fd, " Ink Set: ");
286 switch (*((uint16_t *)raw_data))
287 {
288 case INKSET_CMYK:
289 fprintf(fd, "CMYK\n");
290 break;
291 default:
292 fprintf(fd, "%" PRIu16 " (0x%" PRIx16 ")\n",
293 *((uint16_t *)raw_data),
294 *((uint16_t *)raw_data));
295 break;
296 }
297 return 1;
298 }
299 return 0;
300
301 case TIFFTAG_DOTRANGE:
302 if (value_count == 2 && fip->field_type == TIFF_SHORT)
303 {
304 fprintf(fd, " Dot Range: %" PRIu16 "-%" PRIu16 "\n",
305 ((uint16_t *)raw_data)[0], ((uint16_t *)raw_data)[1]);
306 return 1;
307 }
308 return 0;
309
311 if (value_count == 2 && fip->field_type == TIFF_RATIONAL)
312 {
313 fprintf(fd, " White Point: %g-%g\n",
314 (double)((float *)raw_data)[0],
315 (double)((float *)raw_data)[1]);
316 return 1;
317 }
318 return 0;
319
321 {
322 uint32_t i;
323
324 fprintf(fd, " XMLPacket (XMP Metadata):\n");
325 for (i = 0; i < value_count; i++)
326 fputc(((char *)raw_data)[i], fd);
327 fprintf(fd, "\n");
328 return 1;
329 }
331 fprintf(fd, " RichTIFFIPTC Data: <present>, %" PRIu32 " bytes\n",
332 value_count);
333 return 1;
334
336 fprintf(fd, " Photoshop Data: <present>, %" PRIu32 " bytes\n",
337 value_count);
338 return 1;
339
341 fprintf(fd, " ICC Profile: <present>, %" PRIu32 " bytes\n",
342 value_count);
343 return 1;
344
345 case TIFFTAG_STONITS:
346 if (value_count == 1 && fip->field_type == TIFF_DOUBLE)
347 {
348 fprintf(fd, " Sample to Nits conversion factor: %.4e\n",
349 *((double *)raw_data));
350 return 1;
351 }
352 return 0;
353
354 default:
355 break;
356 }
357
358 return 0;
359}
360
361/*
362 * Print the contents of the current directory
363 * to the specified stdio file stream.
364 */
365void TIFFPrintDirectory(TIFF *tif, FILE *fd, long flags)
366{
367 TIFFDirectory *td = &tif->tif_dir;
368 const char *sep;
369
370 fprintf(fd, "TIFF Directory at offset 0x%" PRIx64 " (%" PRIu64 ")\n",
371 tif->tif_diroff, tif->tif_diroff);
373 {
374 fprintf(fd, " Subfile Type:");
375 sep = " ";
377 {
378 fprintf(fd, "%sreduced-resolution image", sep);
379 sep = "/";
380 }
382 {
383 fprintf(fd, "%smulti-page document", sep);
384 sep = "/";
385 }
387 fprintf(fd, "%stransparency mask", sep);
388 fprintf(fd, " (%" PRIu32 " = 0x%" PRIx32 ")\n", td->td_subfiletype,
389 td->td_subfiletype);
390 }
392 {
393 fprintf(fd, " Image Width: %" PRIu32 " Image Length: %" PRIu32,
396 fprintf(fd, " Image Depth: %" PRIu32, td->td_imagedepth);
397 fprintf(fd, "\n");
398 }
400 {
401 fprintf(fd, " Tile Width: %" PRIu32 " Tile Length: %" PRIu32,
402 td->td_tilewidth, td->td_tilelength);
404 fprintf(fd, " Tile Depth: %" PRIu32, td->td_tiledepth);
405 fprintf(fd, "\n");
406 }
408 {
409 fprintf(fd, " Resolution: %g, %g", (double)td->td_xresolution,
410 (double)td->td_yresolution);
412 {
413 switch (td->td_resolutionunit)
414 {
415 case RESUNIT_NONE:
416 fprintf(fd, " (unitless)");
417 break;
418 case RESUNIT_INCH:
419 fprintf(fd, " pixels/inch");
420 break;
422 fprintf(fd, " pixels/cm");
423 break;
424 default:
425 fprintf(fd, " (unit %" PRIu16 " = 0x%" PRIx16 ")",
427 break;
428 }
429 }
430 fprintf(fd, "\n");
431 }
433 fprintf(fd, " Position: %g, %g\n", (double)td->td_xposition,
434 (double)td->td_yposition);
436 fprintf(fd, " Bits/Sample: %" PRIu16 "\n", td->td_bitspersample);
438 {
439 fprintf(fd, " Sample Format: ");
440 switch (td->td_sampleformat)
441 {
443 fprintf(fd, "void\n");
444 break;
445 case SAMPLEFORMAT_INT:
446 fprintf(fd, "signed integer\n");
447 break;
449 fprintf(fd, "unsigned integer\n");
450 break;
452 fprintf(fd, "IEEE floating point\n");
453 break;
455 fprintf(fd, "complex signed integer\n");
456 break;
458 fprintf(fd, "complex IEEE floating point\n");
459 break;
460 default:
461 fprintf(fd, "%" PRIu16 " (0x%" PRIx16 ")\n",
463 break;
464 }
465 }
467 {
468 const TIFFCodec *c = TIFFFindCODEC(td->td_compression);
469 fprintf(fd, " Compression Scheme: ");
470 if (c)
471 fprintf(fd, "%s\n", c->name);
472 else
473 fprintf(fd, "%" PRIu16 " (0x%" PRIx16 ")\n", td->td_compression,
474 td->td_compression);
475 }
477 {
478 fprintf(fd, " Photometric Interpretation: ");
479 if (td->td_photometric < NPHOTONAMES)
480 fprintf(fd, "%s\n", photoNames[td->td_photometric]);
481 else
482 {
483 switch (td->td_photometric)
484 {
485 case PHOTOMETRIC_LOGL:
486 fprintf(fd, "CIE Log2(L)\n");
487 break;
489 fprintf(fd, "CIE Log2(L) (u',v')\n");
490 break;
491 default:
492 fprintf(fd, "%" PRIu16 " (0x%" PRIx16 ")\n",
494 break;
495 }
496 }
497 }
499 td->td_sampleinfo)
500 {
501 uint16_t i;
502 fprintf(fd, " Extra Samples: %" PRIu16 "<", td->td_extrasamples);
503 sep = "";
504 for (i = 0; i < td->td_extrasamples; i++)
505 {
506 switch (td->td_sampleinfo[i])
507 {
509 fprintf(fd, "%sunspecified", sep);
510 break;
512 fprintf(fd, "%sassoc-alpha", sep);
513 break;
515 fprintf(fd, "%sunassoc-alpha", sep);
516 break;
517 default:
518 fprintf(fd, "%s%" PRIu16 " (0x%" PRIx16 ")", sep,
519 td->td_sampleinfo[i], td->td_sampleinfo[i]);
520 break;
521 }
522 sep = ", ";
523 }
524 fprintf(fd, ">\n");
525 }
527 {
528 char *cp;
529 uint16_t i;
530 fprintf(fd, " Ink Names: ");
531 i = td->td_samplesperpixel;
532 sep = "";
533 for (cp = td->td_inknames;
534 i > 0 && cp < td->td_inknames + td->td_inknameslen;
535 cp = strchr(cp, '\0') + 1, i--)
536 {
537 size_t max_chars =
538 (size_t)(td->td_inknameslen - (cp - td->td_inknames));
539 fputs(sep, fd);
540 _TIFFprintAsciiBounded(fd, cp, max_chars);
541 sep = ", ";
542 }
543 fputs("\n", fd);
544 }
546 {
547 fprintf(fd, " NumberOfInks: %d\n", td->td_numberofinks);
548 }
550 {
551 fprintf(fd, " Thresholding: ");
552 switch (td->td_threshholding)
553 {
555 fprintf(fd, "bilevel art scan\n");
556 break;
558 fprintf(fd, "halftone or dithered scan\n");
559 break;
561 fprintf(fd, "error diffused\n");
562 break;
563 default:
564 fprintf(fd, "%" PRIu16 " (0x%" PRIx16 ")\n",
566 break;
567 }
568 }
570 {
571 fprintf(fd, " FillOrder: ");
572 switch (td->td_fillorder)
573 {
575 fprintf(fd, "msb-to-lsb\n");
576 break;
578 fprintf(fd, "lsb-to-msb\n");
579 break;
580 default:
581 fprintf(fd, "%" PRIu16 " (0x%" PRIx16 ")\n", td->td_fillorder,
582 td->td_fillorder);
583 break;
584 }
585 }
587 {
588 fprintf(fd, " YCbCr Subsampling: %" PRIu16 ", %" PRIu16 "\n",
590 }
592 {
593 fprintf(fd, " YCbCr Positioning: ");
594 switch (td->td_ycbcrpositioning)
595 {
597 fprintf(fd, "centered\n");
598 break;
600 fprintf(fd, "cosited\n");
601 break;
602 default:
603 fprintf(fd, "%" PRIu16 " (0x%" PRIx16 ")\n",
605 break;
606 }
607 }
609 fprintf(fd, " Halftone Hints: light %" PRIu16 " dark %" PRIu16 "\n",
610 td->td_halftonehints[0], td->td_halftonehints[1]);
612 {
613 fprintf(fd, " Orientation: ");
615 fprintf(fd, "%s\n", orientNames[td->td_orientation]);
616 else
617 fprintf(fd, "%" PRIu16 " (0x%" PRIx16 ")\n", td->td_orientation,
618 td->td_orientation);
619 }
621 fprintf(fd, " Samples/Pixel: %" PRIx16 "\n", td->td_samplesperpixel);
623 {
624 fprintf(fd, " Rows/Strip: ");
625 if (td->td_rowsperstrip == (uint32_t)-1)
626 fprintf(fd, "(infinite)\n");
627 else
628 fprintf(fd, "%" PRIu32 "\n", td->td_rowsperstrip);
629 }
631 fprintf(fd, " Min Sample Value: %" PRIu16 "\n", td->td_minsamplevalue);
633 fprintf(fd, " Max Sample Value: %" PRIu16 "\n", td->td_maxsamplevalue);
635 {
636 int i;
637 int count =
639 fprintf(fd, " SMin Sample Value:");
640 for (i = 0; i < count; ++i)
641 fprintf(fd, " %g", td->td_sminsamplevalue[i]);
642 fprintf(fd, "\n");
643 }
645 {
646 int i;
647 int count =
649 fprintf(fd, " SMax Sample Value:");
650 for (i = 0; i < count; ++i)
651 fprintf(fd, " %g", td->td_smaxsamplevalue[i]);
652 fprintf(fd, "\n");
653 }
655 {
656 fprintf(fd, " Planar Configuration: ");
657 switch (td->td_planarconfig)
658 {
660 fprintf(fd, "single image plane\n");
661 break;
663 fprintf(fd, "separate image planes\n");
664 break;
665 default:
666 fprintf(fd, "%" PRIu16 " (0x%" PRIx16 ")\n",
668 break;
669 }
670 }
672 fprintf(fd, " Page Number: %" PRIu16 "-%" PRIu16 "\n",
673 td->td_pagenumber[0], td->td_pagenumber[1]);
674 if (TIFFFieldSet(tif, FIELD_COLORMAP) && td->td_colormap[0] &&
675 td->td_colormap[1] && td->td_colormap[2])
676 {
677 fprintf(fd, " Color Map: ");
678 if (flags & TIFFPRINT_COLORMAP)
679 {
680 fprintf(fd, "\n");
681 for (uint32_t l = 0; l < td->td_colormap_count; l++)
682 fprintf(fd,
683 " %5" PRIu32 ": %5" PRIu16 " %5" PRIu16 " %5" PRIu16
684 "\n",
685 l, td->td_colormap[0][l], td->td_colormap[1][l],
686 td->td_colormap[2][l]);
687 }
688 else
689 fprintf(fd, "(present)\n");
690 }
692 {
693 int i;
694 fprintf(fd, " Reference Black/White:\n");
695 for (i = 0; i < 3; i++)
696 fprintf(fd, " %2d: %5g %5g\n", i,
697 (double)td->td_refblackwhite[2 * i + 0],
698 (double)td->td_refblackwhite[2 * i + 1]);
699 }
701 td->td_transferfunction[0] &&
702 ((td->td_samplesperpixel - td->td_extrasamples > 1 &&
703 td->td_transferfunction[1] && td->td_transferfunction[2]) ||
704 td->td_samplesperpixel - td->td_extrasamples <= 1))
705 {
706 fprintf(fd, " Transfer Function: ");
707 if (flags & TIFFPRINT_CURVES)
708 {
709 fprintf(fd, "\n");
710 for (uint32_t l = 0; l < td->td_transferfunction_count; l++)
711 {
712 uint16_t i;
713 fprintf(fd, " %2" PRIu32 ": %5" PRIu16, l,
714 td->td_transferfunction[0][l]);
715 for (i = 1;
716 i < td->td_samplesperpixel - td->td_extrasamples && i < 3;
717 i++)
718 fprintf(fd, " %5" PRIu16, td->td_transferfunction[i][l]);
719 fputc('\n', fd);
720 }
721 }
722 else
723 fprintf(fd, "(present)\n");
724 }
725 if (TIFFFieldSet(tif, FIELD_SUBIFD) && (td->td_subifd))
726 {
727 uint16_t i;
728 fprintf(fd, " SubIFD Offsets:");
729 for (i = 0; i < td->td_nsubifd; i++)
730 fprintf(fd, " %5" PRIu64, td->td_subifd[i]);
731 fputc('\n', fd);
732 }
733
734 /*
735 ** Custom tag support.
736 */
737 {
738 int i;
739 short count;
740
741 count = (short)TIFFGetTagListCount(tif);
742 for (i = 0; i < count; i++)
743 {
744 uint32_t tag = TIFFGetTagListEntry(tif, i);
745 const TIFFField *fip;
746 uint32_t value_count;
747 int mem_alloc = 0;
748 void *raw_data = NULL;
749 uint16_t dotrange[2]; /* must be kept in that scope and not moved in
750 the below TIFFTAG_DOTRANGE specific case */
751
752 fip = TIFFFieldWithTag(tif, tag);
753 if (fip == NULL)
754 continue;
755
756 if (fip->field_passcount)
757 {
759 {
760 if (TIFFGetField(tif, tag, &value_count, &raw_data) != 1)
761 continue;
762 }
763 else if (fip->field_readcount == TIFF_VARIABLE)
764 {
765 uint16_t small_value_count;
766 if (TIFFGetField(tif, tag, &small_value_count, &raw_data) !=
767 1)
768 continue;
769 value_count = small_value_count;
770 }
771 else
772 {
773 assert(fip->field_readcount == TIFF_VARIABLE ||
775 continue;
776 }
777 }
778 else
779 {
780 if (fip->field_readcount == TIFF_VARIABLE ||
782 value_count = 1;
783 else if (fip->field_readcount == TIFF_SPP)
784 value_count = td->td_samplesperpixel;
785 else
786 value_count = (uint32_t)fip->field_readcount;
787 if (fip->field_tag == TIFFTAG_DOTRANGE &&
788 strcmp(fip->field_name, "DotRange") == 0)
789 {
790 /* TODO: This is an evil exception and should not have been
791 handled this way ... likely best if we move it into
792 the directory structure with an explicit field in
793 libtiff 4.1 and assign it a FIELD_ value */
794 raw_data = dotrange;
795 TIFFGetField(tif, tag, dotrange + 0, dotrange + 1);
796 }
797 else if (fip->field_type == TIFF_ASCII ||
800 fip->field_readcount == TIFF_SPP || value_count > 1)
801 {
802 if (TIFFGetField(tif, tag, &raw_data) != 1)
803 continue;
804 }
805 else
806 {
807 /*--: Rational2Double: For Rationals evaluate
808 * "set_get_field_type" to determine internal storage size.
809 */
810 int tv_size = TIFFFieldSetGetSize(fip);
811 raw_data = _TIFFCheckMalloc(tif, value_count, tv_size,
812 "for tag data");
813 if (raw_data == NULL)
814 continue;
815 mem_alloc = 1;
816 if (TIFFGetField(tif, tag, raw_data) != 1)
817 {
818 _TIFFfreeExt(tif, raw_data);
819 continue;
820 }
821 }
822 }
823
824 /*
825 * Catch the tags which needs to be specially handled
826 * and pretty print them. If tag not handled in
827 * _TIFFPrettyPrintField() fall down and print it as
828 * any other tag.
829 */
830 if (raw_data != NULL &&
831 !_TIFFPrettyPrintField(tif, fip, fd, tag, value_count,
832 raw_data))
833 _TIFFPrintField(fd, fip, value_count, raw_data);
834
835 if (mem_alloc)
836 _TIFFfreeExt(tif, raw_data);
837 }
838 }
839
840 if (tif->tif_tagmethods.printdir)
841 (*tif->tif_tagmethods.printdir)(tif, fd, flags);
842
843 if ((flags & TIFFPRINT_STRIPS) && TIFFFieldSet(tif, FIELD_STRIPOFFSETS))
844 {
845 uint32_t s;
846
847 fprintf(fd, " %" PRIu32 " %s:\n", td->td_nstrips,
848 isTiled(tif) ? "Tiles" : "Strips");
849 for (s = 0; s < td->td_nstrips; s++)
850 fprintf(fd, " %3" PRIu32 ": [%8" PRIu64 ", %8" PRIu64 "]\n", s,
851 TIFFGetStrileOffset(tif, s),
852 TIFFGetStrileByteCount(tif, s));
853 }
854}
855
856void _TIFFprintAscii(FILE *fd, const char *cp)
857{
858 _TIFFprintAsciiBounded(fd, cp, strlen(cp));
859}
860
885static void _TIFFprintAsciiBounded(FILE *fd, const char *cp, size_t max_chars)
886{
887 for (; max_chars > 0 && *cp != '\0'; cp++, max_chars--)
888 {
889 const char *tp;
890
891 if (isprint((int)*cp))
892 {
893 fputc(*cp, fd);
894 continue;
895 }
896 for (tp = "\tt\bb\rr\nn\vv"; *tp; tp++)
897 if (*tp++ == *cp)
898 break;
899 if (*tp)
900 fprintf(fd, "\\%c", *tp);
901 else
902 fprintf(fd, "\\%03o", (unsigned int)(*cp & 0xff));
903 }
904}
905
906void _TIFFprintAsciiTag(FILE *fd, const char *name, const char *value)
907{
908 fprintf(fd, " %s: \"", name);
909 _TIFFprintAscii(fd, value);
910 fprintf(fd, "\"\n");
911}
static int _TIFFPrettyPrintField(TIFF *tif, const TIFFField *fip, FILE *fd, uint32_t tag, uint32_t value_count, void *raw_data)
Try specialised formatting for selected named custom tags.
Definition tif_print.c:268
#define NORIENTNAMES
Count orientation display entries, including the zero placeholder.
Definition tif_print.c:95
#define NPHOTONAMES
Count the entries in photoNames, including the reserved placeholder.
Definition tif_print.c:69
#define NTAGS
Count the anonymous-tag friendly-name overrides.
Definition tif_print.c:131
static void _TIFFPrintField(FILE *fd, const TIFFField *fip, uint32_t value_count, void *raw_data)
Print a custom field using its generic numeric or string representation.
Definition tif_print.c:160
void _TIFFprintAsciiTag(FILE *fd, const char *name, const char *value)
Print a labelled quoted value using the private ASCII formatter.
Definition tif_print.c:906
static const struct tagname tagnames[]
Supply display labels for anonymous GDAL metadata and nodata tags.
Definition tif_print.c:120
static void _TIFFprintAsciiBounded(FILE *fd, const char *cp, size_t max_chars)
Print at most a byte bound using the private ASCII escape convention.
Definition tif_print.c:885
static const char *const photoNames[]
Map common photometric identifiers to display names.
Definition tif_print.c:50
void _TIFFprintAscii(FILE *fd, const char *cp)
Print a terminated string using the private ASCII escape convention.
Definition tif_print.c:856
static const char *const orientNames[]
Map orientation identifiers to display descriptions.
Definition tif_print.c:78
#define FIELD_RESOLUTION
Index the resolution presence bit; not an on-disk tag number.
Definition tif_dir.h:429
#define FIELD_SUBFILETYPE
Index the subfile type presence bit; not an on-disk tag number.
Definition tif_dir.h:441
#define FIELD_STRIPOFFSETS
Index the strile offsets presence bit; not an on-disk tag number.
Definition tif_dir.h:519
#define FIELD_TRANSFERFUNCTION
Index the transfer function presence bit; not an on-disk tag number.
Definition tif_dir.h:580
#define FIELD_HALFTONEHINTS
Index the halftone hints presence bit; not an on-disk tag number.
Definition tif_dir.h:559
#define FIELD_ORIENTATION
Index the orientation presence bit; not an on-disk tag number.
Definition tif_dir.h:471
#define FIELD_MINSAMPLEVALUE
Index the minimum sample value presence bit; not an on-disk tag number.
Definition tif_dir.h:487
#define FIELD_FILLORDER
Index the fill order presence bit; not an on-disk tag number.
Definition tif_dir.h:466
#define FIELD_SMAXSAMPLEVALUE
Index the per-sample maximum presence bit; not an on-disk tag number.
Definition tif_dir.h:544
#define FIELD_IMAGEDIMENSIONS
Index the image dimensions presence bit; not an on-disk tag number.
Definition tif_dir.h:419
#define FIELD_YCBCRSUBSAMPLING
Index the YCbCr subsampling presence bit; not an on-disk tag number.
Definition tif_dir.h:564
#define FIELD_COLORMAP
Index the colormap presence bit; not an on-disk tag number.
Definition tif_dir.h:524
#define FIELD_SUBIFD
Index the child IFD presence bit; not an on-disk tag number.
Definition tif_dir.h:590
#define FIELD_EXTRASAMPLES
Index the extra samples presence bit; not an on-disk tag number.
Definition tif_dir.h:529
#define FIELD_IMAGEDEPTH
Index the image depth presence bit; not an on-disk tag number.
Definition tif_dir.h:549
#define FIELD_SMINSAMPLEVALUE
Index the per-sample minimum presence bit; not an on-disk tag number.
Definition tif_dir.h:539
#define TIFFFieldSet(tif, field)
Test a directory presence bit.
Definition tif_dir.h:662
#define FIELD_MAXSAMPLEVALUE
Index the maximum sample value presence bit; not an on-disk tag number.
Definition tif_dir.h:493
#define FIELD_NUMBEROFINKS
Index the number of inks presence bit; not an on-disk tag number.
Definition tif_dir.h:595
#define FIELD_TILEDEPTH
Index the tile depth presence bit; not an on-disk tag number.
Definition tif_dir.h:554
#define FIELD_TILEDIMENSIONS
Index the tile dimensions presence bit; not an on-disk tag number.
Definition tif_dir.h:424
#define FIELD_POSITION
Index the position presence bit; not an on-disk tag number.
Definition tif_dir.h:434
#define FIELD_ROWSPERSTRIP
Index the rows per strip presence bit; not an on-disk tag number.
Definition tif_dir.h:481
#define FIELD_COMPRESSION
Index the compression presence bit; not an on-disk tag number.
Definition tif_dir.h:451
#define FIELD_YCBCRPOSITIONING
Index the YCbCr positioning presence bit; not an on-disk tag number.
Definition tif_dir.h:569
#define FIELD_REFBLACKWHITE
Index the reference black/white presence bit; not an on-disk tag number.
Definition tif_dir.h:575
#define FIELD_SAMPLEFORMAT
Index the sample format presence bit; not an on-disk tag number.
Definition tif_dir.h:534
#define FIELD_PAGENUMBER
Index the page number presence bit; not an on-disk tag number.
Definition tif_dir.h:509
#define FIELD_BITSPERSAMPLE
Index the bits per sample presence bit; not an on-disk tag number.
Definition tif_dir.h:446
#define FIELD_INKNAMES
Index the ink names presence bit; not an on-disk tag number.
Definition tif_dir.h:585
#define FIELD_RESOLUTIONUNIT
Index the resolution unit presence bit; not an on-disk tag number.
Definition tif_dir.h:504
#define FIELD_PLANARCONFIG
Index the planar configuration presence bit; not an on-disk tag number.
Definition tif_dir.h:499
#define FIELD_SAMPLESPERPIXEL
Index the samples per pixel presence bit; not an on-disk tag number.
Definition tif_dir.h:476
#define FIELD_PHOTOMETRIC
Index the photometric presence bit; not an on-disk tag number.
Definition tif_dir.h:456
#define FIELD_THRESHHOLDING
Index the thresholding presence bit; not an on-disk tag number.
Definition tif_dir.h:461
void _TIFFfreeExt(TIFF *tif, void *p)
Release a handle-aware allocation and its payload charge.
Definition tif_open.c:301
void * _TIFFCheckMalloc(TIFF *tif, tmsize_t nmemb, tmsize_t elem_size, const char *what)
Allocate a checked array with an allocation-failure diagnostic.
Definition tif_aux.c:274
#define isTiled(tif)
Test whether a handle uses tiled storage.
Definition tiffiop.h:833
#define TIFF_PERSAMPLE
Select per-sample arrays for supported sample-valued fields.
Definition tiffiop.h:523
const TIFFCodec * TIFFFindCODEC(uint16_t scheme)
Find the highest-priority descriptor for a compression scheme.
#define TIFFPRINT_STRIPS
Include strip/tile offsets and byte counts in directory printing.
Definition tiffio.h:190
#define TIFFPRINT_COLORMAP
Include palette entries in directory printing.
Definition tiffio.h:209
#define TIFF_SPP
Mark a field whose count follows SamplesPerPixel.
Definition tiffio.h:1302
#define TIFF_VARIABLE
Mark a variable-length field with a 16-bit count convention.
Definition tiffio.h:1297
#define TIFFPRINT_CURVES
Include transfer-function curves in directory printing.
Definition tiffio.h:199
#define TIFF_VARIABLE2
Mark a variable-length field with a 32-bit count convention.
Definition tiffio.h:1310
void TIFFPrintDirectory(TIFF *tif, FILE *fd, long flags)
Print a human-readable description of the current directory.
Definition tif_print.c:365
uint32_t TIFFGetTagListEntry(TIFF *tif, int tag_index)
Look up a tag number by its custom-value list index.
int TIFFFieldIsAnonymous(const TIFFField *fip)
Test whether a field was registered as an unknown tag.
const TIFFField * TIFFFieldWithTag(TIFF *tif, uint32_t tag)
Find a registered field by tag number.
int TIFFGetTagListCount(TIFF *tif)
Count values stored in the current custom-tag list.
int TIFFFieldSetGetSize(const TIFFField *fip)
Report the internal element storage width of a field.
uint64_t TIFFGetStrileOffset(TIFF *tif, uint32_t strile)
Query one logical strile file offset.
uint64_t TIFFGetStrileByteCount(TIFF *tif, uint32_t strile)
Query one logical strile byte count.
int TIFFGetField(TIFF *tif, uint32_t tag,...)
Query a present tag in the current directory.
Definition tif_dir.c:2099
#define PLANARCONFIG_SEPARATE
Separate planes of data.
Definition tiff.h:474
#define THRESHHOLD_HALFTONE
Ordered dither or halftone scan.
Definition tiff.h:414
#define TIFFTAG_GDAL_METADATA
TIFF tag: Used by the GDAL library.
Definition tiff.h:945
#define TIFFTAG_WHITEPOINT
TIFF tag: Image white point.
Definition tiff.h:556
#define TIFFTAG_DOTRANGE
TIFF tag: 0% and 100% dot codes (introduced in TIFF 6.0).
Definition tiff.h:596
#define EXTRASAMPLE_UNASSALPHA
Unassociated alpha data (introduced in TIFF 6.0).
Definition tiff.h:606
#define YCBCRPOSITION_CENTERED
As in PostScript Level 2 (introduced in TIFF 6.0).
Definition tiff.h:733
#define YCBCRPOSITION_COSITED
As in CCIR 601-1 (introduced in TIFF 6.0).
Definition tiff.h:735
#define RESUNIT_CENTIMETER
Resolution measured in pixels per centimetre.
Definition tiff.h:522
#define EXTRASAMPLE_ASSOCALPHA
Associated alpha data (introduced in TIFF 6.0).
Definition tiff.h:604
#define FILETYPE_MASK
Transparency mask.
Definition tiff.h:281
#define TIFFTAG_XMLPACKET
TIFF tag: XMP XML packet (introduced after TIFF 6.0).
Definition tiff.h:741
#define PHOTOMETRIC_LOGL
CIE Log2(L).
Definition tiff.h:406
#define TIFFTAG_INKSET
TIFF tag: Inks in separated image (introduced in TIFF 6.0).
Definition tiff.h:586
#define TIFFTAG_GDAL_NODATA
TIFF tag: Used by the GDAL library.
Definition tiff.h:947
#define FILLORDER_LSB2MSB
Least significant -> most.
Definition tiff.h:426
#define SAMPLEFORMAT_COMPLEXINT
Complex signed int (introduced in TIFF 6.0).
Definition tiff.h:618
#define SAMPLEFORMAT_UINT
Unsigned integer data (introduced in TIFF 6.0).
Definition tiff.h:610
#define EXTRASAMPLE_UNSPECIFIED
Unspecified data (introduced in TIFF 6.0).
Definition tiff.h:602
#define RESUNIT_NONE
No meaningful units.
Definition tiff.h:518
#define FILETYPE_REDUCEDIMAGE
Reduced resolution version.
Definition tiff.h:277
#define THRESHHOLD_ERRORDIFFUSE
Usually floyd-steinberg.
Definition tiff.h:416
#define PHOTOMETRIC_LOGLUV
CIE Log2(L) (u',v').
Definition tiff.h:408
#define FILETYPE_PAGE
One page of many.
Definition tiff.h:279
#define SAMPLEFORMAT_IEEEFP
IEEE floating point data (introduced in TIFF 6.0).
Definition tiff.h:614
#define INKSET_CMYK
Cyan-magenta-yellow-black color (introduced in TIFF 6.0).
Definition tiff.h:588
#define TIFFTAG_ICCPROFILE
TIFF tag: ICC profile data.
Definition tiff.h:908
#define FILLORDER_MSB2LSB
Most significant -> least.
Definition tiff.h:424
#define SAMPLEFORMAT_COMPLEXIEEEFP
Complex ieee floating (introduced in TIFF 6.0).
Definition tiff.h:620
#define RESUNIT_INCH
Resolution measured in pixels per inch.
Definition tiff.h:520
#define THRESHHOLD_BILEVEL
B&w art scan.
Definition tiff.h:412
#define TIFFTAG_STONITS
TIFF tag: Sample value to Nits.
Definition tiff.h:933
#define TIFFTAG_PHOTOSHOP
TIFF tag: Photoshop image resource data.
Definition tiff.h:898
#define SAMPLEFORMAT_VOID
Untyped data (introduced in TIFF 6.0).
Definition tiff.h:616
#define SAMPLEFORMAT_INT
Signed integer data (introduced in TIFF 6.0).
Definition tiff.h:612
#define TIFFTAG_RICHTIFFIPTC
TIFF tag: RichTIFF IPTC metadata.
Definition tiff.h:844
#define PLANARCONFIG_CONTIG
Single image plane.
Definition tiff.h:472
@ TIFF_SSHORT
Signed 16-bit integer.
Definition tiff.h:247
@ TIFF_SLONG
Signed 32-bit integer.
Definition tiff.h:249
@ TIFF_BYTE
Unsigned 8-bit integer.
Definition tiff.h:233
@ TIFF_SBYTE
Signed 8-bit integer.
Definition tiff.h:243
@ TIFF_IFD
Unsigned 32-bit IFD byte offset.
Definition tiff.h:257
@ TIFF_SHORT
Unsigned 16-bit integer.
Definition tiff.h:237
@ TIFF_UNDEFINED
Untyped 8-bit data.
Definition tiff.h:245
@ TIFF_LONG
Unsigned 32-bit integer.
Definition tiff.h:239
@ TIFF_SLONG8
BigTIFF signed 64-bit integer.
Definition tiff.h:261
@ TIFF_LONG8
BigTIFF unsigned 64-bit integer.
Definition tiff.h:259
@ TIFF_ASCII
Sequence of 8-bit bytes ending in a null byte.
Definition tiff.h:235
@ TIFF_FLOAT
32-bit IEEE floating-point value.
Definition tiff.h:253
@ TIFF_DOUBLE
64-bit IEEE floating-point value.
Definition tiff.h:255
@ TIFF_IFD8
BigTIFF unsigned 64-bit IFD byte offset.
Definition tiff.h:263
@ TIFF_SRATIONAL
Signed 32-bit numerator and denominator.
Definition tiff.h:251
@ TIFF_RATIONAL
Unsigned 32-bit numerator and denominator.
Definition tiff.h:241
Describe a named compression scheme and its initialiser.
Definition tiffio.h:706
const char * name
Codec name; storage lifetime follows the API supplying this descriptor.
Definition tiffio.h:711
Store the current directory values and image traversal state.
Definition tif_dir.h:143
uint16_t td_pagenumber[2]
Page index and total-page count as two uint16_t values.
Definition tif_dir.h:206
float td_xposition
Horizontal image position in resolution units.
Definition tif_dir.h:202
uint32_t td_tiledepth
Tile depth in slices.
Definition tif_dir.h:164
uint16_t td_fillorder
FILLORDER_* bit order within file bytes.
Definition tif_dir.h:178
float td_xresolution
Horizontal pixels per resolution unit.
Definition tif_dir.h:194
int td_inknameslen
Byte length of the concatenated ink-name strings, including terminators.
Definition tif_dir.h:333
uint16_t * td_sampleinfo
Owned ExtraSamples interpretation array of td_extrasamples entries, or NULL.
Definition tif_dir.h:237
float * td_refblackwhite
Owned six-float reference black/white array, or NULL.
Definition tif_dir.h:327
uint32_t td_rowsperstrip
Rows per strip; UINT32_MAX represents one whole-image strip.
Definition tif_dir.h:184
uint32_t td_imagewidth
Image width in pixels.
Definition tif_dir.h:154
uint16_t td_compression
COMPRESSION_* codec identifier.
Definition tif_dir.h:172
uint16_t td_photometric
PHOTOMETRIC_* interpretation.
Definition tif_dir.h:174
uint32_t td_tilewidth
Tile width in pixels.
Definition tif_dir.h:160
float td_yresolution
Vertical pixels per resolution unit.
Definition tif_dir.h:196
uint16_t td_extrasamples
Number of extra samples described by td_sampleinfo.
Definition tif_dir.h:232
uint16_t td_threshholding
THRESHHOLD_* bilevel rendering convention.
Definition tif_dir.h:176
uint16_t td_minsamplevalue
Legacy unsigned minimum sample value.
Definition tif_dir.h:186
double * td_sminsamplevalue
Owned SamplesPerPixel-length array of minimum values, or NULL.
Definition tif_dir.h:190
uint16_t td_bitspersample
Bits in each sample.
Definition tif_dir.h:168
char * td_inknames
Owned concatenated null-terminated ink names, or NULL.
Definition tif_dir.h:335
uint16_t * td_transferfunction[3]
Up to three owned gamma curves of td_transferfunction_count entries each.
Definition tif_dir.h:320
uint16_t td_maxsamplevalue
Legacy unsigned maximum sample value.
Definition tif_dir.h:188
uint32_t td_imagedepth
Image depth in slices.
Definition tif_dir.h:158
uint16_t td_orientation
ORIENTATION_* storage orientation.
Definition tif_dir.h:180
uint16_t td_resolutionunit
RESUNIT_* unit for resolution and position values.
Definition tif_dir.h:198
uint32_t td_colormap_count
Number of entries in each ColorMap plane that the directory uses, zero when none is installed.
Definition tif_dir.h:223
uint16_t td_planarconfig
PLANARCONFIG_* sample-plane arrangement.
Definition tif_dir.h:200
double * td_smaxsamplevalue
Owned SamplesPerPixel-length array of maximum values, or NULL.
Definition tif_dir.h:192
uint16_t * td_colormap[3]
Three owned palette planes of td_colormap_alloc entries each, or NULL slots; presence is FIELD_COLORM...
Definition tif_dir.h:218
uint16_t td_sampleformat
SAMPLEFORMAT_* interpretation of samples.
Definition tif_dir.h:170
uint16_t td_ycbcrsubsampling[2]
Horizontal and vertical YCbCr subsampling factors.
Definition tif_dir.h:312
uint16_t td_samplesperpixel
Samples per pixel, including extra samples.
Definition tif_dir.h:182
uint32_t td_subfiletype
NewSubfileType flag mask.
Definition tif_dir.h:166
uint32_t td_nstrips
Total strile count across all planes; logical array length.
Definition tif_dir.h:271
uint16_t td_numberofinks
Number of inks, kept consistent with accepted InkNames where possible.
Definition tif_dir.h:340
uint32_t td_imagelength
Image length in rows.
Definition tif_dir.h:156
uint32_t td_tilelength
Tile length in rows.
Definition tif_dir.h:162
uint16_t td_nsubifd
Number of child-directory offsets in td_subifd.
Definition tif_dir.h:307
uint64_t * td_subifd
Owned array of td_nsubifd child-directory offsets, or NULL.
Definition tif_dir.h:309
float td_yposition
Vertical image position in resolution units.
Definition tif_dir.h:204
uint32_t td_transferfunction_count
Number of entries in each installed TransferFunction curve, zero when none is installed; the only rec...
Definition tif_dir.h:325
uint16_t td_ycbcrpositioning
YCBCRPOSITION_* placement convention.
Definition tif_dir.h:314
uint16_t td_halftonehints[2]
Highlight and shadow grayscale breakpoints.
Definition tif_dir.h:230
TIFFPrintMethod printdir
Optional codec/extension directory-print callback.
Definition tiffio.h:1579
Describe a field's file type and internal argument contract.
Definition tif_dir.h:993
TIFFDataType field_type
On-disk TIFFDataType, distinct from the argument representation.
Definition tif_dir.h:1009
unsigned char field_passcount
Nonzero for an explicit count argument; tag-specific exceptions still apply.
Definition tif_dir.h:1033
const char * field_name
Borrowed or anonymous-owned null-terminated name; must remain live while used.
Definition tif_dir.h:1038
uint32_t field_tag
Tag identifier in this schema namespace.
Definition tif_dir.h:995
short field_readcount
Fixed getter count or TIFF_VARIABLE/TIFF_VARIABLE2/TIFF_SPP rule.
Definition tif_dir.h:1001
Associate an anonymous on-disk tag with a friendly print label.
Definition tif_print.c:106
const char * name
Borrowed static null-terminated display name.
Definition tif_print.c:110
uint16_t tag
On-disk tag identifier to relabel.
Definition tif_print.c:108
Hold private state for one open TIFF library instance.
Definition tiffiop.h:389
TIFFTagMethods tif_tagmethods
Inline table of directory field and print callbacks.
Definition tiffiop.h:742
uint64_t tif_diroff
Current directory byte offset, or zero for an unlinked in-memory IFD.
Definition tiffiop.h:558
TIFFDirectory tif_dir
Inline representation of the current image directory.
Definition tiffiop.h:572
uint32_t tif_flags
Bitmask combining the TIFF_* handle-state flags declared below.
Definition tiffiop.h:404
Declare private library state, callbacks, and implementation helpers.