b5a3e8cb7c5c3ea324c6fd339e98674a8f51d8de
[reactos.git] / dll / 3rdparty / libtiff / tif_print.c
1 /*
2 * Copyright (c) 1988-1997 Sam Leffler
3 * Copyright (c) 1991-1997 Silicon Graphics, Inc.
4 *
5 * Permission to use, copy, modify, distribute, and sell this software and
6 * its documentation for any purpose is hereby granted without fee, provided
7 * that (i) the above copyright notices and this permission notice appear in
8 * all copies of the software and related documentation, and (ii) the names of
9 * Sam Leffler and Silicon Graphics may not be used in any advertising or
10 * publicity relating to the software without the specific, prior written
11 * permission of Sam Leffler and Silicon Graphics.
12 *
13 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
14 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
15 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
16 *
17 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
18 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
19 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
21 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
22 * OF THIS SOFTWARE.
23 */
24
25 /*
26 * TIFF Library.
27 *
28 * Directory Printing Support
29 */
30
31 #include <precomp.h>
32 //#include <stdio.h>
33
34 //#include <ctype.h>
35
36 static void
37 _TIFFprintAsciiBounded(FILE* fd, const char* cp, size_t max_chars);
38
39 static const char * const 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 * const 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 long l, n;
240
241 #if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
242 fprintf(fd, "TIFF Directory at offset 0x%I64x (%I64u)\n",
243 (unsigned __int64) tif->tif_diroff,
244 (unsigned __int64) tif->tif_diroff);
245 #else
246 fprintf(fd, "TIFF Directory at offset 0x%llx (%llu)\n",
247 (unsigned long long) tif->tif_diroff,
248 (unsigned long long) tif->tif_diroff);
249 #endif
250 if (TIFFFieldSet(tif,FIELD_SUBFILETYPE)) {
251 fprintf(fd, " Subfile Type:");
252 sep = " ";
253 if (td->td_subfiletype & FILETYPE_REDUCEDIMAGE) {
254 fprintf(fd, "%sreduced-resolution image", sep);
255 sep = "/";
256 }
257 if (td->td_subfiletype & FILETYPE_PAGE) {
258 fprintf(fd, "%smulti-page document", sep);
259 sep = "/";
260 }
261 if (td->td_subfiletype & FILETYPE_MASK)
262 fprintf(fd, "%stransparency mask", sep);
263 fprintf(fd, " (%lu = 0x%lx)\n",
264 (unsigned long) td->td_subfiletype, (long) td->td_subfiletype);
265 }
266 if (TIFFFieldSet(tif,FIELD_IMAGEDIMENSIONS)) {
267 fprintf(fd, " Image Width: %lu Image Length: %lu",
268 (unsigned long) td->td_imagewidth, (unsigned long) td->td_imagelength);
269 if (TIFFFieldSet(tif,FIELD_IMAGEDEPTH))
270 fprintf(fd, " Image Depth: %lu",
271 (unsigned long) td->td_imagedepth);
272 fprintf(fd, "\n");
273 }
274 if (TIFFFieldSet(tif,FIELD_TILEDIMENSIONS)) {
275 fprintf(fd, " Tile Width: %lu Tile Length: %lu",
276 (unsigned long) td->td_tilewidth, (unsigned long) td->td_tilelength);
277 if (TIFFFieldSet(tif,FIELD_TILEDEPTH))
278 fprintf(fd, " Tile Depth: %lu",
279 (unsigned long) td->td_tiledepth);
280 fprintf(fd, "\n");
281 }
282 if (TIFFFieldSet(tif,FIELD_RESOLUTION)) {
283 fprintf(fd, " Resolution: %g, %g",
284 td->td_xresolution, td->td_yresolution);
285 if (TIFFFieldSet(tif,FIELD_RESOLUTIONUNIT)) {
286 switch (td->td_resolutionunit) {
287 case RESUNIT_NONE:
288 fprintf(fd, " (unitless)");
289 break;
290 case RESUNIT_INCH:
291 fprintf(fd, " pixels/inch");
292 break;
293 case RESUNIT_CENTIMETER:
294 fprintf(fd, " pixels/cm");
295 break;
296 default:
297 fprintf(fd, " (unit %u = 0x%x)",
298 td->td_resolutionunit,
299 td->td_resolutionunit);
300 break;
301 }
302 }
303 fprintf(fd, "\n");
304 }
305 if (TIFFFieldSet(tif,FIELD_POSITION))
306 fprintf(fd, " Position: %g, %g\n",
307 td->td_xposition, td->td_yposition);
308 if (TIFFFieldSet(tif,FIELD_BITSPERSAMPLE))
309 fprintf(fd, " Bits/Sample: %u\n", td->td_bitspersample);
310 if (TIFFFieldSet(tif,FIELD_SAMPLEFORMAT)) {
311 fprintf(fd, " Sample Format: ");
312 switch (td->td_sampleformat) {
313 case SAMPLEFORMAT_VOID:
314 fprintf(fd, "void\n");
315 break;
316 case SAMPLEFORMAT_INT:
317 fprintf(fd, "signed integer\n");
318 break;
319 case SAMPLEFORMAT_UINT:
320 fprintf(fd, "unsigned integer\n");
321 break;
322 case SAMPLEFORMAT_IEEEFP:
323 fprintf(fd, "IEEE floating point\n");
324 break;
325 case SAMPLEFORMAT_COMPLEXINT:
326 fprintf(fd, "complex signed integer\n");
327 break;
328 case SAMPLEFORMAT_COMPLEXIEEEFP:
329 fprintf(fd, "complex IEEE floating point\n");
330 break;
331 default:
332 fprintf(fd, "%u (0x%x)\n",
333 td->td_sampleformat, td->td_sampleformat);
334 break;
335 }
336 }
337 if (TIFFFieldSet(tif,FIELD_COMPRESSION)) {
338 const TIFFCodec* c = TIFFFindCODEC(td->td_compression);
339 fprintf(fd, " Compression Scheme: ");
340 if (c)
341 fprintf(fd, "%s\n", c->name);
342 else
343 fprintf(fd, "%u (0x%x)\n",
344 td->td_compression, td->td_compression);
345 }
346 if (TIFFFieldSet(tif,FIELD_PHOTOMETRIC)) {
347 fprintf(fd, " Photometric Interpretation: ");
348 if (td->td_photometric < NPHOTONAMES)
349 fprintf(fd, "%s\n", photoNames[td->td_photometric]);
350 else {
351 switch (td->td_photometric) {
352 case PHOTOMETRIC_LOGL:
353 fprintf(fd, "CIE Log2(L)\n");
354 break;
355 case PHOTOMETRIC_LOGLUV:
356 fprintf(fd, "CIE Log2(L) (u',v')\n");
357 break;
358 default:
359 fprintf(fd, "%u (0x%x)\n",
360 td->td_photometric, td->td_photometric);
361 break;
362 }
363 }
364 }
365 if (TIFFFieldSet(tif,FIELD_EXTRASAMPLES) && td->td_extrasamples) {
366 uint16 i;
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 uint16 i;
392 fprintf(fd, " Ink Names: ");
393 i = td->td_samplesperpixel;
394 sep = "";
395 for (cp = td->td_inknames;
396 i > 0 && cp < td->td_inknames + td->td_inknameslen;
397 cp = strchr(cp,'\0')+1, i--) {
398 size_t max_chars =
399 td->td_inknameslen - (cp - td->td_inknames);
400 fputs(sep, fd);
401 _TIFFprintAsciiBounded(fd, cp, max_chars);
402 sep = ", ";
403 }
404 fputs("\n", fd);
405 }
406 if (TIFFFieldSet(tif,FIELD_THRESHHOLDING)) {
407 fprintf(fd, " Thresholding: ");
408 switch (td->td_threshholding) {
409 case THRESHHOLD_BILEVEL:
410 fprintf(fd, "bilevel art scan\n");
411 break;
412 case THRESHHOLD_HALFTONE:
413 fprintf(fd, "halftone or dithered scan\n");
414 break;
415 case THRESHHOLD_ERRORDIFFUSE:
416 fprintf(fd, "error diffused\n");
417 break;
418 default:
419 fprintf(fd, "%u (0x%x)\n",
420 td->td_threshholding, td->td_threshholding);
421 break;
422 }
423 }
424 if (TIFFFieldSet(tif,FIELD_FILLORDER)) {
425 fprintf(fd, " FillOrder: ");
426 switch (td->td_fillorder) {
427 case FILLORDER_MSB2LSB:
428 fprintf(fd, "msb-to-lsb\n");
429 break;
430 case FILLORDER_LSB2MSB:
431 fprintf(fd, "lsb-to-msb\n");
432 break;
433 default:
434 fprintf(fd, "%u (0x%x)\n",
435 td->td_fillorder, td->td_fillorder);
436 break;
437 }
438 }
439 if (TIFFFieldSet(tif,FIELD_YCBCRSUBSAMPLING))
440 {
441 fprintf(fd, " YCbCr Subsampling: %u, %u\n",
442 td->td_ycbcrsubsampling[0], td->td_ycbcrsubsampling[1] );
443 }
444 if (TIFFFieldSet(tif,FIELD_YCBCRPOSITIONING)) {
445 fprintf(fd, " YCbCr Positioning: ");
446 switch (td->td_ycbcrpositioning) {
447 case YCBCRPOSITION_CENTERED:
448 fprintf(fd, "centered\n");
449 break;
450 case YCBCRPOSITION_COSITED:
451 fprintf(fd, "cosited\n");
452 break;
453 default:
454 fprintf(fd, "%u (0x%x)\n",
455 td->td_ycbcrpositioning, td->td_ycbcrpositioning);
456 break;
457 }
458 }
459 if (TIFFFieldSet(tif,FIELD_HALFTONEHINTS))
460 fprintf(fd, " Halftone Hints: light %u dark %u\n",
461 td->td_halftonehints[0], td->td_halftonehints[1]);
462 if (TIFFFieldSet(tif,FIELD_ORIENTATION)) {
463 fprintf(fd, " Orientation: ");
464 if (td->td_orientation < NORIENTNAMES)
465 fprintf(fd, "%s\n", orientNames[td->td_orientation]);
466 else
467 fprintf(fd, "%u (0x%x)\n",
468 td->td_orientation, td->td_orientation);
469 }
470 if (TIFFFieldSet(tif,FIELD_SAMPLESPERPIXEL))
471 fprintf(fd, " Samples/Pixel: %u\n", td->td_samplesperpixel);
472 if (TIFFFieldSet(tif,FIELD_ROWSPERSTRIP)) {
473 fprintf(fd, " Rows/Strip: ");
474 if (td->td_rowsperstrip == (uint32) -1)
475 fprintf(fd, "(infinite)\n");
476 else
477 fprintf(fd, "%lu\n", (unsigned long) td->td_rowsperstrip);
478 }
479 if (TIFFFieldSet(tif,FIELD_MINSAMPLEVALUE))
480 fprintf(fd, " Min Sample Value: %u\n", td->td_minsamplevalue);
481 if (TIFFFieldSet(tif,FIELD_MAXSAMPLEVALUE))
482 fprintf(fd, " Max Sample Value: %u\n", td->td_maxsamplevalue);
483 if (TIFFFieldSet(tif,FIELD_SMINSAMPLEVALUE)) {
484 int i;
485 int count = (tif->tif_flags & TIFF_PERSAMPLE) ? td->td_samplesperpixel : 1;
486 fprintf(fd, " SMin Sample Value:");
487 for (i = 0; i < count; ++i)
488 fprintf(fd, " %g", td->td_sminsamplevalue[i]);
489 fprintf(fd, "\n");
490 }
491 if (TIFFFieldSet(tif,FIELD_SMAXSAMPLEVALUE)) {
492 int i;
493 int count = (tif->tif_flags & TIFF_PERSAMPLE) ? td->td_samplesperpixel : 1;
494 fprintf(fd, " SMax Sample Value:");
495 for (i = 0; i < count; ++i)
496 fprintf(fd, " %g", td->td_smaxsamplevalue[i]);
497 fprintf(fd, "\n");
498 }
499 if (TIFFFieldSet(tif,FIELD_PLANARCONFIG)) {
500 fprintf(fd, " Planar Configuration: ");
501 switch (td->td_planarconfig) {
502 case PLANARCONFIG_CONTIG:
503 fprintf(fd, "single image plane\n");
504 break;
505 case PLANARCONFIG_SEPARATE:
506 fprintf(fd, "separate image planes\n");
507 break;
508 default:
509 fprintf(fd, "%u (0x%x)\n",
510 td->td_planarconfig, td->td_planarconfig);
511 break;
512 }
513 }
514 if (TIFFFieldSet(tif,FIELD_PAGENUMBER))
515 fprintf(fd, " Page Number: %u-%u\n",
516 td->td_pagenumber[0], td->td_pagenumber[1]);
517 if (TIFFFieldSet(tif,FIELD_COLORMAP)) {
518 fprintf(fd, " Color Map: ");
519 if (flags & TIFFPRINT_COLORMAP) {
520 fprintf(fd, "\n");
521 n = 1L<<td->td_bitspersample;
522 for (l = 0; l < n; l++)
523 fprintf(fd, " %5ld: %5u %5u %5u\n",
524 l,
525 td->td_colormap[0][l],
526 td->td_colormap[1][l],
527 td->td_colormap[2][l]);
528 } else
529 fprintf(fd, "(present)\n");
530 }
531 if (TIFFFieldSet(tif,FIELD_REFBLACKWHITE)) {
532 int i;
533 fprintf(fd, " Reference Black/White:\n");
534 for (i = 0; i < 3; i++)
535 fprintf(fd, " %2d: %5g %5g\n", i,
536 td->td_refblackwhite[2*i+0],
537 td->td_refblackwhite[2*i+1]);
538 }
539 if (TIFFFieldSet(tif,FIELD_TRANSFERFUNCTION)) {
540 fprintf(fd, " Transfer Function: ");
541 if (flags & TIFFPRINT_CURVES) {
542 fprintf(fd, "\n");
543 n = 1L<<td->td_bitspersample;
544 for (l = 0; l < n; l++) {
545 uint16 i;
546 fprintf(fd, " %2ld: %5u",
547 l, td->td_transferfunction[0][l]);
548 for (i = 1; i < td->td_samplesperpixel - td->td_extrasamples && i < 3; i++)
549 fprintf(fd, " %5u",
550 td->td_transferfunction[i][l]);
551 fputc('\n', fd);
552 }
553 } else
554 fprintf(fd, "(present)\n");
555 }
556 if (TIFFFieldSet(tif, FIELD_SUBIFD) && (td->td_subifd)) {
557 uint16 i;
558 fprintf(fd, " SubIFD Offsets:");
559 for (i = 0; i < td->td_nsubifd; i++)
560 #if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
561 fprintf(fd, " %5I64u",
562 (unsigned __int64) td->td_subifd[i]);
563 #else
564 fprintf(fd, " %5llu",
565 (unsigned long long) td->td_subifd[i]);
566 #endif
567 fputc('\n', fd);
568 }
569
570 /*
571 ** Custom tag support.
572 */
573 {
574 int i;
575 short count;
576
577 count = (short) TIFFGetTagListCount(tif);
578 for(i = 0; i < count; i++) {
579 uint32 tag = TIFFGetTagListEntry(tif, i);
580 const TIFFField *fip;
581 uint32 value_count;
582 int mem_alloc = 0;
583 void *raw_data;
584
585 fip = TIFFFieldWithTag(tif, tag);
586 if(fip == NULL)
587 continue;
588
589 if(fip->field_passcount) {
590 if (fip->field_readcount == TIFF_VARIABLE2 ) {
591 if(TIFFGetField(tif, tag, &value_count, &raw_data) != 1)
592 continue;
593 } else if (fip->field_readcount == TIFF_VARIABLE ) {
594 uint16 small_value_count;
595 if(TIFFGetField(tif, tag, &small_value_count, &raw_data) != 1)
596 continue;
597 value_count = small_value_count;
598 } else {
599 assert (fip->field_readcount == TIFF_VARIABLE
600 || fip->field_readcount == TIFF_VARIABLE2);
601 continue;
602 }
603 } else {
604 if (fip->field_readcount == TIFF_VARIABLE
605 || fip->field_readcount == TIFF_VARIABLE2)
606 value_count = 1;
607 else if (fip->field_readcount == TIFF_SPP)
608 value_count = td->td_samplesperpixel;
609 else
610 value_count = fip->field_readcount;
611 if (fip->field_tag == TIFFTAG_DOTRANGE
612 && strcmp(fip->field_name,"DotRange") == 0) {
613 /* TODO: This is an evil exception and should not have been
614 handled this way ... likely best if we move it into
615 the directory structure with an explicit field in
616 libtiff 4.1 and assign it a FIELD_ value */
617 static uint16 dotrange[2];
618 raw_data = dotrange;
619 TIFFGetField(tif, tag, dotrange+0, dotrange+1);
620 } else if (fip->field_type == TIFF_ASCII
621 || fip->field_readcount == TIFF_VARIABLE
622 || fip->field_readcount == TIFF_VARIABLE2
623 || fip->field_readcount == TIFF_SPP
624 || value_count > 1) {
625 if(TIFFGetField(tif, tag, &raw_data) != 1)
626 continue;
627 } else {
628 raw_data = _TIFFmalloc(
629 _TIFFDataSize(fip->field_type)
630 * value_count);
631 mem_alloc = 1;
632 if(TIFFGetField(tif, tag, raw_data) != 1) {
633 _TIFFfree(raw_data);
634 continue;
635 }
636 }
637 }
638
639 /*
640 * Catch the tags which needs to be specially handled
641 * and pretty print them. If tag not handled in
642 * _TIFFPrettyPrintField() fall down and print it as
643 * any other tag.
644 */
645 if (!_TIFFPrettyPrintField(tif, fip, fd, tag, value_count, raw_data))
646 _TIFFPrintField(fd, fip, value_count, raw_data);
647
648 if(mem_alloc)
649 _TIFFfree(raw_data);
650 }
651 }
652
653 if (tif->tif_tagmethods.printdir)
654 (*tif->tif_tagmethods.printdir)(tif, fd, flags);
655
656 _TIFFFillStriles( tif );
657
658 if ((flags & TIFFPRINT_STRIPS) &&
659 TIFFFieldSet(tif,FIELD_STRIPOFFSETS)) {
660 uint32 s;
661
662 fprintf(fd, " %lu %s:\n",
663 (unsigned long) td->td_nstrips,
664 isTiled(tif) ? "Tiles" : "Strips");
665 for (s = 0; s < td->td_nstrips; s++)
666 #if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
667 fprintf(fd, " %3lu: [%8I64u, %8I64u]\n",
668 (unsigned long) s,
669 td->td_stripoffset ? (unsigned __int64) td->td_stripoffset[s] : 0,
670 td->td_stripbytecount ? (unsigned __int64) td->td_stripbytecount[s] : 0);
671 #else
672 fprintf(fd, " %3lu: [%8llu, %8llu]\n",
673 (unsigned long) s,
674 td->td_stripoffset ? (unsigned long long) td->td_stripoffset[s] : 0,
675 td->td_stripbytecount ? (unsigned long long) td->td_stripbytecount[s] : 0);
676 #endif
677 }
678 }
679
680 void
681 _TIFFprintAscii(FILE* fd, const char* cp)
682 {
683 _TIFFprintAsciiBounded( fd, cp, strlen(cp));
684 }
685
686 static void
687 _TIFFprintAsciiBounded(FILE* fd, const char* cp, size_t max_chars)
688 {
689 for (; max_chars > 0 && *cp != '\0'; cp++, max_chars--) {
690 const char* tp;
691
692 if (isprint((int)*cp)) {
693 fputc(*cp, fd);
694 continue;
695 }
696 for (tp = "\tt\bb\rr\nn\vv"; *tp; tp++)
697 if (*tp++ == *cp)
698 break;
699 if (*tp)
700 fprintf(fd, "\\%c", *tp);
701 else
702 fprintf(fd, "\\%03o", *cp & 0xff);
703 }
704 }
705
706 void
707 _TIFFprintAsciiTag(FILE* fd, const char* name, const char* value)
708 {
709 fprintf(fd, " %s: \"", name);
710 _TIFFprintAscii(fd, value);
711 fprintf(fd, "\"\n");
712 }
713
714 /* vim: set ts=8 sts=8 sw=8 noet: */
715 /*
716 * Local Variables:
717 * mode: c
718 * c-basic-offset: 8
719 * fill-column: 78
720 * End:
721 */