]>
git.saurik.com Git - wxWidgets.git/blob - src/tiff/tif_print.c
4 * Copyright (c) 1988-1997 Sam Leffler
5 * Copyright (c) 1991-1997 Silicon Graphics, Inc.
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.
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.
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
30 * Directory Printing Support
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 */
46 "CIE L*a*b*", /* PHOTOMETRIC_CIELAB */
48 #define NPHOTONAMES (sizeof (photoNames) / sizeof (photoNames[0]))
50 static const char *orientNames
[] = {
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 */
61 #define NORIENTNAMES (sizeof (orientNames) / sizeof (orientNames[0]))
64 * Print the contents of the current directory
65 * to the specified stdio file stream.
68 TIFFPrintDirectory(TIFF
* tif
, FILE* fd
, long flags
)
70 register TIFFDirectory
*td
;
75 fprintf(fd
, "TIFF Directory at offset 0x%lx\n", (long) tif
->tif_diroff
);
77 if (TIFFFieldSet(tif
,FIELD_SUBFILETYPE
)) {
78 fprintf(fd
, " Subfile Type:");
80 if (td
->td_subfiletype
& FILETYPE_REDUCEDIMAGE
) {
81 fprintf(fd
, "%sreduced-resolution image", sep
);
84 if (td
->td_subfiletype
& FILETYPE_PAGE
) {
85 fprintf(fd
, "%smulti-page document", sep
);
88 if (td
->td_subfiletype
& FILETYPE_MASK
)
89 fprintf(fd
, "%stransparency mask", sep
);
90 fprintf(fd
, " (%lu = 0x%lx)\n",
91 (long) td
->td_subfiletype
, (long) td
->td_subfiletype
);
93 if (TIFFFieldSet(tif
,FIELD_IMAGEDIMENSIONS
)) {
94 fprintf(fd
, " Image Width: %lu Image Length: %lu",
95 (u_long
) td
->td_imagewidth
, (u_long
) td
->td_imagelength
);
96 if (TIFFFieldSet(tif
,FIELD_IMAGEDEPTH
))
97 fprintf(fd
, " Image Depth: %lu",
98 (u_long
) td
->td_imagedepth
);
101 if (TIFFFieldSet(tif
,FIELD_TILEDIMENSIONS
)) {
102 fprintf(fd
, " Tile Width: %lu Tile Length: %lu",
103 (u_long
) td
->td_tilewidth
, (u_long
) td
->td_tilelength
);
104 if (TIFFFieldSet(tif
,FIELD_TILEDEPTH
))
105 fprintf(fd
, " Tile Depth: %lu",
106 (u_long
) td
->td_tiledepth
);
109 if (TIFFFieldSet(tif
,FIELD_RESOLUTION
)) {
110 fprintf(fd
, " Resolution: %g, %g",
111 td
->td_xresolution
, td
->td_yresolution
);
112 if (TIFFFieldSet(tif
,FIELD_RESOLUTIONUNIT
)) {
113 switch (td
->td_resolutionunit
) {
115 fprintf(fd
, " (unitless)");
118 fprintf(fd
, " pixels/inch");
120 case RESUNIT_CENTIMETER
:
121 fprintf(fd
, " pixels/cm");
124 fprintf(fd
, " (unit %u = 0x%x)",
125 td
->td_resolutionunit
,
126 td
->td_resolutionunit
);
132 if (TIFFFieldSet(tif
,FIELD_POSITION
))
133 fprintf(fd
, " Position: %g, %g\n",
134 td
->td_xposition
, td
->td_yposition
);
135 if (TIFFFieldSet(tif
,FIELD_BITSPERSAMPLE
))
136 fprintf(fd
, " Bits/Sample: %u\n", td
->td_bitspersample
);
137 if (TIFFFieldSet(tif
,FIELD_SAMPLEFORMAT
)) {
138 fprintf(fd
, " Sample Format: ");
139 switch (td
->td_sampleformat
) {
140 case SAMPLEFORMAT_VOID
:
141 fprintf(fd
, "void\n");
143 case SAMPLEFORMAT_INT
:
144 fprintf(fd
, "signed integer\n");
146 case SAMPLEFORMAT_UINT
:
147 fprintf(fd
, "unsigned integer\n");
149 case SAMPLEFORMAT_IEEEFP
:
150 fprintf(fd
, "IEEE floating point\n");
153 fprintf(fd
, "%u (0x%x)\n",
154 td
->td_sampleformat
, td
->td_sampleformat
);
158 if (TIFFFieldSet(tif
,FIELD_COMPRESSION
)) {
159 const TIFFCodec
* c
= TIFFFindCODEC(td
->td_compression
);
160 fprintf(fd
, " Compression Scheme: ");
162 fprintf(fd
, "%s\n", c
->name
);
164 fprintf(fd
, "%u (0x%x)\n",
165 td
->td_compression
, td
->td_compression
);
167 if (TIFFFieldSet(tif
,FIELD_PHOTOMETRIC
)) {
168 fprintf(fd
, " Photometric Interpretation: ");
169 if (td
->td_photometric
< NPHOTONAMES
)
170 fprintf(fd
, "%s\n", photoNames
[td
->td_photometric
]);
172 switch (td
->td_photometric
) {
173 case PHOTOMETRIC_LOGL
:
174 fprintf(fd
, "CIE Log2(L)\n");
176 case PHOTOMETRIC_LOGLUV
:
177 fprintf(fd
, "CIE Log2(L) (u',v')\n");
180 fprintf(fd
, "%u (0x%x)\n",
181 td
->td_photometric
, td
->td_photometric
);
186 if (TIFFFieldSet(tif
,FIELD_EXTRASAMPLES
) && td
->td_extrasamples
) {
187 fprintf(fd
, " Extra Samples: %u<", td
->td_extrasamples
);
189 for (i
= 0; i
< td
->td_extrasamples
; i
++) {
190 switch (td
->td_sampleinfo
[i
]) {
191 case EXTRASAMPLE_UNSPECIFIED
:
192 fprintf(fd
, "%sunspecified", sep
);
194 case EXTRASAMPLE_ASSOCALPHA
:
195 fprintf(fd
, "%sassoc-alpha", sep
);
197 case EXTRASAMPLE_UNASSALPHA
:
198 fprintf(fd
, "%sunassoc-alpha", sep
);
201 fprintf(fd
, "%s%u (0x%x)", sep
,
202 td
->td_sampleinfo
[i
], td
->td_sampleinfo
[i
]);
209 if (TIFFFieldSet(tif
,FIELD_STONITS
)) {
210 fprintf(fd
, " Sample to Nits conversion factor: %.4e\n",
214 if (TIFFFieldSet(tif
,FIELD_INKSET
)) {
215 fprintf(fd
, " Ink Set: ");
216 switch (td
->td_inkset
) {
218 fprintf(fd
, "CMYK\n");
221 fprintf(fd
, "%u (0x%x)\n",
222 td
->td_inkset
, td
->td_inkset
);
226 if (TIFFFieldSet(tif
,FIELD_INKNAMES
)) {
228 fprintf(fd
, " Ink Names: ");
229 i
= td
->td_samplesperpixel
;
231 for (cp
= td
->td_inknames
; i
> 0; cp
= strchr(cp
,'\0')+1, i
--) {
232 fprintf(fd
, "%s", sep
);
233 _TIFFprintAscii(fd
, cp
);
237 if (TIFFFieldSet(tif
,FIELD_NUMBEROFINKS
))
238 fprintf(fd
, " Number of Inks: %u\n", td
->td_ninks
);
239 if (TIFFFieldSet(tif
,FIELD_DOTRANGE
))
240 fprintf(fd
, " Dot Range: %u-%u\n",
241 td
->td_dotrange
[0], td
->td_dotrange
[1]);
242 if (TIFFFieldSet(tif
,FIELD_TARGETPRINTER
))
243 _TIFFprintAsciiTag(fd
, "Target Printer", td
->td_targetprinter
);
245 if (TIFFFieldSet(tif
,FIELD_THRESHHOLDING
)) {
246 fprintf(fd
, " Thresholding: ");
247 switch (td
->td_threshholding
) {
248 case THRESHHOLD_BILEVEL
:
249 fprintf(fd
, "bilevel art scan\n");
251 case THRESHHOLD_HALFTONE
:
252 fprintf(fd
, "halftone or dithered scan\n");
254 case THRESHHOLD_ERRORDIFFUSE
:
255 fprintf(fd
, "error diffused\n");
258 fprintf(fd
, "%u (0x%x)\n",
259 td
->td_threshholding
, td
->td_threshholding
);
263 if (TIFFFieldSet(tif
,FIELD_FILLORDER
)) {
264 fprintf(fd
, " FillOrder: ");
265 switch (td
->td_fillorder
) {
266 case FILLORDER_MSB2LSB
:
267 fprintf(fd
, "msb-to-lsb\n");
269 case FILLORDER_LSB2MSB
:
270 fprintf(fd
, "lsb-to-msb\n");
273 fprintf(fd
, "%u (0x%x)\n",
274 td
->td_fillorder
, td
->td_fillorder
);
279 if (TIFFFieldSet(tif
,FIELD_YCBCRSUBSAMPLING
))
280 fprintf(fd
, " YCbCr Subsampling: %u, %u\n",
281 td
->td_ycbcrsubsampling
[0], td
->td_ycbcrsubsampling
[1]);
282 if (TIFFFieldSet(tif
,FIELD_YCBCRPOSITIONING
)) {
283 fprintf(fd
, " YCbCr Positioning: ");
284 switch (td
->td_ycbcrpositioning
) {
285 case YCBCRPOSITION_CENTERED
:
286 fprintf(fd
, "centered\n");
288 case YCBCRPOSITION_COSITED
:
289 fprintf(fd
, "cosited\n");
292 fprintf(fd
, "%u (0x%x)\n",
293 td
->td_ycbcrpositioning
, td
->td_ycbcrpositioning
);
297 if (TIFFFieldSet(tif
,FIELD_YCBCRCOEFFICIENTS
))
298 fprintf(fd
, " YCbCr Coefficients: %g, %g, %g\n",
299 td
->td_ycbcrcoeffs
[0],
300 td
->td_ycbcrcoeffs
[1],
301 td
->td_ycbcrcoeffs
[2]);
303 if (TIFFFieldSet(tif
,FIELD_HALFTONEHINTS
))
304 fprintf(fd
, " Halftone Hints: light %u dark %u\n",
305 td
->td_halftonehints
[0], td
->td_halftonehints
[1]);
306 if (TIFFFieldSet(tif
,FIELD_ARTIST
))
307 _TIFFprintAsciiTag(fd
, "Artist", td
->td_artist
);
308 if (TIFFFieldSet(tif
,FIELD_DATETIME
))
309 _TIFFprintAsciiTag(fd
, "Date & Time", td
->td_datetime
);
310 if (TIFFFieldSet(tif
,FIELD_HOSTCOMPUTER
))
311 _TIFFprintAsciiTag(fd
, "Host Computer", td
->td_hostcomputer
);
312 if (TIFFFieldSet(tif
,FIELD_SOFTWARE
))
313 _TIFFprintAsciiTag(fd
, "Software", td
->td_software
);
314 if (TIFFFieldSet(tif
,FIELD_DOCUMENTNAME
))
315 _TIFFprintAsciiTag(fd
, "Document Name", td
->td_documentname
);
316 if (TIFFFieldSet(tif
,FIELD_IMAGEDESCRIPTION
))
317 _TIFFprintAsciiTag(fd
, "Image Description", td
->td_imagedescription
);
318 if (TIFFFieldSet(tif
,FIELD_MAKE
))
319 _TIFFprintAsciiTag(fd
, "Make", td
->td_make
);
320 if (TIFFFieldSet(tif
,FIELD_MODEL
))
321 _TIFFprintAsciiTag(fd
, "Model", td
->td_model
);
322 if (TIFFFieldSet(tif
,FIELD_ORIENTATION
)) {
323 fprintf(fd
, " Orientation: ");
324 if (td
->td_orientation
< NORIENTNAMES
)
325 fprintf(fd
, "%s\n", orientNames
[td
->td_orientation
]);
327 fprintf(fd
, "%u (0x%x)\n",
328 td
->td_orientation
, td
->td_orientation
);
330 if (TIFFFieldSet(tif
,FIELD_SAMPLESPERPIXEL
))
331 fprintf(fd
, " Samples/Pixel: %u\n", td
->td_samplesperpixel
);
332 if (TIFFFieldSet(tif
,FIELD_ROWSPERSTRIP
)) {
333 fprintf(fd
, " Rows/Strip: ");
334 if (td
->td_rowsperstrip
== (uint32
) -1)
335 fprintf(fd
, "(infinite)\n");
337 fprintf(fd
, "%lu\n", (u_long
) td
->td_rowsperstrip
);
339 if (TIFFFieldSet(tif
,FIELD_MINSAMPLEVALUE
))
340 fprintf(fd
, " Min Sample Value: %u\n", td
->td_minsamplevalue
);
341 if (TIFFFieldSet(tif
,FIELD_MAXSAMPLEVALUE
))
342 fprintf(fd
, " Max Sample Value: %u\n", td
->td_maxsamplevalue
);
343 if (TIFFFieldSet(tif
,FIELD_SMINSAMPLEVALUE
))
344 fprintf(fd
, " SMin Sample Value: %g\n",
345 td
->td_sminsamplevalue
);
346 if (TIFFFieldSet(tif
,FIELD_SMAXSAMPLEVALUE
))
347 fprintf(fd
, " SMax Sample Value: %g\n",
348 td
->td_smaxsamplevalue
);
349 if (TIFFFieldSet(tif
,FIELD_PLANARCONFIG
)) {
350 fprintf(fd
, " Planar Configuration: ");
351 switch (td
->td_planarconfig
) {
352 case PLANARCONFIG_CONTIG
:
353 fprintf(fd
, "single image plane\n");
355 case PLANARCONFIG_SEPARATE
:
356 fprintf(fd
, "separate image planes\n");
359 fprintf(fd
, "%u (0x%x)\n",
360 td
->td_planarconfig
, td
->td_planarconfig
);
364 if (TIFFFieldSet(tif
,FIELD_PAGENAME
))
365 _TIFFprintAsciiTag(fd
, "Page Name", td
->td_pagename
);
366 if (TIFFFieldSet(tif
,FIELD_PAGENUMBER
))
367 fprintf(fd
, " Page Number: %u-%u\n",
368 td
->td_pagenumber
[0], td
->td_pagenumber
[1]);
369 if (TIFFFieldSet(tif
,FIELD_COLORMAP
)) {
370 fprintf(fd
, " Color Map: ");
371 if (flags
& TIFFPRINT_COLORMAP
) {
373 n
= 1L<<td
->td_bitspersample
;
374 for (l
= 0; l
< n
; l
++)
375 fprintf(fd
, " %5lu: %5u %5u %5u\n",
377 td
->td_colormap
[0][l
],
378 td
->td_colormap
[1][l
],
379 td
->td_colormap
[2][l
]);
381 fprintf(fd
, "(present)\n");
383 #ifdef COLORIMETRY_SUPPORT
384 if (TIFFFieldSet(tif
,FIELD_WHITEPOINT
))
385 fprintf(fd
, " White Point: %g-%g\n",
386 td
->td_whitepoint
[0], td
->td_whitepoint
[1]);
387 if (TIFFFieldSet(tif
,FIELD_PRIMARYCHROMAS
))
388 fprintf(fd
, " Primary Chromaticities: %g,%g %g,%g %g,%g\n",
389 td
->td_primarychromas
[0], td
->td_primarychromas
[1],
390 td
->td_primarychromas
[2], td
->td_primarychromas
[3],
391 td
->td_primarychromas
[4], td
->td_primarychromas
[5]);
392 if (TIFFFieldSet(tif
,FIELD_REFBLACKWHITE
)) {
393 fprintf(fd
, " Reference Black/White:\n");
394 for (i
= 0; i
< td
->td_samplesperpixel
; i
++)
395 fprintf(fd
, " %2d: %5g %5g\n",
397 td
->td_refblackwhite
[2*i
+0],
398 td
->td_refblackwhite
[2*i
+1]);
400 if (TIFFFieldSet(tif
,FIELD_TRANSFERFUNCTION
)) {
401 fprintf(fd
, " Transfer Function: ");
402 if (flags
& TIFFPRINT_CURVES
) {
404 n
= 1L<<td
->td_bitspersample
;
405 for (l
= 0; l
< n
; l
++) {
406 fprintf(fd
, " %2lu: %5u",
407 l
, td
->td_transferfunction
[0][l
]);
408 for (i
= 1; i
< td
->td_samplesperpixel
; i
++)
410 td
->td_transferfunction
[i
][l
]);
414 fprintf(fd
, "(present)\n");
418 if (TIFFFieldSet(tif
,FIELD_ICCPROFILE
))
419 fprintf(fd
, " ICC Profile: <present>, %lu bytes\n",
420 (u_long
) td
->td_profileLength
);
422 #ifdef PHOTOSHOP_SUPPORT
423 if (TIFFFieldSet(tif
,FIELD_PHOTOSHOP
))
424 fprintf(fd
, " Photoshop Data: <present>, %lu bytes\n",
425 (u_long
) td
->td_photoshopLength
);
428 if (TIFFFieldSet(tif
,FIELD_RICHTIFFIPTC
))
429 fprintf(fd
, " RichTIFFIPTC Data: <present>, %lu bytes\n",
430 (u_long
) td
->td_richtiffiptcLength
);
433 if (TIFFFieldSet(tif
, FIELD_SUBIFD
)) {
434 fprintf(fd
, " SubIFD Offsets:");
435 for (i
= 0; i
< td
->td_nsubifd
; i
++)
436 fprintf(fd
, " %5lu", (long) td
->td_subifd
[i
]);
440 if (tif
->tif_printdir
)
441 (*tif
->tif_printdir
)(tif
, fd
, flags
);
442 if ((flags
& TIFFPRINT_STRIPS
) &&
443 TIFFFieldSet(tif
,FIELD_STRIPOFFSETS
)) {
446 fprintf(fd
, " %lu %s:\n",
447 (long) td
->td_nstrips
,
448 isTiled(tif
) ? "Tiles" : "Strips");
449 for (s
= 0; s
< td
->td_nstrips
; s
++)
450 fprintf(fd
, " %3lu: [%8lu, %8lu]\n",
452 (u_long
) td
->td_stripoffset
[s
],
453 (u_long
) td
->td_stripbytecount
[s
]);
458 _TIFFprintAscii(FILE* fd
, const char* cp
)
460 for (; *cp
!= '\0'; cp
++) {
467 for (tp
= "\tt\bb\rr\nn\vv"; *tp
; tp
++)
471 fprintf(fd
, "\\%c", *tp
);
473 fprintf(fd
, "\\%03o", *cp
& 0xff);
478 _TIFFprintAsciiTag(FILE* fd
, const char* name
, const char* value
)
480 fprintf(fd
, " %s: \"", name
);
481 _TIFFprintAscii(fd
, value
);