LCOV - code coverage report
Current view: directory - frmts/gtiff/libtiff - tif_print.c (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 362 0 0.0 %
Date: 2010-01-09 Functions: 5 0 0.0 %

       1                 : /* $Id: tif_print.c,v 1.48 2009-08-24 16:51:14 bfriesen Exp $ */
       2                 : 
       3                 : /*
       4                 :  * Copyright (c) 1988-1997 Sam Leffler
       5                 :  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
       6                 :  *
       7                 :  * Permission to use, copy, modify, distribute, and sell this software and 
       8                 :  * its documentation for any purpose is hereby granted without fee, provided
       9                 :  * that (i) the above copyright notices and this permission notice appear in
      10                 :  * all copies of the software and related documentation, and (ii) the names of
      11                 :  * Sam Leffler and Silicon Graphics may not be used in any advertising or
      12                 :  * publicity relating to the software without the specific, prior written
      13                 :  * permission of Sam Leffler and Silicon Graphics.
      14                 :  * 
      15                 :  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
      16                 :  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
      17                 :  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
      18                 :  * 
      19                 :  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
      20                 :  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
      21                 :  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
      22                 :  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
      23                 :  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
      24                 :  * OF THIS SOFTWARE.
      25                 :  */
      26                 : 
      27                 : /*
      28                 :  * TIFF Library.
      29                 :  *
      30                 :  * Directory Printing Support
      31                 :  */
      32                 : #include "tiffiop.h"
      33                 : #include <stdio.h>
      34                 : 
      35                 : #include <ctype.h>
      36                 : 
      37                 : static const char *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                 : };
      48                 : #define NPHOTONAMES (sizeof (photoNames) / sizeof (photoNames[0]))
      49                 : 
      50                 : static const char *orientNames[] = {
      51                 :     "0 (0x0)",
      52                 :     "row 0 top, col 0 lhs",     /* ORIENTATION_TOPLEFT */
      53                 :     "row 0 top, col 0 rhs",     /* ORIENTATION_TOPRIGHT */
      54                 :     "row 0 bottom, col 0 rhs",      /* ORIENTATION_BOTRIGHT */
      55                 :     "row 0 bottom, col 0 lhs",      /* ORIENTATION_BOTLEFT */
      56                 :     "row 0 lhs, col 0 top",     /* ORIENTATION_LEFTTOP */
      57                 :     "row 0 rhs, col 0 top",     /* ORIENTATION_RIGHTTOP */
      58                 :     "row 0 rhs, col 0 bottom",      /* ORIENTATION_RIGHTBOT */
      59                 :     "row 0 lhs, col 0 bottom",      /* ORIENTATION_LEFTBOT */
      60                 : };
      61                 : #define NORIENTNAMES  (sizeof (orientNames) / sizeof (orientNames[0]))
      62                 : 
      63                 : static void
      64               0 : _TIFFPrintField(FILE* fd, const TIFFField *fip,
      65                 :     uint32 value_count, void *raw_data)
      66                 : {
      67                 :   uint32 j;
      68                 :     
      69               0 :   fprintf(fd, "  %s: ", fip->field_name);
      70                 : 
      71               0 :   for(j = 0; j < value_count; j++) {
      72               0 :     if(fip->field_type == TIFF_BYTE)
      73               0 :       fprintf(fd, "%u", ((uint8 *) raw_data)[j]);
      74               0 :     else if(fip->field_type == TIFF_UNDEFINED)
      75               0 :       fprintf(fd, "0x%x",
      76               0 :           (unsigned int) ((unsigned char *) raw_data)[j]);
      77               0 :     else if(fip->field_type == TIFF_SBYTE)
      78               0 :       fprintf(fd, "%d", ((int8 *) raw_data)[j]);
      79               0 :     else if(fip->field_type == TIFF_SHORT)
      80               0 :       fprintf(fd, "%u", ((uint16 *) raw_data)[j]);
      81               0 :     else if(fip->field_type == TIFF_SSHORT)
      82               0 :       fprintf(fd, "%d", ((int16 *) raw_data)[j]);
      83               0 :     else if(fip->field_type == TIFF_LONG)
      84               0 :       fprintf(fd, "%lu",
      85               0 :           (unsigned long)((uint32 *) raw_data)[j]);
      86               0 :     else if(fip->field_type == TIFF_SLONG)
      87               0 :       fprintf(fd, "%ld", (long)((int32 *) raw_data)[j]);
      88               0 :     else if(fip->field_type == TIFF_IFD)
      89               0 :       fprintf(fd, "0x%lx",
      90               0 :         (unsigned long)((uint32 *) raw_data)[j]);
      91               0 :     else if(fip->field_type == TIFF_RATIONAL
      92               0 :       || fip->field_type == TIFF_SRATIONAL
      93               0 :       || fip->field_type == TIFF_FLOAT)
      94               0 :       fprintf(fd, "%f", ((float *) raw_data)[j]);
      95               0 :     else if(fip->field_type == TIFF_LONG8)
      96                 : #if defined(__WIN32__) && defined(_MSC_VER)
      97                 :       fprintf(fd, "%I64u",
      98                 :           (unsigned __int64)((uint64 *) raw_data)[j]);
      99                 : #else
     100               0 :       fprintf(fd, "%llu",
     101               0 :           (unsigned long long)((uint64 *) raw_data)[j]);
     102                 : #endif
     103               0 :     else if(fip->field_type == TIFF_SLONG8)
     104                 : #if defined(__WIN32__) && defined(_MSC_VER)
     105                 :       fprintf(fd, "%I64d", (__int64)((int64 *) raw_data)[j]);
     106                 : #else
     107               0 :       fprintf(fd, "%lld", (long long)((int64 *) raw_data)[j]);
     108                 : #endif
     109               0 :     else if(fip->field_type == TIFF_IFD8)
     110                 : #if defined(__WIN32__) && defined(_MSC_VER)
     111                 :       fprintf(fd, "0x%I64x",
     112                 :         (unsigned __int64)((uint64 *) raw_data)[j]);
     113                 : #else
     114               0 :       fprintf(fd, "0x%llx",
     115               0 :         (unsigned long long)((uint64 *) raw_data)[j]);
     116                 : #endif
     117               0 :     else if(fip->field_type == TIFF_FLOAT)
     118               0 :       fprintf(fd, "%f", ((float *)raw_data)[j]);
     119               0 :     else if(fip->field_type == TIFF_DOUBLE)
     120               0 :       fprintf(fd, "%f", ((double *) raw_data)[j]);
     121               0 :     else if(fip->field_type == TIFF_ASCII) {
     122               0 :       fprintf(fd, "%s", (char *) raw_data);
     123               0 :       break;
     124                 :     }
     125                 :     else {
     126               0 :       fprintf(fd, "<unsupported data type in TIFFPrint>");
     127               0 :       break;
     128                 :     }
     129                 : 
     130               0 :     if(j < value_count - 1)
     131               0 :       fprintf(fd, ",");
     132                 :   }
     133                 : 
     134               0 :   fprintf(fd, "\n");
     135               0 : }
     136                 : 
     137                 : static int
     138               0 : _TIFFPrettyPrintField(TIFF* tif, FILE* fd, uint32 tag,
     139                 :           uint32 value_count, void *raw_data)
     140                 : {
     141               0 :   TIFFDirectory *td = &tif->tif_dir;
     142                 : 
     143               0 :   switch (tag)
     144                 :   {
     145                 :     case TIFFTAG_INKSET:
     146               0 :       fprintf(fd, "  Ink Set: ");
     147               0 :       switch (*((uint16*)raw_data)) {
     148                 :         case INKSET_CMYK:
     149               0 :           fprintf(fd, "CMYK\n");
     150               0 :           break;
     151                 :         default:
     152               0 :           fprintf(fd, "%u (0x%x)\n",
     153               0 :               *((uint16*)raw_data),
     154               0 :               *((uint16*)raw_data));
     155                 :           break;
     156                 :       }
     157               0 :       return 1;
     158                 :     case TIFFTAG_DOTRANGE:
     159               0 :       fprintf(fd, "  Dot Range: %u-%u\n",
     160               0 :           ((uint16*)raw_data)[0], ((uint16*)raw_data)[1]);
     161               0 :       return 1;
     162                 :     case TIFFTAG_WHITEPOINT:
     163               0 :       fprintf(fd, "  White Point: %g-%g\n",
     164               0 :           ((float *)raw_data)[0], ((float *)raw_data)[1]);
     165               0 :       return 1;
     166                 :     case TIFFTAG_REFERENCEBLACKWHITE:
     167                 :     {
     168                 :       uint16 i;
     169                 : 
     170               0 :       fprintf(fd, "  Reference Black/White:\n");
     171               0 :       for (i = 0; i < td->td_samplesperpixel; i++)
     172               0 :       fprintf(fd, "    %2d: %5g %5g\n", i,
     173               0 :           ((float *)raw_data)[2*i+0],
     174               0 :           ((float *)raw_data)[2*i+1]);
     175               0 :       return 1;
     176                 :     }
     177                 :     case TIFFTAG_XMLPACKET:
     178                 :     {
     179                 :       uint32 i;
     180                 : 
     181               0 :       fprintf(fd, "  XMLPacket (XMP Metadata):\n" );
     182               0 :       for(i = 0; i < value_count; i++)
     183               0 :         fputc(((char *)raw_data)[i], fd);
     184               0 :       fprintf( fd, "\n" );
     185               0 :       return 1;
     186                 :     }
     187                 :     case TIFFTAG_RICHTIFFIPTC:
     188                 :       /*
     189                 :        * XXX: for some weird reason RichTIFFIPTC tag
     190                 :        * defined as array of LONG values.
     191                 :        */
     192               0 :       fprintf(fd,
     193                 :           "  RichTIFFIPTC Data: <present>, %lu bytes\n",
     194                 :           (unsigned long) value_count * 4);
     195               0 :       return 1;
     196                 :     case TIFFTAG_PHOTOSHOP:
     197               0 :       fprintf(fd, "  Photoshop Data: <present>, %lu bytes\n",
     198                 :           (unsigned long) value_count);
     199               0 :       return 1;
     200                 :     case TIFFTAG_ICCPROFILE:
     201               0 :       fprintf(fd, "  ICC Profile: <present>, %lu bytes\n",
     202                 :           (unsigned long) value_count);
     203               0 :       return 1;
     204                 :     case TIFFTAG_STONITS:
     205               0 :       fprintf(fd,
     206                 :           "  Sample to Nits conversion factor: %.4e\n",
     207               0 :           *((double*)raw_data));
     208               0 :       return 1;
     209                 :   }
     210                 : 
     211               0 :   return 0;
     212                 : }
     213                 : 
     214                 : /*
     215                 :  * Print the contents of the current directory
     216                 :  * to the specified stdio file stream.
     217                 :  */
     218                 : void
     219               0 : TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags)
     220                 : {
     221               0 :   TIFFDirectory *td = &tif->tif_dir;
     222                 :   char *sep;
     223                 :   uint16 i;
     224                 :   long l, n;
     225                 : 
     226                 : #if defined(__WIN32__) && defined(_MSC_VER)
     227                 :   fprintf(fd, "TIFF Directory at offset 0x%I64x (%I64u)\n",
     228                 :     (unsigned __int64) tif->tif_diroff,
     229                 :     (unsigned __int64) tif->tif_diroff);
     230                 : #else
     231               0 :   fprintf(fd, "TIFF Directory at offset 0x%llx (%llu)\n",
     232                 :     (unsigned long long) tif->tif_diroff,
     233                 :     (unsigned long long) tif->tif_diroff);
     234                 : #endif
     235               0 :   if (TIFFFieldSet(tif,FIELD_SUBFILETYPE)) {
     236               0 :     fprintf(fd, "  Subfile Type:");
     237               0 :     sep = " ";
     238               0 :     if (td->td_subfiletype & FILETYPE_REDUCEDIMAGE) {
     239               0 :       fprintf(fd, "%sreduced-resolution image", sep);
     240               0 :       sep = "/";
     241                 :     }
     242               0 :     if (td->td_subfiletype & FILETYPE_PAGE) {
     243               0 :       fprintf(fd, "%smulti-page document", sep);
     244               0 :       sep = "/";
     245                 :     }
     246               0 :     if (td->td_subfiletype & FILETYPE_MASK)
     247               0 :       fprintf(fd, "%stransparency mask", sep);
     248               0 :     fprintf(fd, " (%lu = 0x%lx)\n",
     249                 :         (long) td->td_subfiletype, (long) td->td_subfiletype);
     250                 :   }
     251               0 :   if (TIFFFieldSet(tif,FIELD_IMAGEDIMENSIONS)) {
     252               0 :     fprintf(fd, "  Image Width: %lu Image Length: %lu",
     253                 :         (unsigned long) td->td_imagewidth, (unsigned long) td->td_imagelength);
     254               0 :     if (TIFFFieldSet(tif,FIELD_IMAGEDEPTH))
     255               0 :       fprintf(fd, " Image Depth: %lu",
     256                 :           (unsigned long) td->td_imagedepth);
     257               0 :     fprintf(fd, "\n");
     258                 :   }
     259               0 :   if (TIFFFieldSet(tif,FIELD_TILEDIMENSIONS)) {
     260               0 :     fprintf(fd, "  Tile Width: %lu Tile Length: %lu",
     261                 :         (unsigned long) td->td_tilewidth, (unsigned long) td->td_tilelength);
     262               0 :     if (TIFFFieldSet(tif,FIELD_TILEDEPTH))
     263               0 :       fprintf(fd, " Tile Depth: %lu",
     264                 :           (unsigned long) td->td_tiledepth);
     265               0 :     fprintf(fd, "\n");
     266                 :   }
     267               0 :   if (TIFFFieldSet(tif,FIELD_RESOLUTION)) {
     268               0 :     fprintf(fd, "  Resolution: %g, %g",
     269               0 :         td->td_xresolution, td->td_yresolution);
     270               0 :     if (TIFFFieldSet(tif,FIELD_RESOLUTIONUNIT)) {
     271               0 :       switch (td->td_resolutionunit) {
     272                 :       case RESUNIT_NONE:
     273               0 :         fprintf(fd, " (unitless)");
     274               0 :         break;
     275                 :       case RESUNIT_INCH:
     276               0 :         fprintf(fd, " pixels/inch");
     277               0 :         break;
     278                 :       case RESUNIT_CENTIMETER:
     279               0 :         fprintf(fd, " pixels/cm");
     280               0 :         break;
     281                 :       default:
     282               0 :         fprintf(fd, " (unit %u = 0x%x)",
     283               0 :             td->td_resolutionunit,
     284               0 :             td->td_resolutionunit);
     285                 :         break;
     286                 :       }
     287                 :     }
     288               0 :     fprintf(fd, "\n");
     289                 :   }
     290               0 :   if (TIFFFieldSet(tif,FIELD_POSITION))
     291               0 :     fprintf(fd, "  Position: %g, %g\n",
     292               0 :         td->td_xposition, td->td_yposition);
     293               0 :   if (TIFFFieldSet(tif,FIELD_BITSPERSAMPLE))
     294               0 :     fprintf(fd, "  Bits/Sample: %u\n", td->td_bitspersample);
     295               0 :   if (TIFFFieldSet(tif,FIELD_SAMPLEFORMAT)) {
     296               0 :     fprintf(fd, "  Sample Format: ");
     297               0 :     switch (td->td_sampleformat) {
     298                 :     case SAMPLEFORMAT_VOID:
     299               0 :       fprintf(fd, "void\n");
     300               0 :       break;
     301                 :     case SAMPLEFORMAT_INT:
     302               0 :       fprintf(fd, "signed integer\n");
     303               0 :       break;
     304                 :     case SAMPLEFORMAT_UINT:
     305               0 :       fprintf(fd, "unsigned integer\n");
     306               0 :       break;
     307                 :     case SAMPLEFORMAT_IEEEFP:
     308               0 :       fprintf(fd, "IEEE floating point\n");
     309               0 :       break;
     310                 :     case SAMPLEFORMAT_COMPLEXINT:
     311               0 :       fprintf(fd, "complex signed integer\n");
     312               0 :       break;
     313                 :     case SAMPLEFORMAT_COMPLEXIEEEFP:
     314               0 :       fprintf(fd, "complex IEEE floating point\n");
     315               0 :       break;
     316                 :     default:
     317               0 :       fprintf(fd, "%u (0x%x)\n",
     318               0 :           td->td_sampleformat, td->td_sampleformat);
     319                 :       break;
     320                 :     }
     321                 :   }
     322               0 :   if (TIFFFieldSet(tif,FIELD_COMPRESSION)) {
     323               0 :     const TIFFCodec* c = TIFFFindCODEC(td->td_compression);
     324               0 :     fprintf(fd, "  Compression Scheme: ");
     325               0 :     if (c)
     326               0 :       fprintf(fd, "%s\n", c->name);
     327                 :     else
     328               0 :       fprintf(fd, "%u (0x%x)\n",
     329               0 :           td->td_compression, td->td_compression);
     330                 :   }
     331               0 :   if (TIFFFieldSet(tif,FIELD_PHOTOMETRIC)) {
     332               0 :     fprintf(fd, "  Photometric Interpretation: ");
     333               0 :     if (td->td_photometric < NPHOTONAMES)
     334               0 :       fprintf(fd, "%s\n", photoNames[td->td_photometric]);
     335                 :     else {
     336               0 :       switch (td->td_photometric) {
     337                 :       case PHOTOMETRIC_LOGL:
     338               0 :         fprintf(fd, "CIE Log2(L)\n");
     339               0 :         break;
     340                 :       case PHOTOMETRIC_LOGLUV:
     341               0 :         fprintf(fd, "CIE Log2(L) (u',v')\n");
     342               0 :         break;
     343                 :       default:
     344               0 :         fprintf(fd, "%u (0x%x)\n",
     345               0 :             td->td_photometric, td->td_photometric);
     346                 :         break;
     347                 :       }
     348                 :     }
     349                 :   }
     350               0 :   if (TIFFFieldSet(tif,FIELD_EXTRASAMPLES) && td->td_extrasamples) {
     351               0 :     fprintf(fd, "  Extra Samples: %u<", td->td_extrasamples);
     352               0 :     sep = "";
     353               0 :     for (i = 0; i < td->td_extrasamples; i++) {
     354               0 :       switch (td->td_sampleinfo[i]) {
     355                 :       case EXTRASAMPLE_UNSPECIFIED:
     356               0 :         fprintf(fd, "%sunspecified", sep);
     357               0 :         break;
     358                 :       case EXTRASAMPLE_ASSOCALPHA:
     359               0 :         fprintf(fd, "%sassoc-alpha", sep);
     360               0 :         break;
     361                 :       case EXTRASAMPLE_UNASSALPHA:
     362               0 :         fprintf(fd, "%sunassoc-alpha", sep);
     363               0 :         break;
     364                 :       default:
     365               0 :         fprintf(fd, "%s%u (0x%x)", sep,
     366               0 :             td->td_sampleinfo[i], td->td_sampleinfo[i]);
     367                 :         break;
     368                 :       }
     369               0 :       sep = ", ";
     370                 :     }
     371               0 :     fprintf(fd, ">\n");
     372                 :   }
     373               0 :   if (TIFFFieldSet(tif,FIELD_INKNAMES)) {
     374                 :     char* cp;
     375               0 :     fprintf(fd, "  Ink Names: ");
     376               0 :     i = td->td_samplesperpixel;
     377               0 :     sep = "";
     378               0 :     for (cp = td->td_inknames; i > 0; cp = strchr(cp,'\0')+1, i--) {
     379               0 :       fputs(sep, fd);
     380               0 :       _TIFFprintAscii(fd, cp);
     381               0 :       sep = ", ";
     382                 :     }
     383               0 :                 fputs("\n", fd);
     384                 :   }
     385               0 :   if (TIFFFieldSet(tif,FIELD_THRESHHOLDING)) {
     386               0 :     fprintf(fd, "  Thresholding: ");
     387               0 :     switch (td->td_threshholding) {
     388                 :     case THRESHHOLD_BILEVEL:
     389               0 :       fprintf(fd, "bilevel art scan\n");
     390               0 :       break;
     391                 :     case THRESHHOLD_HALFTONE:
     392               0 :       fprintf(fd, "halftone or dithered scan\n");
     393               0 :       break;
     394                 :     case THRESHHOLD_ERRORDIFFUSE:
     395               0 :       fprintf(fd, "error diffused\n");
     396               0 :       break;
     397                 :     default:
     398               0 :       fprintf(fd, "%u (0x%x)\n",
     399               0 :           td->td_threshholding, td->td_threshholding);
     400                 :       break;
     401                 :     }
     402                 :   }
     403               0 :   if (TIFFFieldSet(tif,FIELD_FILLORDER)) {
     404               0 :     fprintf(fd, "  FillOrder: ");
     405               0 :     switch (td->td_fillorder) {
     406                 :     case FILLORDER_MSB2LSB:
     407               0 :       fprintf(fd, "msb-to-lsb\n");
     408               0 :       break;
     409                 :     case FILLORDER_LSB2MSB:
     410               0 :       fprintf(fd, "lsb-to-msb\n");
     411               0 :       break;
     412                 :     default:
     413               0 :       fprintf(fd, "%u (0x%x)\n",
     414               0 :           td->td_fillorder, td->td_fillorder);
     415                 :       break;
     416                 :     }
     417                 :   }
     418               0 :   if (TIFFFieldSet(tif,FIELD_YCBCRSUBSAMPLING))
     419                 :         {
     420               0 :     fprintf(fd, "  YCbCr Subsampling: %u, %u\n",
     421               0 :       td->td_ycbcrsubsampling[0], td->td_ycbcrsubsampling[1] );
     422                 :   }
     423               0 :   if (TIFFFieldSet(tif,FIELD_YCBCRPOSITIONING)) {
     424               0 :     fprintf(fd, "  YCbCr Positioning: ");
     425               0 :     switch (td->td_ycbcrpositioning) {
     426                 :     case YCBCRPOSITION_CENTERED:
     427               0 :       fprintf(fd, "centered\n");
     428               0 :       break;
     429                 :     case YCBCRPOSITION_COSITED:
     430               0 :       fprintf(fd, "cosited\n");
     431               0 :       break;
     432                 :     default:
     433               0 :       fprintf(fd, "%u (0x%x)\n",
     434               0 :           td->td_ycbcrpositioning, td->td_ycbcrpositioning);
     435                 :       break;
     436                 :     }
     437                 :   }
     438               0 :   if (TIFFFieldSet(tif,FIELD_HALFTONEHINTS))
     439               0 :     fprintf(fd, "  Halftone Hints: light %u dark %u\n",
     440               0 :         td->td_halftonehints[0], td->td_halftonehints[1]);
     441               0 :   if (TIFFFieldSet(tif,FIELD_ORIENTATION)) {
     442               0 :     fprintf(fd, "  Orientation: ");
     443               0 :     if (td->td_orientation < NORIENTNAMES)
     444               0 :       fprintf(fd, "%s\n", orientNames[td->td_orientation]);
     445                 :     else
     446               0 :       fprintf(fd, "%u (0x%x)\n",
     447               0 :           td->td_orientation, td->td_orientation);
     448                 :   }
     449               0 :   if (TIFFFieldSet(tif,FIELD_SAMPLESPERPIXEL))
     450               0 :     fprintf(fd, "  Samples/Pixel: %u\n", td->td_samplesperpixel);
     451               0 :   if (TIFFFieldSet(tif,FIELD_ROWSPERSTRIP)) {
     452               0 :     fprintf(fd, "  Rows/Strip: ");
     453               0 :     if (td->td_rowsperstrip == (uint32) -1)
     454               0 :       fprintf(fd, "(infinite)\n");
     455                 :     else
     456               0 :       fprintf(fd, "%lu\n", (unsigned long) td->td_rowsperstrip);
     457                 :   }
     458               0 :   if (TIFFFieldSet(tif,FIELD_MINSAMPLEVALUE))
     459               0 :     fprintf(fd, "  Min Sample Value: %u\n", td->td_minsamplevalue);
     460               0 :   if (TIFFFieldSet(tif,FIELD_MAXSAMPLEVALUE))
     461               0 :     fprintf(fd, "  Max Sample Value: %u\n", td->td_maxsamplevalue);
     462               0 :   if (TIFFFieldSet(tif,FIELD_SMINSAMPLEVALUE))
     463               0 :     fprintf(fd, "  SMin Sample Value: %g\n",
     464                 :         td->td_sminsamplevalue);
     465               0 :   if (TIFFFieldSet(tif,FIELD_SMAXSAMPLEVALUE))
     466               0 :     fprintf(fd, "  SMax Sample Value: %g\n",
     467                 :         td->td_smaxsamplevalue);
     468               0 :   if (TIFFFieldSet(tif,FIELD_PLANARCONFIG)) {
     469               0 :     fprintf(fd, "  Planar Configuration: ");
     470               0 :     switch (td->td_planarconfig) {
     471                 :     case PLANARCONFIG_CONTIG:
     472               0 :       fprintf(fd, "single image plane\n");
     473               0 :       break;
     474                 :     case PLANARCONFIG_SEPARATE:
     475               0 :       fprintf(fd, "separate image planes\n");
     476               0 :       break;
     477                 :     default:
     478               0 :       fprintf(fd, "%u (0x%x)\n",
     479               0 :           td->td_planarconfig, td->td_planarconfig);
     480                 :       break;
     481                 :     }
     482                 :   }
     483               0 :   if (TIFFFieldSet(tif,FIELD_PAGENUMBER))
     484               0 :     fprintf(fd, "  Page Number: %u-%u\n",
     485               0 :         td->td_pagenumber[0], td->td_pagenumber[1]);
     486               0 :   if (TIFFFieldSet(tif,FIELD_COLORMAP)) {
     487               0 :     fprintf(fd, "  Color Map: ");
     488               0 :     if (flags & TIFFPRINT_COLORMAP) {
     489               0 :       fprintf(fd, "\n");
     490               0 :       n = 1L<<td->td_bitspersample;
     491               0 :       for (l = 0; l < n; l++)
     492               0 :         fprintf(fd, "   %5lu: %5u %5u %5u\n",
     493                 :             l,
     494               0 :             td->td_colormap[0][l],
     495               0 :             td->td_colormap[1][l],
     496               0 :             td->td_colormap[2][l]);
     497                 :     } else
     498               0 :       fprintf(fd, "(present)\n");
     499                 :   }
     500               0 :   if (TIFFFieldSet(tif,FIELD_TRANSFERFUNCTION)) {
     501               0 :     fprintf(fd, "  Transfer Function: ");
     502               0 :     if (flags & TIFFPRINT_CURVES) {
     503               0 :       fprintf(fd, "\n");
     504               0 :       n = 1L<<td->td_bitspersample;
     505               0 :       for (l = 0; l < n; l++) {
     506               0 :         fprintf(fd, "    %2lu: %5u",
     507               0 :             l, td->td_transferfunction[0][l]);
     508               0 :         for (i = 1; i < td->td_samplesperpixel; i++)
     509               0 :           fprintf(fd, " %5u",
     510               0 :               td->td_transferfunction[i][l]);
     511               0 :         fputc('\n', fd);
     512                 :       }
     513                 :     } else
     514               0 :       fprintf(fd, "(present)\n");
     515                 :   }
     516               0 :   if (TIFFFieldSet(tif, FIELD_SUBIFD) && (td->td_subifd)) {
     517               0 :     fprintf(fd, "  SubIFD Offsets:");
     518               0 :     for (i = 0; i < td->td_nsubifd; i++)
     519                 : #if defined(__WIN32__) && defined(_MSC_VER)
     520                 :       fprintf(fd, " %5I64u",
     521                 :         (unsigned __int64) td->td_subifd[i]);
     522                 : #else
     523               0 :       fprintf(fd, " %5llu",
     524               0 :         (unsigned long long) td->td_subifd[i]);
     525                 : #endif
     526               0 :     fputc('\n', fd);
     527                 :   }
     528                 : 
     529                 :   /*
     530                 :   ** Custom tag support.
     531                 :   */
     532                 :   {
     533                 :     int  i;
     534                 :     short count;
     535                 : 
     536               0 :     count = (short) TIFFGetTagListCount(tif);
     537               0 :     for(i = 0; i < count; i++) {
     538               0 :       uint32 tag = TIFFGetTagListEntry(tif, i);
     539                 :       const TIFFField *fip;
     540                 :       uint32 value_count;
     541               0 :       int mem_alloc = 0;
     542                 :       void *raw_data;
     543                 : 
     544               0 :       fip = TIFFFieldWithTag(tif, tag);
     545               0 :       if(fip == NULL)
     546               0 :         continue;
     547                 : 
     548               0 :       if(fip->field_passcount) {
     549               0 :         if(TIFFGetField(tif, tag, &value_count, &raw_data) != 1)
     550               0 :           continue;
     551                 :       } else {
     552               0 :         if (fip->field_readcount == TIFF_VARIABLE
     553               0 :             || fip->field_readcount == TIFF_VARIABLE2)
     554               0 :           value_count = 1;
     555               0 :         else if (fip->field_readcount == TIFF_SPP)
     556               0 :           value_count = td->td_samplesperpixel;
     557                 :         else
     558               0 :           value_count = fip->field_readcount;
     559               0 :         if ((fip->field_type == TIFF_ASCII
     560               0 :             || fip->field_readcount == TIFF_VARIABLE
     561               0 :             || fip->field_readcount == TIFF_VARIABLE2
     562               0 :             || fip->field_readcount == TIFF_SPP
     563               0 :             || value_count > 1)
     564                 :             && fip->field_tag != TIFFTAG_PAGENUMBER
     565               0 :             && fip->field_tag != TIFFTAG_HALFTONEHINTS
     566               0 :             && fip->field_tag != TIFFTAG_YCBCRSUBSAMPLING
     567               0 :             && fip->field_tag != TIFFTAG_DOTRANGE) {
     568               0 :           if(TIFFGetField(tif, tag, &raw_data) != 1)
     569               0 :             continue;
     570               0 :         } else if (fip->field_tag != TIFFTAG_PAGENUMBER
     571               0 :             && fip->field_tag != TIFFTAG_HALFTONEHINTS
     572               0 :             && fip->field_tag != TIFFTAG_YCBCRSUBSAMPLING
     573               0 :             && fip->field_tag != TIFFTAG_DOTRANGE) {
     574               0 :           raw_data = _TIFFmalloc(
     575               0 :               _TIFFDataSize(fip->field_type)
     576                 :               * value_count);
     577               0 :           mem_alloc = 1;
     578               0 :           if(TIFFGetField(tif, tag, raw_data) != 1) {
     579               0 :             _TIFFfree(raw_data);
     580               0 :             continue;
     581                 :           }
     582                 :         } else {
     583                 :           /*
     584                 :            * XXX: Should be fixed and removed,
     585                 :            * see the notes related to
     586                 :            * TIFFTAG_PAGENUMBER,
     587                 :            * TIFFTAG_HALFTONEHINTS,
     588                 :            * TIFFTAG_YCBCRSUBSAMPLING and
     589                 :            * TIFFTAG_DOTRANGE tags in tif_dir.c.
     590                 :            */
     591                 :           char *tmp;
     592               0 :           raw_data = _TIFFmalloc(
     593               0 :               _TIFFDataSize(fip->field_type)
     594                 :               * value_count);
     595               0 :           tmp = raw_data;
     596               0 :           mem_alloc = 1;
     597               0 :           if(TIFFGetField(tif, tag, tmp,
     598                 :               tmp + _TIFFDataSize(fip->field_type)) != 1) {
     599               0 :             _TIFFfree(raw_data);
     600               0 :             continue;
     601                 :           }
     602                 :         }
     603                 :       }
     604                 : 
     605                 :       /*
     606                 :        * Catch the tags which needs to be specially handled
     607                 :        * and pretty print them. If tag not handled in
     608                 :        * _TIFFPrettyPrintField() fall down and print it as
     609                 :        * any other tag.
     610                 :        */
     611               0 :       if (!_TIFFPrettyPrintField(tif, fd, tag, value_count, raw_data))
     612               0 :         _TIFFPrintField(fd, fip, value_count, raw_data);
     613                 : 
     614               0 :       if(mem_alloc)
     615               0 :         _TIFFfree(raw_data);
     616                 :     }
     617                 :   }
     618                 :         
     619               0 :   if (tif->tif_tagmethods.printdir)
     620               0 :     (*tif->tif_tagmethods.printdir)(tif, fd, flags);
     621               0 :   if ((flags & TIFFPRINT_STRIPS) &&
     622               0 :       TIFFFieldSet(tif,FIELD_STRIPOFFSETS)) {
     623                 :     uint32 s;
     624                 : 
     625               0 :     fprintf(fd, "  %lu %s:\n",
     626                 :         (long) td->td_nstrips,
     627               0 :         isTiled(tif) ? "Tiles" : "Strips");
     628               0 :     for (s = 0; s < td->td_nstrips; s++)
     629                 : #if defined(__WIN32__) && defined(_MSC_VER)
     630                 :       fprintf(fd, "    %3lu: [%8I64u, %8I64u]\n",
     631                 :           (unsigned long) s,
     632                 :           (unsigned __int64) td->td_stripoffset[s],
     633                 :           (unsigned __int64) td->td_stripbytecount[s]);
     634                 : #else
     635               0 :       fprintf(fd, "    %3lu: [%8llu, %8llu]\n",
     636                 :           (unsigned long) s,
     637               0 :           (unsigned long long) td->td_stripoffset[s],
     638               0 :           (unsigned long long) td->td_stripbytecount[s]);
     639                 : #endif
     640                 :   }
     641               0 : }
     642                 : 
     643                 : void
     644               0 : _TIFFprintAscii(FILE* fd, const char* cp)
     645                 : {
     646               0 :   for (; *cp != '\0'; cp++) {
     647                 :     const char* tp;
     648                 : 
     649               0 :     if (isprint((int)*cp)) {
     650               0 :       fputc(*cp, fd);
     651               0 :       continue;
     652                 :     }
     653               0 :     for (tp = "\tt\bb\rr\nn\vv"; *tp; tp++)
     654               0 :       if (*tp++ == *cp)
     655               0 :         break;
     656               0 :     if (*tp)
     657               0 :       fprintf(fd, "\\%c", *tp);
     658                 :     else
     659               0 :       fprintf(fd, "\\%03o", *cp & 0xff);
     660                 :   }
     661               0 : }
     662                 : 
     663                 : void
     664               0 : _TIFFprintAsciiTag(FILE* fd, const char* name, const char* value)
     665                 : {
     666               0 :   fprintf(fd, "  %s: \"", name);
     667               0 :   _TIFFprintAscii(fd, value);
     668               0 :   fprintf(fd, "\"\n");
     669               0 : }
     670                 : 
     671                 : /* vim: set ts=8 sts=8 sw=8 noet: */

Generated by: LCOV version 1.7