Move the sources to trunk
[opencv] / otherlibs / _graphics / src / libtiff / tif_print.c
1 /* $Id: tif_print.c,v 1.1 2005/06/17 13:54:52 vp153 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 /*
64  * Print the contents of the current directory
65  * to the specified stdio file stream.
66  */
67 void
68 TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags)
69 {
70         register TIFFDirectory *td;
71         char *sep;
72         uint16 i;
73         long l, n;
74
75         fprintf(fd, "TIFF Directory at offset 0x%lx\n",
76                 (unsigned long)tif->tif_diroff);
77         td = &tif->tif_dir;
78         if (TIFFFieldSet(tif,FIELD_SUBFILETYPE)) {
79                 fprintf(fd, "  Subfile Type:");
80                 sep = " ";
81                 if (td->td_subfiletype & FILETYPE_REDUCEDIMAGE) {
82                         fprintf(fd, "%sreduced-resolution image", sep);
83                         sep = "/";
84                 }
85                 if (td->td_subfiletype & FILETYPE_PAGE) {
86                         fprintf(fd, "%smulti-page document", sep);
87                         sep = "/";
88                 }
89                 if (td->td_subfiletype & FILETYPE_MASK)
90                         fprintf(fd, "%stransparency mask", sep);
91                 fprintf(fd, " (%lu = 0x%lx)\n",
92                     (long) td->td_subfiletype, (long) td->td_subfiletype);
93         }
94         if (TIFFFieldSet(tif,FIELD_IMAGEDIMENSIONS)) {
95                 fprintf(fd, "  Image Width: %lu Image Length: %lu",
96                     (unsigned long) td->td_imagewidth, (unsigned long) td->td_imagelength);
97                 if (TIFFFieldSet(tif,FIELD_IMAGEDEPTH))
98                         fprintf(fd, " Image Depth: %lu",
99                             (unsigned long) td->td_imagedepth);
100                 fprintf(fd, "\n");
101         }
102
103         /* Begin Pixar */
104         if (TIFFFieldSet(tif,FIELD_IMAGEFULLWIDTH) ||
105             TIFFFieldSet(tif,FIELD_IMAGEFULLLENGTH)) {
106           fprintf(fd, "  Pixar Full Image Width: %lu Full Image Length: %lu\n",
107                   (unsigned long) td->td_imagefullwidth,
108                   (unsigned long) td->td_imagefulllength);
109         }
110         if (TIFFFieldSet(tif,FIELD_TEXTUREFORMAT))
111           _TIFFprintAsciiTag(fd, "Texture Format", td->td_textureformat);
112         if (TIFFFieldSet(tif,FIELD_WRAPMODES))
113           _TIFFprintAsciiTag(fd, "Texture Wrap Modes", td->td_wrapmodes);
114         if (TIFFFieldSet(tif,FIELD_FOVCOT))
115           fprintf(fd, "  Field of View Cotangent: %g\n", td->td_fovcot);
116         if (TIFFFieldSet(tif,FIELD_MATRIX_WORLDTOSCREEN)) {
117           typedef float Matrix[4][4];
118           Matrix*               m = (Matrix*)td->td_matrixWorldToScreen;
119           
120           fprintf(fd, "  Matrix NP:\n\t%g %g %g %g\n\t%g %g %g %g\n\t%g %g %g %g\n\t%g %g %g %g\n",
121                   (*m)[0][0], (*m)[0][1], (*m)[0][2], (*m)[0][3],
122                   (*m)[1][0], (*m)[1][1], (*m)[1][2], (*m)[1][3],
123                   (*m)[2][0], (*m)[2][1], (*m)[2][2], (*m)[2][3],
124                   (*m)[3][0], (*m)[3][1], (*m)[3][2], (*m)[3][3]);
125         }
126         if (TIFFFieldSet(tif,FIELD_MATRIX_WORLDTOCAMERA)) {
127           typedef float Matrix[4][4];
128           Matrix*               m = (Matrix*)td->td_matrixWorldToCamera;
129           
130           fprintf(fd, "  Matrix Nl:\n\t%g %g %g %g\n\t%g %g %g %g\n\t%g %g %g %g\n\t%g %g %g %g\n",
131                   (*m)[0][0], (*m)[0][1], (*m)[0][2], (*m)[0][3],
132                   (*m)[1][0], (*m)[1][1], (*m)[1][2], (*m)[1][3],
133                   (*m)[2][0], (*m)[2][1], (*m)[2][2], (*m)[2][3],
134                   (*m)[3][0], (*m)[3][1], (*m)[3][2], (*m)[3][3]);
135         }
136         /* End Pixar */
137         
138         if (TIFFFieldSet(tif,FIELD_TILEDIMENSIONS)) {
139                 fprintf(fd, "  Tile Width: %lu Tile Length: %lu",
140                     (unsigned long) td->td_tilewidth, (unsigned long) td->td_tilelength);
141                 if (TIFFFieldSet(tif,FIELD_TILEDEPTH))
142                         fprintf(fd, " Tile Depth: %lu",
143                             (unsigned long) td->td_tiledepth);
144                 fprintf(fd, "\n");
145         }
146         if (TIFFFieldSet(tif,FIELD_RESOLUTION)) {
147                 fprintf(fd, "  Resolution: %g, %g",
148                     td->td_xresolution, td->td_yresolution);
149                 if (TIFFFieldSet(tif,FIELD_RESOLUTIONUNIT)) {
150                         switch (td->td_resolutionunit) {
151                         case RESUNIT_NONE:
152                                 fprintf(fd, " (unitless)");
153                                 break;
154                         case RESUNIT_INCH:
155                                 fprintf(fd, " pixels/inch");
156                                 break;
157                         case RESUNIT_CENTIMETER:
158                                 fprintf(fd, " pixels/cm");
159                                 break;
160                         default:
161                                 fprintf(fd, " (unit %u = 0x%x)",
162                                     td->td_resolutionunit,
163                                     td->td_resolutionunit);
164                                 break;
165                         }
166                 }
167                 fprintf(fd, "\n");
168         }
169         if (TIFFFieldSet(tif,FIELD_POSITION))
170                 fprintf(fd, "  Position: %g, %g\n",
171                     td->td_xposition, td->td_yposition);
172         if (TIFFFieldSet(tif,FIELD_BITSPERSAMPLE))
173                 fprintf(fd, "  Bits/Sample: %u\n", td->td_bitspersample);
174         if (TIFFFieldSet(tif,FIELD_SAMPLEFORMAT)) {
175                 fprintf(fd, "  Sample Format: ");
176                 switch (td->td_sampleformat) {
177                 case SAMPLEFORMAT_VOID:
178                         fprintf(fd, "void\n");
179                         break;
180                 case SAMPLEFORMAT_INT:
181                         fprintf(fd, "signed integer\n");
182                         break;
183                 case SAMPLEFORMAT_UINT:
184                         fprintf(fd, "unsigned integer\n");
185                         break;
186                 case SAMPLEFORMAT_IEEEFP:
187                         fprintf(fd, "IEEE floating point\n");
188                         break;
189                 case SAMPLEFORMAT_COMPLEXINT:
190                         fprintf(fd, "complex signed integer\n");
191                         break;
192                 case SAMPLEFORMAT_COMPLEXIEEEFP:
193                         fprintf(fd, "complex IEEE floating point\n");
194                         break;
195                 default:
196                         fprintf(fd, "%u (0x%x)\n",
197                             td->td_sampleformat, td->td_sampleformat);
198                         break;
199                 }
200         }
201         if (TIFFFieldSet(tif,FIELD_COMPRESSION)) {
202                 const TIFFCodec* c = TIFFFindCODEC(td->td_compression);
203                 fprintf(fd, "  Compression Scheme: ");
204                 if (c)
205                         fprintf(fd, "%s\n", c->name);
206                 else
207                         fprintf(fd, "%u (0x%x)\n",
208                             td->td_compression, td->td_compression);
209         }
210         if (TIFFFieldSet(tif,FIELD_PHOTOMETRIC)) {
211                 fprintf(fd, "  Photometric Interpretation: ");
212                 if (td->td_photometric < NPHOTONAMES)
213                         fprintf(fd, "%s\n", photoNames[td->td_photometric]);
214                 else {
215                         switch (td->td_photometric) {
216                         case PHOTOMETRIC_LOGL:
217                                 fprintf(fd, "CIE Log2(L)\n");
218                                 break;
219                         case PHOTOMETRIC_LOGLUV:
220                                 fprintf(fd, "CIE Log2(L) (u',v')\n");
221                                 break;
222                         default:
223                                 fprintf(fd, "%u (0x%x)\n",
224                                     td->td_photometric, td->td_photometric);
225                                 break;
226                         }
227                 }
228         }
229         if (TIFFFieldSet(tif,FIELD_EXTRASAMPLES) && td->td_extrasamples) {
230                 fprintf(fd, "  Extra Samples: %u<", td->td_extrasamples);
231                 sep = "";
232                 for (i = 0; i < td->td_extrasamples; i++) {
233                         switch (td->td_sampleinfo[i]) {
234                         case EXTRASAMPLE_UNSPECIFIED:
235                                 fprintf(fd, "%sunspecified", sep);
236                                 break;
237                         case EXTRASAMPLE_ASSOCALPHA:
238                                 fprintf(fd, "%sassoc-alpha", sep);
239                                 break;
240                         case EXTRASAMPLE_UNASSALPHA:
241                                 fprintf(fd, "%sunassoc-alpha", sep);
242                                 break;
243                         default:
244                                 fprintf(fd, "%s%u (0x%x)", sep,
245                                     td->td_sampleinfo[i], td->td_sampleinfo[i]);
246                                 break;
247                         }
248                         sep = ", ";
249                 }
250                 fprintf(fd, ">\n");
251         }
252         if (TIFFFieldSet(tif,FIELD_STONITS)) {
253                 fprintf(fd, "  Sample to Nits conversion factor: %.4e\n",
254                                 td->td_stonits);
255         }
256         if (TIFFFieldSet(tif,FIELD_INKSET)) {
257                 fprintf(fd, "  Ink Set: ");
258                 switch (td->td_inkset) {
259                 case INKSET_CMYK:
260                         fprintf(fd, "CMYK\n");
261                         break;
262                 default:
263                         fprintf(fd, "%u (0x%x)\n",
264                             td->td_inkset, td->td_inkset);
265                         break;
266                 }
267         }
268         if (TIFFFieldSet(tif,FIELD_INKNAMES)) {
269                 char* cp;
270                 fprintf(fd, "  Ink Names: ");
271                 i = td->td_samplesperpixel;
272                 sep = "";
273                 for (cp = td->td_inknames; i > 0; cp = strchr(cp,'\0')+1, i--) {
274                         fputs(sep, fd);
275                         _TIFFprintAscii(fd, cp);
276                         sep = ", ";
277                 }
278                 fputs("\n", fd);
279         }
280         if (TIFFFieldSet(tif,FIELD_NUMBEROFINKS))
281                 fprintf(fd, "  Number of Inks: %u\n", td->td_ninks);
282         if (TIFFFieldSet(tif,FIELD_DOTRANGE))
283                 fprintf(fd, "  Dot Range: %u-%u\n",
284                     td->td_dotrange[0], td->td_dotrange[1]);
285         if (TIFFFieldSet(tif,FIELD_TARGETPRINTER))
286                 _TIFFprintAsciiTag(fd, "Target Printer", td->td_targetprinter);
287         if (TIFFFieldSet(tif,FIELD_THRESHHOLDING)) {
288                 fprintf(fd, "  Thresholding: ");
289                 switch (td->td_threshholding) {
290                 case THRESHHOLD_BILEVEL:
291                         fprintf(fd, "bilevel art scan\n");
292                         break;
293                 case THRESHHOLD_HALFTONE:
294                         fprintf(fd, "halftone or dithered scan\n");
295                         break;
296                 case THRESHHOLD_ERRORDIFFUSE:
297                         fprintf(fd, "error diffused\n");
298                         break;
299                 default:
300                         fprintf(fd, "%u (0x%x)\n",
301                             td->td_threshholding, td->td_threshholding);
302                         break;
303                 }
304         }
305         if (TIFFFieldSet(tif,FIELD_FILLORDER)) {
306                 fprintf(fd, "  FillOrder: ");
307                 switch (td->td_fillorder) {
308                 case FILLORDER_MSB2LSB:
309                         fprintf(fd, "msb-to-lsb\n");
310                         break;
311                 case FILLORDER_LSB2MSB:
312                         fprintf(fd, "lsb-to-msb\n");
313                         break;
314                 default:
315                         fprintf(fd, "%u (0x%x)\n",
316                             td->td_fillorder, td->td_fillorder);
317                         break;
318                 }
319         }
320         if (TIFFFieldSet(tif,FIELD_YCBCRSUBSAMPLING))
321         {
322             /*
323              * For hacky reasons (see tif_jpeg.c - JPEGFixupTestSubsampling),
324              * we need to fetch this rather than trust what is in our
325              * structures.
326              */
327             uint16 subsampling[2];
328
329             TIFFGetField( tif, TIFFTAG_YCBCRSUBSAMPLING, 
330                           subsampling + 0, subsampling + 1 );
331                 fprintf(fd, "  YCbCr Subsampling: %u, %u\n",
332                         subsampling[0], subsampling[1] );
333         }
334         if (TIFFFieldSet(tif,FIELD_YCBCRPOSITIONING)) {
335                 fprintf(fd, "  YCbCr Positioning: ");
336                 switch (td->td_ycbcrpositioning) {
337                 case YCBCRPOSITION_CENTERED:
338                         fprintf(fd, "centered\n");
339                         break;
340                 case YCBCRPOSITION_COSITED:
341                         fprintf(fd, "cosited\n");
342                         break;
343                 default:
344                         fprintf(fd, "%u (0x%x)\n",
345                             td->td_ycbcrpositioning, td->td_ycbcrpositioning);
346                         break;
347                 }
348         }
349         if (TIFFFieldSet(tif,FIELD_YCBCRCOEFFICIENTS))
350                 fprintf(fd, "  YCbCr Coefficients: %g, %g, %g\n",
351                     td->td_ycbcrcoeffs[0],
352                     td->td_ycbcrcoeffs[1],
353                     td->td_ycbcrcoeffs[2]);
354         if (TIFFFieldSet(tif,FIELD_HALFTONEHINTS))
355                 fprintf(fd, "  Halftone Hints: light %u dark %u\n",
356                     td->td_halftonehints[0], td->td_halftonehints[1]);
357         if (TIFFFieldSet(tif,FIELD_ARTIST))
358                 _TIFFprintAsciiTag(fd, "Artist", td->td_artist);
359         if (TIFFFieldSet(tif,FIELD_DATETIME))
360                 _TIFFprintAsciiTag(fd, "Date & Time", td->td_datetime);
361         if (TIFFFieldSet(tif,FIELD_HOSTCOMPUTER))
362                 _TIFFprintAsciiTag(fd, "Host Computer", td->td_hostcomputer);
363         if (TIFFFieldSet(tif,FIELD_COPYRIGHT))
364                 _TIFFprintAsciiTag(fd, "Copyright", td->td_copyright);
365         if (TIFFFieldSet(tif,FIELD_DOCUMENTNAME))
366                 _TIFFprintAsciiTag(fd, "Document Name", td->td_documentname);
367         if (TIFFFieldSet(tif,FIELD_IMAGEDESCRIPTION))
368                 _TIFFprintAsciiTag(fd, "Image Description", td->td_imagedescription);
369         if (TIFFFieldSet(tif,FIELD_MAKE))
370                 _TIFFprintAsciiTag(fd, "Make", td->td_make);
371         if (TIFFFieldSet(tif,FIELD_MODEL))
372                 _TIFFprintAsciiTag(fd, "Model", td->td_model);
373         if (TIFFFieldSet(tif,FIELD_ORIENTATION)) {
374                 fprintf(fd, "  Orientation: ");
375                 if (td->td_orientation < NORIENTNAMES)
376                         fprintf(fd, "%s\n", orientNames[td->td_orientation]);
377                 else
378                         fprintf(fd, "%u (0x%x)\n",
379                             td->td_orientation, td->td_orientation);
380         }
381         if (TIFFFieldSet(tif,FIELD_SAMPLESPERPIXEL))
382                 fprintf(fd, "  Samples/Pixel: %u\n", td->td_samplesperpixel);
383         if (TIFFFieldSet(tif,FIELD_ROWSPERSTRIP)) {
384                 fprintf(fd, "  Rows/Strip: ");
385                 if (td->td_rowsperstrip == (uint32) -1)
386                         fprintf(fd, "(infinite)\n");
387                 else
388                         fprintf(fd, "%lu\n", (unsigned long) td->td_rowsperstrip);
389         }
390         if (TIFFFieldSet(tif,FIELD_MINSAMPLEVALUE))
391                 fprintf(fd, "  Min Sample Value: %u\n", td->td_minsamplevalue);
392         if (TIFFFieldSet(tif,FIELD_MAXSAMPLEVALUE))
393                 fprintf(fd, "  Max Sample Value: %u\n", td->td_maxsamplevalue);
394         if (TIFFFieldSet(tif,FIELD_SMINSAMPLEVALUE))
395                 fprintf(fd, "  SMin Sample Value: %g\n",
396                     td->td_sminsamplevalue);
397         if (TIFFFieldSet(tif,FIELD_SMAXSAMPLEVALUE))
398                 fprintf(fd, "  SMax Sample Value: %g\n",
399                     td->td_smaxsamplevalue);
400         if (TIFFFieldSet(tif,FIELD_PLANARCONFIG)) {
401                 fprintf(fd, "  Planar Configuration: ");
402                 switch (td->td_planarconfig) {
403                 case PLANARCONFIG_CONTIG:
404                         fprintf(fd, "single image plane\n");
405                         break;
406                 case PLANARCONFIG_SEPARATE:
407                         fprintf(fd, "separate image planes\n");
408                         break;
409                 default:
410                         fprintf(fd, "%u (0x%x)\n",
411                             td->td_planarconfig, td->td_planarconfig);
412                         break;
413                 }
414         }
415         if (TIFFFieldSet(tif,FIELD_PAGENAME))
416                 _TIFFprintAsciiTag(fd, "Page Name", td->td_pagename);
417         if (TIFFFieldSet(tif,FIELD_PAGENUMBER))
418                 fprintf(fd, "  Page Number: %u-%u\n",
419                     td->td_pagenumber[0], td->td_pagenumber[1]);
420         if (TIFFFieldSet(tif,FIELD_COLORMAP)) {
421                 fprintf(fd, "  Color Map: ");
422                 if (flags & TIFFPRINT_COLORMAP) {
423                         fprintf(fd, "\n");
424                         n = 1L<<td->td_bitspersample;
425                         for (l = 0; l < n; l++)
426                                 fprintf(fd, "   %5lu: %5u %5u %5u\n",
427                                     l,
428                                     td->td_colormap[0][l],
429                                     td->td_colormap[1][l],
430                                     td->td_colormap[2][l]);
431                 } else
432                         fprintf(fd, "(present)\n");
433         }
434         if (TIFFFieldSet(tif,FIELD_WHITEPOINT))
435                 fprintf(fd, "  White Point: %g-%g\n",
436                     td->td_whitepoint[0], td->td_whitepoint[1]);
437         if (TIFFFieldSet(tif,FIELD_PRIMARYCHROMAS))
438                 fprintf(fd, "  Primary Chromaticities: %g,%g %g,%g %g,%g\n",
439                     td->td_primarychromas[0], td->td_primarychromas[1],
440                     td->td_primarychromas[2], td->td_primarychromas[3],
441                     td->td_primarychromas[4], td->td_primarychromas[5]);
442         if (TIFFFieldSet(tif,FIELD_REFBLACKWHITE)) {
443                 fprintf(fd, "  Reference Black/White:\n");
444                 for (i = 0; i < td->td_samplesperpixel; i++)
445                         fprintf(fd, "    %2d: %5g %5g\n",
446                             i,
447                             td->td_refblackwhite[2*i+0],
448                             td->td_refblackwhite[2*i+1]);
449         }
450         if (TIFFFieldSet(tif,FIELD_TRANSFERFUNCTION)) {
451                 fprintf(fd, "  Transfer Function: ");
452                 if (flags & TIFFPRINT_CURVES) {
453                         fprintf(fd, "\n");
454                         n = 1L<<td->td_bitspersample;
455                         for (l = 0; l < n; l++) {
456                                 fprintf(fd, "    %2lu: %5u",
457                                     l, td->td_transferfunction[0][l]);
458                                 for (i = 1; i < td->td_samplesperpixel; i++)
459                                         fprintf(fd, " %5u",
460                                             td->td_transferfunction[i][l]);
461                                 fputc('\n', fd);
462                         }
463                 } else
464                         fprintf(fd, "(present)\n");
465         }
466         if (TIFFFieldSet(tif,FIELD_ICCPROFILE))
467                 fprintf(fd, "  ICC Profile: <present>, %lu bytes\n",
468                     (unsigned long) td->td_profileLength);
469         if (TIFFFieldSet(tif,FIELD_PHOTOSHOP))
470                 fprintf(fd, "  Photoshop Data: <present>, %lu bytes\n",
471                     (unsigned long) td->td_photoshopLength);
472         if (TIFFFieldSet(tif,FIELD_RICHTIFFIPTC))
473                 fprintf(fd, "  RichTIFFIPTC Data: <present>, %lu bytes\n",
474                     (unsigned long) td->td_richtiffiptcLength);
475         if (TIFFFieldSet(tif, FIELD_SUBIFD)) {
476                 fprintf(fd, "  SubIFD Offsets:");
477                 for (i = 0; i < td->td_nsubifd; i++)
478                         fprintf(fd, " %5lu", (long) td->td_subifd[i]);
479                 fputc('\n', fd);
480         }
481         if (TIFFFieldSet(tif,FIELD_XMLPACKET)) {
482             fprintf(fd, "  XMLPacket (XMP Metadata):\n" );
483             for( i=0; i < td->td_xmlpacketLength; i++ )
484                 fputc( ((char *)td->td_xmlpacketData)[i], fd );
485             fprintf( fd, "\n" );
486         }
487
488         /*
489         ** Custom tag support.
490         */
491         {
492             int  i;
493             short count;
494
495             count = (short) TIFFGetTagListCount( tif );
496             for( i = 0; i < count; i++ )
497             {
498                 ttag_t  tag = TIFFGetTagListEntry( tif, i );
499                 const TIFFFieldInfo *fld;
500
501                 fld = TIFFFieldWithTag( tif, tag );
502                 if( fld == NULL )
503                     continue;
504
505                 if( fld->field_passcount )
506                 {
507                     short value_count;
508                     int j;
509                     void *raw_data;
510                     
511                     if( TIFFGetField( tif, tag, &value_count, &raw_data ) != 1 )
512                         continue;
513
514                     fprintf(fd, "  %s: ", fld->field_name );
515
516                     for( j = 0; j < value_count; j++ )
517                     {
518                         if( fld->field_type == TIFF_BYTE )
519                             fprintf( fd, "%d",
520                                      (int) ((char *) raw_data)[j] );
521                         else if( fld->field_type == TIFF_SHORT )
522                             fprintf( fd, "%d",
523                                      (int) ((unsigned short *) raw_data)[j] );
524                         else if( fld->field_type == TIFF_SSHORT )
525                             fprintf( fd, "%d",
526                                      (int) ((short *) raw_data)[j] );
527                         else if( fld->field_type == TIFF_LONG )
528                             fprintf( fd, "%d",
529                                      (int) ((unsigned long *) raw_data)[j] );
530                         else if( fld->field_type == TIFF_SLONG )
531                             fprintf( fd, "%d",
532                                      (int) ((long *) raw_data)[j] );
533                         else if( fld->field_type == TIFF_RATIONAL )
534                             fprintf( fd, "%f",
535                                      ((float *) raw_data)[j] );
536                         else if( fld->field_type == TIFF_SRATIONAL )
537                             fprintf( fd, "%f",
538                                      ((float *) raw_data)[j] );
539                         else if( fld->field_type == TIFF_ASCII )
540                         {
541                             fprintf( fd, "%s",
542                                      (char *) raw_data );
543                             break;
544                         }
545                         else if( fld->field_type == TIFF_DOUBLE )
546                             fprintf( fd, "%f",
547                                      ((double *) raw_data)[j] );
548                         else if( fld->field_type == TIFF_FLOAT )
549                             fprintf( fd, "%f",
550                                      ((float *) raw_data)[j] );
551                         else
552                         {
553                             fprintf( fd,
554                                      "<unsupported data type in TIFFPrint>" );
555                             break;
556                         }
557
558                         if( j < value_count-1 )
559                             fprintf( fd, "," );
560                     }
561                     fprintf( fd, "\n" );
562                 } 
563                 else if( !fld->field_passcount
564                          && fld->field_type == TIFF_ASCII )
565                 {
566                     char *data;
567                     
568                     if( TIFFGetField( tif, tag, &data ) )
569                         fprintf(fd, "  %s: %s\n", fld->field_name, data );
570                 }
571             }
572         }
573         
574         if (tif->tif_tagmethods.printdir)
575                 (*tif->tif_tagmethods.printdir)(tif, fd, flags);
576         if ((flags & TIFFPRINT_STRIPS) &&
577             TIFFFieldSet(tif,FIELD_STRIPOFFSETS)) {
578                 tstrip_t s;
579
580                 fprintf(fd, "  %lu %s:\n",
581                     (long) td->td_nstrips,
582                     isTiled(tif) ? "Tiles" : "Strips");
583                 for (s = 0; s < td->td_nstrips; s++)
584                         fprintf(fd, "    %3lu: [%8lu, %8lu]\n",
585                             (unsigned long) s,
586                             (unsigned long) td->td_stripoffset[s],
587                             (unsigned long) td->td_stripbytecount[s]);
588         }
589 }
590
591 void
592 _TIFFprintAscii(FILE* fd, const char* cp)
593 {
594         for (; *cp != '\0'; cp++) {
595                 const char* tp;
596
597                 if (isprint((int)*cp)) {
598                         fputc(*cp, fd);
599                         continue;
600                 }
601                 for (tp = "\tt\bb\rr\nn\vv"; *tp; tp++)
602                         if (*tp++ == *cp)
603                                 break;
604                 if (*tp)
605                         fprintf(fd, "\\%c", *tp);
606                 else
607                         fprintf(fd, "\\%03o", *cp & 0xff);
608         }
609 }
610
611 void
612 _TIFFprintAsciiTag(FILE* fd, const char* name, const char* value)
613 {
614         fprintf(fd, "  %s: \"", name);
615         _TIFFprintAscii(fd, value);
616         fprintf(fd, "\"\n");
617 }
618
619 /* vim: set ts=8 sts=8 sw=8 noet: */