LCOV - code coverage report
Current view: top level - frmts/gtiff/libtiff - tif_print.c (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 0 443 0.0 %
Date: 2026-02-21 16:21:44 Functions: 0 6 0.0 %

          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             :     {
     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 = td->td_inknameslen - (cp - td->td_inknames);
     419           0 :             fputs(sep, fd);
     420           0 :             _TIFFprintAsciiBounded(fd, cp, max_chars);
     421           0 :             sep = ", ";
     422             :         }
     423           0 :         fputs("\n", fd);
     424             :     }
     425           0 :     if (TIFFFieldSet(tif, FIELD_NUMBEROFINKS))
     426             :     {
     427           0 :         fprintf(fd, "  NumberOfInks: %d\n", td->td_numberofinks);
     428             :     }
     429           0 :     if (TIFFFieldSet(tif, FIELD_THRESHHOLDING))
     430             :     {
     431           0 :         fprintf(fd, "  Thresholding: ");
     432           0 :         switch (td->td_threshholding)
     433             :         {
     434           0 :             case THRESHHOLD_BILEVEL:
     435           0 :                 fprintf(fd, "bilevel art scan\n");
     436           0 :                 break;
     437           0 :             case THRESHHOLD_HALFTONE:
     438           0 :                 fprintf(fd, "halftone or dithered scan\n");
     439           0 :                 break;
     440           0 :             case THRESHHOLD_ERRORDIFFUSE:
     441           0 :                 fprintf(fd, "error diffused\n");
     442           0 :                 break;
     443           0 :             default:
     444           0 :                 fprintf(fd, "%" PRIu16 " (0x%" PRIx16 ")\n",
     445           0 :                         td->td_threshholding, td->td_threshholding);
     446           0 :                 break;
     447             :         }
     448           0 :     }
     449           0 :     if (TIFFFieldSet(tif, FIELD_FILLORDER))
     450             :     {
     451           0 :         fprintf(fd, "  FillOrder: ");
     452           0 :         switch (td->td_fillorder)
     453             :         {
     454           0 :             case FILLORDER_MSB2LSB:
     455           0 :                 fprintf(fd, "msb-to-lsb\n");
     456           0 :                 break;
     457           0 :             case FILLORDER_LSB2MSB:
     458           0 :                 fprintf(fd, "lsb-to-msb\n");
     459           0 :                 break;
     460           0 :             default:
     461           0 :                 fprintf(fd, "%" PRIu16 " (0x%" PRIx16 ")\n", td->td_fillorder,
     462           0 :                         td->td_fillorder);
     463           0 :                 break;
     464             :         }
     465           0 :     }
     466           0 :     if (TIFFFieldSet(tif, FIELD_YCBCRSUBSAMPLING))
     467             :     {
     468           0 :         fprintf(fd, "  YCbCr Subsampling: %" PRIu16 ", %" PRIu16 "\n",
     469           0 :                 td->td_ycbcrsubsampling[0], td->td_ycbcrsubsampling[1]);
     470             :     }
     471           0 :     if (TIFFFieldSet(tif, FIELD_YCBCRPOSITIONING))
     472             :     {
     473           0 :         fprintf(fd, "  YCbCr Positioning: ");
     474           0 :         switch (td->td_ycbcrpositioning)
     475             :         {
     476           0 :             case YCBCRPOSITION_CENTERED:
     477           0 :                 fprintf(fd, "centered\n");
     478           0 :                 break;
     479           0 :             case YCBCRPOSITION_COSITED:
     480           0 :                 fprintf(fd, "cosited\n");
     481           0 :                 break;
     482           0 :             default:
     483           0 :                 fprintf(fd, "%" PRIu16 " (0x%" PRIx16 ")\n",
     484           0 :                         td->td_ycbcrpositioning, td->td_ycbcrpositioning);
     485           0 :                 break;
     486             :         }
     487           0 :     }
     488           0 :     if (TIFFFieldSet(tif, FIELD_HALFTONEHINTS))
     489           0 :         fprintf(fd, "  Halftone Hints: light %" PRIu16 " dark %" PRIu16 "\n",
     490           0 :                 td->td_halftonehints[0], td->td_halftonehints[1]);
     491           0 :     if (TIFFFieldSet(tif, FIELD_ORIENTATION))
     492             :     {
     493           0 :         fprintf(fd, "  Orientation: ");
     494           0 :         if (td->td_orientation < NORIENTNAMES)
     495           0 :             fprintf(fd, "%s\n", orientNames[td->td_orientation]);
     496             :         else
     497           0 :             fprintf(fd, "%" PRIu16 " (0x%" PRIx16 ")\n", td->td_orientation,
     498           0 :                     td->td_orientation);
     499             :     }
     500           0 :     if (TIFFFieldSet(tif, FIELD_SAMPLESPERPIXEL))
     501           0 :         fprintf(fd, "  Samples/Pixel: %" PRIx16 "\n", td->td_samplesperpixel);
     502           0 :     if (TIFFFieldSet(tif, FIELD_ROWSPERSTRIP))
     503             :     {
     504           0 :         fprintf(fd, "  Rows/Strip: ");
     505           0 :         if (td->td_rowsperstrip == (uint32_t)-1)
     506           0 :             fprintf(fd, "(infinite)\n");
     507             :         else
     508           0 :             fprintf(fd, "%" PRIu32 "\n", td->td_rowsperstrip);
     509             :     }
     510           0 :     if (TIFFFieldSet(tif, FIELD_MINSAMPLEVALUE))
     511           0 :         fprintf(fd, "  Min Sample Value: %" PRIu16 "\n", td->td_minsamplevalue);
     512           0 :     if (TIFFFieldSet(tif, FIELD_MAXSAMPLEVALUE))
     513           0 :         fprintf(fd, "  Max Sample Value: %" PRIu16 "\n", td->td_maxsamplevalue);
     514           0 :     if (TIFFFieldSet(tif, FIELD_SMINSAMPLEVALUE))
     515             :     {
     516             :         int i;
     517           0 :         int count =
     518           0 :             (tif->tif_flags & TIFF_PERSAMPLE) ? td->td_samplesperpixel : 1;
     519           0 :         fprintf(fd, "  SMin Sample Value:");
     520           0 :         for (i = 0; i < count; ++i)
     521           0 :             fprintf(fd, " %g", td->td_sminsamplevalue[i]);
     522           0 :         fprintf(fd, "\n");
     523             :     }
     524           0 :     if (TIFFFieldSet(tif, FIELD_SMAXSAMPLEVALUE))
     525             :     {
     526             :         int i;
     527           0 :         int count =
     528           0 :             (tif->tif_flags & TIFF_PERSAMPLE) ? td->td_samplesperpixel : 1;
     529           0 :         fprintf(fd, "  SMax Sample Value:");
     530           0 :         for (i = 0; i < count; ++i)
     531           0 :             fprintf(fd, " %g", td->td_smaxsamplevalue[i]);
     532           0 :         fprintf(fd, "\n");
     533             :     }
     534           0 :     if (TIFFFieldSet(tif, FIELD_PLANARCONFIG))
     535             :     {
     536           0 :         fprintf(fd, "  Planar Configuration: ");
     537           0 :         switch (td->td_planarconfig)
     538             :         {
     539           0 :             case PLANARCONFIG_CONTIG:
     540           0 :                 fprintf(fd, "single image plane\n");
     541           0 :                 break;
     542           0 :             case PLANARCONFIG_SEPARATE:
     543           0 :                 fprintf(fd, "separate image planes\n");
     544           0 :                 break;
     545           0 :             default:
     546           0 :                 fprintf(fd, "%" PRIu16 " (0x%" PRIx16 ")\n",
     547           0 :                         td->td_planarconfig, td->td_planarconfig);
     548           0 :                 break;
     549             :         }
     550           0 :     }
     551           0 :     if (TIFFFieldSet(tif, FIELD_PAGENUMBER))
     552           0 :         fprintf(fd, "  Page Number: %" PRIu16 "-%" PRIu16 "\n",
     553           0 :                 td->td_pagenumber[0], td->td_pagenumber[1]);
     554           0 :     if (TIFFFieldSet(tif, FIELD_COLORMAP))
     555             :     {
     556           0 :         fprintf(fd, "  Color Map: ");
     557           0 :         if (flags & TIFFPRINT_COLORMAP)
     558             :         {
     559           0 :             fprintf(fd, "\n");
     560           0 :             n = 1L << td->td_bitspersample;
     561           0 :             for (l = 0; l < n; l++)
     562           0 :                 fprintf(fd, "   %5ld: %5" PRIu16 " %5" PRIu16 " %5" PRIu16 "\n",
     563           0 :                         l, td->td_colormap[0][l], td->td_colormap[1][l],
     564           0 :                         td->td_colormap[2][l]);
     565             :         }
     566             :         else
     567           0 :             fprintf(fd, "(present)\n");
     568             :     }
     569           0 :     if (TIFFFieldSet(tif, FIELD_REFBLACKWHITE))
     570             :     {
     571             :         int i;
     572           0 :         fprintf(fd, "  Reference Black/White:\n");
     573           0 :         for (i = 0; i < 3; i++)
     574           0 :             fprintf(fd, "    %2d: %5g %5g\n", i,
     575           0 :                     td->td_refblackwhite[2 * i + 0],
     576           0 :                     td->td_refblackwhite[2 * i + 1]);
     577             :     }
     578           0 :     if (TIFFFieldSet(tif, FIELD_TRANSFERFUNCTION))
     579             :     {
     580           0 :         fprintf(fd, "  Transfer Function: ");
     581           0 :         if (flags & TIFFPRINT_CURVES)
     582             :         {
     583           0 :             fprintf(fd, "\n");
     584           0 :             n = 1L << td->td_bitspersample;
     585           0 :             for (l = 0; l < n; l++)
     586             :             {
     587             :                 uint16_t i;
     588           0 :                 fprintf(fd, "    %2ld: %5" PRIu16, l,
     589           0 :                         td->td_transferfunction[0][l]);
     590           0 :                 for (i = 1;
     591           0 :                      i < td->td_samplesperpixel - td->td_extrasamples && i < 3;
     592           0 :                      i++)
     593           0 :                     fprintf(fd, " %5" PRIu16, td->td_transferfunction[i][l]);
     594           0 :                 fputc('\n', fd);
     595             :             }
     596             :         }
     597             :         else
     598           0 :             fprintf(fd, "(present)\n");
     599             :     }
     600           0 :     if (TIFFFieldSet(tif, FIELD_SUBIFD) && (td->td_subifd))
     601             :     {
     602             :         uint16_t i;
     603           0 :         fprintf(fd, "  SubIFD Offsets:");
     604           0 :         for (i = 0; i < td->td_nsubifd; i++)
     605           0 :             fprintf(fd, " %5" PRIu64, td->td_subifd[i]);
     606           0 :         fputc('\n', fd);
     607             :     }
     608             : 
     609             :     /*
     610             :     ** Custom tag support.
     611             :     */
     612             :     {
     613             :         int i;
     614             :         short count;
     615             : 
     616           0 :         count = (short)TIFFGetTagListCount(tif);
     617           0 :         for (i = 0; i < count; i++)
     618             :         {
     619           0 :             uint32_t tag = TIFFGetTagListEntry(tif, i);
     620             :             const TIFFField *fip;
     621             :             uint32_t value_count;
     622           0 :             int mem_alloc = 0;
     623           0 :             void *raw_data = NULL;
     624             :             uint16_t dotrange[2]; /* must be kept in that scope and not moved in
     625             :                                      the below TIFFTAG_DOTRANGE specific case */
     626             : 
     627           0 :             fip = TIFFFieldWithTag(tif, tag);
     628           0 :             if (fip == NULL)
     629           0 :                 continue;
     630             : 
     631           0 :             if (fip->field_passcount)
     632             :             {
     633           0 :                 if (fip->field_readcount == TIFF_VARIABLE2)
     634             :                 {
     635           0 :                     if (TIFFGetField(tif, tag, &value_count, &raw_data) != 1)
     636           0 :                         continue;
     637             :                 }
     638           0 :                 else if (fip->field_readcount == TIFF_VARIABLE)
     639             :                 {
     640             :                     uint16_t small_value_count;
     641           0 :                     if (TIFFGetField(tif, tag, &small_value_count, &raw_data) !=
     642             :                         1)
     643           0 :                         continue;
     644           0 :                     value_count = small_value_count;
     645             :                 }
     646             :                 else
     647             :                 {
     648           0 :                     assert(fip->field_readcount == TIFF_VARIABLE ||
     649             :                            fip->field_readcount == TIFF_VARIABLE2);
     650           0 :                     continue;
     651             :                 }
     652             :             }
     653             :             else
     654             :             {
     655           0 :                 if (fip->field_readcount == TIFF_VARIABLE ||
     656           0 :                     fip->field_readcount == TIFF_VARIABLE2)
     657           0 :                     value_count = 1;
     658           0 :                 else if (fip->field_readcount == TIFF_SPP)
     659           0 :                     value_count = td->td_samplesperpixel;
     660             :                 else
     661           0 :                     value_count = fip->field_readcount;
     662           0 :                 if (fip->field_tag == TIFFTAG_DOTRANGE &&
     663           0 :                     strcmp(fip->field_name, "DotRange") == 0)
     664             :                 {
     665             :                     /* TODO: This is an evil exception and should not have been
     666             :                        handled this way ... likely best if we move it into
     667             :                        the directory structure with an explicit field in
     668             :                        libtiff 4.1 and assign it a FIELD_ value */
     669           0 :                     raw_data = dotrange;
     670           0 :                     TIFFGetField(tif, tag, dotrange + 0, dotrange + 1);
     671             :                 }
     672           0 :                 else if (fip->field_type == TIFF_ASCII ||
     673           0 :                          fip->field_readcount == TIFF_VARIABLE ||
     674           0 :                          fip->field_readcount == TIFF_VARIABLE2 ||
     675           0 :                          fip->field_readcount == TIFF_SPP || value_count > 1)
     676             :                 {
     677           0 :                     if (TIFFGetField(tif, tag, &raw_data) != 1)
     678           0 :                         continue;
     679             :                 }
     680             :                 else
     681             :                 {
     682             :                     /*--: Rational2Double: For Rationals evaluate
     683             :                      * "set_get_field_type" to determine internal storage size.
     684             :                      */
     685           0 :                     int tv_size = TIFFFieldSetGetSize(fip);
     686           0 :                     raw_data = _TIFFmallocExt(tif, tv_size * value_count);
     687           0 :                     mem_alloc = 1;
     688           0 :                     if (TIFFGetField(tif, tag, raw_data) != 1)
     689             :                     {
     690           0 :                         _TIFFfreeExt(tif, raw_data);
     691           0 :                         continue;
     692             :                     }
     693             :                 }
     694             :             }
     695             : 
     696             :             /*
     697             :              * Catch the tags which needs to be specially handled
     698             :              * and pretty print them. If tag not handled in
     699             :              * _TIFFPrettyPrintField() fall down and print it as
     700             :              * any other tag.
     701             :              */
     702           0 :             if (raw_data != NULL &&
     703           0 :                 !_TIFFPrettyPrintField(tif, fip, fd, tag, value_count,
     704             :                                        raw_data))
     705           0 :                 _TIFFPrintField(fd, fip, value_count, raw_data);
     706             : 
     707           0 :             if (mem_alloc)
     708           0 :                 _TIFFfreeExt(tif, raw_data);
     709             :         }
     710             :     }
     711             : 
     712           0 :     if (tif->tif_tagmethods.printdir)
     713           0 :         (*tif->tif_tagmethods.printdir)(tif, fd, flags);
     714             : 
     715           0 :     if ((flags & TIFFPRINT_STRIPS) && TIFFFieldSet(tif, FIELD_STRIPOFFSETS))
     716             :     {
     717             :         uint32_t s;
     718             : 
     719           0 :         fprintf(fd, "  %" PRIu32 " %s:\n", td->td_nstrips,
     720           0 :                 isTiled(tif) ? "Tiles" : "Strips");
     721           0 :         for (s = 0; s < td->td_nstrips; s++)
     722           0 :             fprintf(fd, "    %3" PRIu32 ": [%8" PRIu64 ", %8" PRIu64 "]\n", s,
     723             :                     TIFFGetStrileOffset(tif, s),
     724             :                     TIFFGetStrileByteCount(tif, s));
     725             :     }
     726           0 : }
     727             : 
     728           0 : void _TIFFprintAscii(FILE *fd, const char *cp)
     729             : {
     730           0 :     _TIFFprintAsciiBounded(fd, cp, strlen(cp));
     731           0 : }
     732             : 
     733           0 : static void _TIFFprintAsciiBounded(FILE *fd, const char *cp, size_t max_chars)
     734             : {
     735           0 :     for (; max_chars > 0 && *cp != '\0'; cp++, max_chars--)
     736             :     {
     737             :         const char *tp;
     738             : 
     739           0 :         if (isprint((int)*cp))
     740             :         {
     741           0 :             fputc(*cp, fd);
     742           0 :             continue;
     743             :         }
     744           0 :         for (tp = "\tt\bb\rr\nn\vv"; *tp; tp++)
     745           0 :             if (*tp++ == *cp)
     746           0 :                 break;
     747           0 :         if (*tp)
     748           0 :             fprintf(fd, "\\%c", *tp);
     749             :         else
     750           0 :             fprintf(fd, "\\%03o", (unsigned int)(*cp & 0xff));
     751             :     }
     752           0 : }
     753             : 
     754           0 : void _TIFFprintAsciiTag(FILE *fd, const char *name, const char *value)
     755             : {
     756           0 :     fprintf(fd, "  %s: \"", name);
     757           0 :     _TIFFprintAscii(fd, value);
     758           0 :     fprintf(fd, "\"\n");
     759           0 : }

Generated by: LCOV version 1.14