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