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 452 0.0 %
Date: 2026-05-13 23:47:50 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", (double)((float *)raw_data)[j]);
     122             :         }
     123           0 :         else if (fip->field_type == TIFF_FLOAT)
     124           0 :             fprintf(fd, "%f", (double)((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",
     197           0 :                         (double)((float *)raw_data)[0],
     198           0 :                         (double)((float *)raw_data)[1]);
     199           0 :                 return 1;
     200             :             }
     201           0 :             return 0;
     202             : 
     203           0 :         case TIFFTAG_XMLPACKET:
     204             :         {
     205             :             uint32_t i;
     206             : 
     207           0 :             fprintf(fd, "  XMLPacket (XMP Metadata):\n");
     208           0 :             for (i = 0; i < value_count; i++)
     209           0 :                 fputc(((char *)raw_data)[i], fd);
     210           0 :             fprintf(fd, "\n");
     211           0 :             return 1;
     212             :         }
     213           0 :         case TIFFTAG_RICHTIFFIPTC:
     214           0 :             fprintf(fd, "  RichTIFFIPTC Data: <present>, %" PRIu32 " bytes\n",
     215             :                     value_count);
     216           0 :             return 1;
     217             : 
     218           0 :         case TIFFTAG_PHOTOSHOP:
     219           0 :             fprintf(fd, "  Photoshop Data: <present>, %" PRIu32 " bytes\n",
     220             :                     value_count);
     221           0 :             return 1;
     222             : 
     223           0 :         case TIFFTAG_ICCPROFILE:
     224           0 :             fprintf(fd, "  ICC Profile: <present>, %" PRIu32 " bytes\n",
     225             :                     value_count);
     226           0 :             return 1;
     227             : 
     228           0 :         case TIFFTAG_STONITS:
     229           0 :             if (value_count == 1 && fip->field_type == TIFF_DOUBLE)
     230             :             {
     231           0 :                 fprintf(fd, "  Sample to Nits conversion factor: %.4e\n",
     232             :                         *((double *)raw_data));
     233           0 :                 return 1;
     234             :             }
     235           0 :             return 0;
     236             : 
     237           0 :         default:
     238           0 :             break;
     239             :     }
     240             : 
     241           0 :     return 0;
     242             : }
     243             : 
     244             : /*
     245             :  * Print the contents of the current directory
     246             :  * to the specified stdio file stream.
     247             :  */
     248           0 : void TIFFPrintDirectory(TIFF *tif, FILE *fd, long flags)
     249             : {
     250           0 :     TIFFDirectory *td = &tif->tif_dir;
     251             :     const char *sep;
     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", (double)td->td_xresolution,
     293           0 :                 (double)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", (double)td->td_xposition,
     317           0 :                 (double)td->td_yposition);
     318           0 :     if (TIFFFieldSet(tif, FIELD_BITSPERSAMPLE))
     319           0 :         fprintf(fd, "  Bits/Sample: %" PRIu16 "\n", td->td_bitspersample);
     320           0 :     if (TIFFFieldSet(tif, FIELD_SAMPLEFORMAT))
     321             :     {
     322           0 :         fprintf(fd, "  Sample Format: ");
     323           0 :         switch (td->td_sampleformat)
     324             :         {
     325           0 :             case SAMPLEFORMAT_VOID:
     326           0 :                 fprintf(fd, "void\n");
     327           0 :                 break;
     328           0 :             case SAMPLEFORMAT_INT:
     329           0 :                 fprintf(fd, "signed integer\n");
     330           0 :                 break;
     331           0 :             case SAMPLEFORMAT_UINT:
     332           0 :                 fprintf(fd, "unsigned integer\n");
     333           0 :                 break;
     334           0 :             case SAMPLEFORMAT_IEEEFP:
     335           0 :                 fprintf(fd, "IEEE floating point\n");
     336           0 :                 break;
     337           0 :             case SAMPLEFORMAT_COMPLEXINT:
     338           0 :                 fprintf(fd, "complex signed integer\n");
     339           0 :                 break;
     340           0 :             case SAMPLEFORMAT_COMPLEXIEEEFP:
     341           0 :                 fprintf(fd, "complex IEEE floating point\n");
     342           0 :                 break;
     343           0 :             default:
     344           0 :                 fprintf(fd, "%" PRIu16 " (0x%" PRIx16 ")\n",
     345           0 :                         td->td_sampleformat, td->td_sampleformat);
     346           0 :                 break;
     347             :         }
     348           0 :     }
     349           0 :     if (TIFFFieldSet(tif, FIELD_COMPRESSION))
     350             :     {
     351           0 :         const TIFFCodec *c = TIFFFindCODEC(td->td_compression);
     352           0 :         fprintf(fd, "  Compression Scheme: ");
     353           0 :         if (c)
     354           0 :             fprintf(fd, "%s\n", c->name);
     355             :         else
     356           0 :             fprintf(fd, "%" PRIu16 " (0x%" PRIx16 ")\n", td->td_compression,
     357           0 :                     td->td_compression);
     358             :     }
     359           0 :     if (TIFFFieldSet(tif, FIELD_PHOTOMETRIC))
     360             :     {
     361           0 :         fprintf(fd, "  Photometric Interpretation: ");
     362           0 :         if (td->td_photometric < NPHOTONAMES)
     363           0 :             fprintf(fd, "%s\n", photoNames[td->td_photometric]);
     364             :         else
     365             :         {
     366           0 :             switch (td->td_photometric)
     367             :             {
     368           0 :                 case PHOTOMETRIC_LOGL:
     369           0 :                     fprintf(fd, "CIE Log2(L)\n");
     370           0 :                     break;
     371           0 :                 case PHOTOMETRIC_LOGLUV:
     372           0 :                     fprintf(fd, "CIE Log2(L) (u',v')\n");
     373           0 :                     break;
     374           0 :                 default:
     375           0 :                     fprintf(fd, "%" PRIu16 " (0x%" PRIx16 ")\n",
     376           0 :                             td->td_photometric, td->td_photometric);
     377           0 :                     break;
     378             :             }
     379           0 :         }
     380             :     }
     381           0 :     if (TIFFFieldSet(tif, FIELD_EXTRASAMPLES) && td->td_extrasamples &&
     382           0 :         td->td_sampleinfo)
     383             :     {
     384             :         uint16_t i;
     385           0 :         fprintf(fd, "  Extra Samples: %" PRIu16 "<", td->td_extrasamples);
     386           0 :         sep = "";
     387           0 :         for (i = 0; i < td->td_extrasamples; i++)
     388             :         {
     389           0 :             switch (td->td_sampleinfo[i])
     390             :             {
     391           0 :                 case EXTRASAMPLE_UNSPECIFIED:
     392           0 :                     fprintf(fd, "%sunspecified", sep);
     393           0 :                     break;
     394           0 :                 case EXTRASAMPLE_ASSOCALPHA:
     395           0 :                     fprintf(fd, "%sassoc-alpha", sep);
     396           0 :                     break;
     397           0 :                 case EXTRASAMPLE_UNASSALPHA:
     398           0 :                     fprintf(fd, "%sunassoc-alpha", sep);
     399           0 :                     break;
     400           0 :                 default:
     401           0 :                     fprintf(fd, "%s%" PRIu16 " (0x%" PRIx16 ")", sep,
     402           0 :                             td->td_sampleinfo[i], td->td_sampleinfo[i]);
     403           0 :                     break;
     404             :             }
     405           0 :             sep = ", ";
     406             :         }
     407           0 :         fprintf(fd, ">\n");
     408             :     }
     409           0 :     if (TIFFFieldSet(tif, FIELD_INKNAMES))
     410             :     {
     411             :         char *cp;
     412             :         uint16_t i;
     413           0 :         fprintf(fd, "  Ink Names: ");
     414           0 :         i = td->td_samplesperpixel;
     415           0 :         sep = "";
     416           0 :         for (cp = td->td_inknames;
     417           0 :              i > 0 && cp < td->td_inknames + td->td_inknameslen;
     418           0 :              cp = strchr(cp, '\0') + 1, i--)
     419             :         {
     420           0 :             size_t max_chars =
     421           0 :                 (size_t)(td->td_inknameslen - (cp - td->td_inknames));
     422           0 :             fputs(sep, fd);
     423           0 :             _TIFFprintAsciiBounded(fd, cp, max_chars);
     424           0 :             sep = ", ";
     425             :         }
     426           0 :         fputs("\n", fd);
     427             :     }
     428           0 :     if (TIFFFieldSet(tif, FIELD_NUMBEROFINKS))
     429             :     {
     430           0 :         fprintf(fd, "  NumberOfInks: %d\n", td->td_numberofinks);
     431             :     }
     432           0 :     if (TIFFFieldSet(tif, FIELD_THRESHHOLDING))
     433             :     {
     434           0 :         fprintf(fd, "  Thresholding: ");
     435           0 :         switch (td->td_threshholding)
     436             :         {
     437           0 :             case THRESHHOLD_BILEVEL:
     438           0 :                 fprintf(fd, "bilevel art scan\n");
     439           0 :                 break;
     440           0 :             case THRESHHOLD_HALFTONE:
     441           0 :                 fprintf(fd, "halftone or dithered scan\n");
     442           0 :                 break;
     443           0 :             case THRESHHOLD_ERRORDIFFUSE:
     444           0 :                 fprintf(fd, "error diffused\n");
     445           0 :                 break;
     446           0 :             default:
     447           0 :                 fprintf(fd, "%" PRIu16 " (0x%" PRIx16 ")\n",
     448           0 :                         td->td_threshholding, td->td_threshholding);
     449           0 :                 break;
     450             :         }
     451           0 :     }
     452           0 :     if (TIFFFieldSet(tif, FIELD_FILLORDER))
     453             :     {
     454           0 :         fprintf(fd, "  FillOrder: ");
     455           0 :         switch (td->td_fillorder)
     456             :         {
     457           0 :             case FILLORDER_MSB2LSB:
     458           0 :                 fprintf(fd, "msb-to-lsb\n");
     459           0 :                 break;
     460           0 :             case FILLORDER_LSB2MSB:
     461           0 :                 fprintf(fd, "lsb-to-msb\n");
     462           0 :                 break;
     463           0 :             default:
     464           0 :                 fprintf(fd, "%" PRIu16 " (0x%" PRIx16 ")\n", td->td_fillorder,
     465           0 :                         td->td_fillorder);
     466           0 :                 break;
     467             :         }
     468           0 :     }
     469           0 :     if (TIFFFieldSet(tif, FIELD_YCBCRSUBSAMPLING))
     470             :     {
     471           0 :         fprintf(fd, "  YCbCr Subsampling: %" PRIu16 ", %" PRIu16 "\n",
     472           0 :                 td->td_ycbcrsubsampling[0], td->td_ycbcrsubsampling[1]);
     473             :     }
     474           0 :     if (TIFFFieldSet(tif, FIELD_YCBCRPOSITIONING))
     475             :     {
     476           0 :         fprintf(fd, "  YCbCr Positioning: ");
     477           0 :         switch (td->td_ycbcrpositioning)
     478             :         {
     479           0 :             case YCBCRPOSITION_CENTERED:
     480           0 :                 fprintf(fd, "centered\n");
     481           0 :                 break;
     482           0 :             case YCBCRPOSITION_COSITED:
     483           0 :                 fprintf(fd, "cosited\n");
     484           0 :                 break;
     485           0 :             default:
     486           0 :                 fprintf(fd, "%" PRIu16 " (0x%" PRIx16 ")\n",
     487           0 :                         td->td_ycbcrpositioning, td->td_ycbcrpositioning);
     488           0 :                 break;
     489             :         }
     490           0 :     }
     491           0 :     if (TIFFFieldSet(tif, FIELD_HALFTONEHINTS))
     492           0 :         fprintf(fd, "  Halftone Hints: light %" PRIu16 " dark %" PRIu16 "\n",
     493           0 :                 td->td_halftonehints[0], td->td_halftonehints[1]);
     494           0 :     if (TIFFFieldSet(tif, FIELD_ORIENTATION))
     495             :     {
     496           0 :         fprintf(fd, "  Orientation: ");
     497           0 :         if (td->td_orientation < NORIENTNAMES)
     498           0 :             fprintf(fd, "%s\n", orientNames[td->td_orientation]);
     499             :         else
     500           0 :             fprintf(fd, "%" PRIu16 " (0x%" PRIx16 ")\n", td->td_orientation,
     501           0 :                     td->td_orientation);
     502             :     }
     503           0 :     if (TIFFFieldSet(tif, FIELD_SAMPLESPERPIXEL))
     504           0 :         fprintf(fd, "  Samples/Pixel: %" PRIx16 "\n", td->td_samplesperpixel);
     505           0 :     if (TIFFFieldSet(tif, FIELD_ROWSPERSTRIP))
     506             :     {
     507           0 :         fprintf(fd, "  Rows/Strip: ");
     508           0 :         if (td->td_rowsperstrip == (uint32_t)-1)
     509           0 :             fprintf(fd, "(infinite)\n");
     510             :         else
     511           0 :             fprintf(fd, "%" PRIu32 "\n", td->td_rowsperstrip);
     512             :     }
     513           0 :     if (TIFFFieldSet(tif, FIELD_MINSAMPLEVALUE))
     514           0 :         fprintf(fd, "  Min Sample Value: %" PRIu16 "\n", td->td_minsamplevalue);
     515           0 :     if (TIFFFieldSet(tif, FIELD_MAXSAMPLEVALUE))
     516           0 :         fprintf(fd, "  Max Sample Value: %" PRIu16 "\n", td->td_maxsamplevalue);
     517           0 :     if (TIFFFieldSet(tif, FIELD_SMINSAMPLEVALUE))
     518             :     {
     519             :         int i;
     520           0 :         int count =
     521           0 :             (tif->tif_flags & TIFF_PERSAMPLE) ? td->td_samplesperpixel : 1;
     522           0 :         fprintf(fd, "  SMin Sample Value:");
     523           0 :         for (i = 0; i < count; ++i)
     524           0 :             fprintf(fd, " %g", td->td_sminsamplevalue[i]);
     525           0 :         fprintf(fd, "\n");
     526             :     }
     527           0 :     if (TIFFFieldSet(tif, FIELD_SMAXSAMPLEVALUE))
     528             :     {
     529             :         int i;
     530           0 :         int count =
     531           0 :             (tif->tif_flags & TIFF_PERSAMPLE) ? td->td_samplesperpixel : 1;
     532           0 :         fprintf(fd, "  SMax Sample Value:");
     533           0 :         for (i = 0; i < count; ++i)
     534           0 :             fprintf(fd, " %g", td->td_smaxsamplevalue[i]);
     535           0 :         fprintf(fd, "\n");
     536             :     }
     537           0 :     if (TIFFFieldSet(tif, FIELD_PLANARCONFIG))
     538             :     {
     539           0 :         fprintf(fd, "  Planar Configuration: ");
     540           0 :         switch (td->td_planarconfig)
     541             :         {
     542           0 :             case PLANARCONFIG_CONTIG:
     543           0 :                 fprintf(fd, "single image plane\n");
     544           0 :                 break;
     545           0 :             case PLANARCONFIG_SEPARATE:
     546           0 :                 fprintf(fd, "separate image planes\n");
     547           0 :                 break;
     548           0 :             default:
     549           0 :                 fprintf(fd, "%" PRIu16 " (0x%" PRIx16 ")\n",
     550           0 :                         td->td_planarconfig, td->td_planarconfig);
     551           0 :                 break;
     552             :         }
     553           0 :     }
     554           0 :     if (TIFFFieldSet(tif, FIELD_PAGENUMBER))
     555           0 :         fprintf(fd, "  Page Number: %" PRIu16 "-%" PRIu16 "\n",
     556           0 :                 td->td_pagenumber[0], td->td_pagenumber[1]);
     557           0 :     if (TIFFFieldSet(tif, FIELD_COLORMAP) && td->td_colormap[0] &&
     558           0 :         td->td_colormap[1] && td->td_colormap[2])
     559             :     {
     560           0 :         fprintf(fd, "  Color Map: ");
     561           0 :         if (flags & TIFFPRINT_COLORMAP)
     562             :         {
     563           0 :             fprintf(fd, "\n");
     564           0 :             uint64_t n = 1ULL << td->td_bitspersample;
     565           0 :             for (uint64_t l = 0u; l < n; l++)
     566           0 :                 fprintf(fd,
     567             :                         "   %5" PRIu64 ": %5" PRIu16 " %5" PRIu16 " %5" PRIu16
     568             :                         "\n",
     569           0 :                         l, td->td_colormap[0][l], td->td_colormap[1][l],
     570           0 :                         td->td_colormap[2][l]);
     571             :         }
     572             :         else
     573           0 :             fprintf(fd, "(present)\n");
     574             :     }
     575           0 :     if (TIFFFieldSet(tif, FIELD_REFBLACKWHITE))
     576             :     {
     577             :         int i;
     578           0 :         fprintf(fd, "  Reference Black/White:\n");
     579           0 :         for (i = 0; i < 3; i++)
     580           0 :             fprintf(fd, "    %2d: %5g %5g\n", i,
     581           0 :                     (double)td->td_refblackwhite[2 * i + 0],
     582           0 :                     (double)td->td_refblackwhite[2 * i + 1]);
     583             :     }
     584           0 :     if (TIFFFieldSet(tif, FIELD_TRANSFERFUNCTION) &&
     585           0 :         td->td_transferfunction[0] &&
     586           0 :         ((td->td_samplesperpixel - td->td_extrasamples > 1 &&
     587           0 :           td->td_transferfunction[1] && td->td_transferfunction[2]) ||
     588           0 :          td->td_samplesperpixel - td->td_extrasamples <= 1))
     589             :     {
     590           0 :         fprintf(fd, "  Transfer Function: ");
     591           0 :         if (flags & TIFFPRINT_CURVES)
     592             :         {
     593           0 :             fprintf(fd, "\n");
     594           0 :             uint64_t n = 1ULL << td->td_bitspersample;
     595           0 :             for (uint64_t l = 0; l < n; l++)
     596             :             {
     597             :                 uint16_t i;
     598           0 :                 fprintf(fd, "    %2" PRIu64 ": %5" PRIu16, l,
     599           0 :                         td->td_transferfunction[0][l]);
     600           0 :                 for (i = 1;
     601           0 :                      i < td->td_samplesperpixel - td->td_extrasamples && i < 3;
     602           0 :                      i++)
     603           0 :                     fprintf(fd, " %5" PRIu16, td->td_transferfunction[i][l]);
     604           0 :                 fputc('\n', fd);
     605             :             }
     606             :         }
     607             :         else
     608           0 :             fprintf(fd, "(present)\n");
     609             :     }
     610           0 :     if (TIFFFieldSet(tif, FIELD_SUBIFD) && (td->td_subifd))
     611             :     {
     612             :         uint16_t i;
     613           0 :         fprintf(fd, "  SubIFD Offsets:");
     614           0 :         for (i = 0; i < td->td_nsubifd; i++)
     615           0 :             fprintf(fd, " %5" PRIu64, td->td_subifd[i]);
     616           0 :         fputc('\n', fd);
     617             :     }
     618             : 
     619             :     /*
     620             :     ** Custom tag support.
     621             :     */
     622             :     {
     623             :         int i;
     624             :         short count;
     625             : 
     626           0 :         count = (short)TIFFGetTagListCount(tif);
     627           0 :         for (i = 0; i < count; i++)
     628             :         {
     629           0 :             uint32_t tag = TIFFGetTagListEntry(tif, i);
     630             :             const TIFFField *fip;
     631             :             uint32_t value_count;
     632           0 :             int mem_alloc = 0;
     633           0 :             void *raw_data = NULL;
     634             :             uint16_t dotrange[2]; /* must be kept in that scope and not moved in
     635             :                                      the below TIFFTAG_DOTRANGE specific case */
     636             : 
     637           0 :             fip = TIFFFieldWithTag(tif, tag);
     638           0 :             if (fip == NULL)
     639           0 :                 continue;
     640             : 
     641           0 :             if (fip->field_passcount)
     642             :             {
     643           0 :                 if (fip->field_readcount == TIFF_VARIABLE2)
     644             :                 {
     645           0 :                     if (TIFFGetField(tif, tag, &value_count, &raw_data) != 1)
     646           0 :                         continue;
     647             :                 }
     648           0 :                 else if (fip->field_readcount == TIFF_VARIABLE)
     649             :                 {
     650             :                     uint16_t small_value_count;
     651           0 :                     if (TIFFGetField(tif, tag, &small_value_count, &raw_data) !=
     652             :                         1)
     653           0 :                         continue;
     654           0 :                     value_count = small_value_count;
     655             :                 }
     656             :                 else
     657             :                 {
     658           0 :                     assert(fip->field_readcount == TIFF_VARIABLE ||
     659             :                            fip->field_readcount == TIFF_VARIABLE2);
     660           0 :                     continue;
     661             :                 }
     662             :             }
     663             :             else
     664             :             {
     665           0 :                 if (fip->field_readcount == TIFF_VARIABLE ||
     666           0 :                     fip->field_readcount == TIFF_VARIABLE2)
     667           0 :                     value_count = 1;
     668           0 :                 else if (fip->field_readcount == TIFF_SPP)
     669           0 :                     value_count = td->td_samplesperpixel;
     670             :                 else
     671           0 :                     value_count = (uint32_t)fip->field_readcount;
     672           0 :                 if (fip->field_tag == TIFFTAG_DOTRANGE &&
     673           0 :                     strcmp(fip->field_name, "DotRange") == 0)
     674             :                 {
     675             :                     /* TODO: This is an evil exception and should not have been
     676             :                        handled this way ... likely best if we move it into
     677             :                        the directory structure with an explicit field in
     678             :                        libtiff 4.1 and assign it a FIELD_ value */
     679           0 :                     raw_data = dotrange;
     680           0 :                     TIFFGetField(tif, tag, dotrange + 0, dotrange + 1);
     681             :                 }
     682           0 :                 else if (fip->field_type == TIFF_ASCII ||
     683           0 :                          fip->field_readcount == TIFF_VARIABLE ||
     684           0 :                          fip->field_readcount == TIFF_VARIABLE2 ||
     685           0 :                          fip->field_readcount == TIFF_SPP || value_count > 1)
     686             :                 {
     687           0 :                     if (TIFFGetField(tif, tag, &raw_data) != 1)
     688           0 :                         continue;
     689             :                 }
     690             :                 else
     691             :                 {
     692             :                     /*--: Rational2Double: For Rationals evaluate
     693             :                      * "set_get_field_type" to determine internal storage size.
     694             :                      */
     695           0 :                     int tv_size = TIFFFieldSetGetSize(fip);
     696           0 :                     raw_data = _TIFFCheckMalloc(tif, value_count, tv_size,
     697             :                                                 "for tag data");
     698           0 :                     mem_alloc = 1;
     699           0 :                     if (TIFFGetField(tif, tag, raw_data) != 1)
     700             :                     {
     701           0 :                         _TIFFfreeExt(tif, raw_data);
     702           0 :                         continue;
     703             :                     }
     704             :                 }
     705             :             }
     706             : 
     707             :             /*
     708             :              * Catch the tags which needs to be specially handled
     709             :              * and pretty print them. If tag not handled in
     710             :              * _TIFFPrettyPrintField() fall down and print it as
     711             :              * any other tag.
     712             :              */
     713           0 :             if (raw_data != NULL &&
     714           0 :                 !_TIFFPrettyPrintField(tif, fip, fd, tag, value_count,
     715             :                                        raw_data))
     716           0 :                 _TIFFPrintField(fd, fip, value_count, raw_data);
     717             : 
     718           0 :             if (mem_alloc)
     719           0 :                 _TIFFfreeExt(tif, raw_data);
     720             :         }
     721             :     }
     722             : 
     723           0 :     if (tif->tif_tagmethods.printdir)
     724           0 :         (*tif->tif_tagmethods.printdir)(tif, fd, flags);
     725             : 
     726           0 :     if ((flags & TIFFPRINT_STRIPS) && TIFFFieldSet(tif, FIELD_STRIPOFFSETS))
     727             :     {
     728             :         uint32_t s;
     729             : 
     730           0 :         fprintf(fd, "  %" PRIu32 " %s:\n", td->td_nstrips,
     731           0 :                 isTiled(tif) ? "Tiles" : "Strips");
     732           0 :         for (s = 0; s < td->td_nstrips; s++)
     733           0 :             fprintf(fd, "    %3" PRIu32 ": [%8" PRIu64 ", %8" PRIu64 "]\n", s,
     734             :                     TIFFGetStrileOffset(tif, s),
     735             :                     TIFFGetStrileByteCount(tif, s));
     736             :     }
     737           0 : }
     738             : 
     739           0 : void _TIFFprintAscii(FILE *fd, const char *cp)
     740             : {
     741           0 :     _TIFFprintAsciiBounded(fd, cp, strlen(cp));
     742           0 : }
     743             : 
     744           0 : static void _TIFFprintAsciiBounded(FILE *fd, const char *cp, size_t max_chars)
     745             : {
     746           0 :     for (; max_chars > 0 && *cp != '\0'; cp++, max_chars--)
     747             :     {
     748             :         const char *tp;
     749             : 
     750           0 :         if (isprint((int)*cp))
     751             :         {
     752           0 :             fputc(*cp, fd);
     753           0 :             continue;
     754             :         }
     755           0 :         for (tp = "\tt\bb\rr\nn\vv"; *tp; tp++)
     756           0 :             if (*tp++ == *cp)
     757           0 :                 break;
     758           0 :         if (*tp)
     759           0 :             fprintf(fd, "\\%c", *tp);
     760             :         else
     761           0 :             fprintf(fd, "\\%03o", (unsigned int)(*cp & 0xff));
     762             :     }
     763           0 : }
     764             : 
     765           0 : void _TIFFprintAsciiTag(FILE *fd, const char *name, const char *value)
     766             : {
     767           0 :     fprintf(fd, "  %s: \"", name);
     768           0 :     _TIFFprintAscii(fd, value);
     769           0 :     fprintf(fd, "\"\n");
     770           0 : }

Generated by: LCOV version 1.14