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