~ubuntu-branches/ubuntu/trusty/freeimage/trusty

« back to all changes in this revision

Viewing changes to Source/LibTIFF/tif_print.c

  • Committer: Package Import Robot
  • Author(s): Evan Broder, Evan Broder, Stefano Rivera
  • Date: 2011-12-06 14:31:21 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20111206143121-1d1honlf3ixuk6lw
Tags: 3.15.1-1
[ Evan Broder ]
* QA upload.
* New upstream release (closes: 649541, LP: #898825, #898845)
  - Refreshed patches.
    + Abuse dh-autoreconf to generate Makefile.srcs and fipMakefile.srcs
      patches at build time
  - Update debian/freeimage-get-orig-source for the new version.
  - Add new build-dep libraw-dev.
  - Update patch to disable embedded libraries to deal with API changes
    in libpng, libmng, and libraw.
  - Make sure we install symlinks for libfreeimageplus.
  - Use (upstream-supported) CFLAGS instead of COMPILERFLAGS.
* Switch to source format 3.0 (quilt)
* Switch to dh(1) and debhelper compat 8
* Add missing misc:Depends.
* Include the upstream changelog.
* Update Debian standards version (no other changes needed).

[ Stefano Rivera ]
* Dropped README.source.
* Updated freeimage (3.9.5) fixes CVE-2011-1167, CVE-2011-0192,
  CVE-2010-2595
* Override lintian's embedded-library error for libtiff. It wasn't
  extricable.

Show diffs side-by-side

added added

removed removed

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