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