]> git.saurik.com Git - wxWidgets.git/blame - src/tiff/tif_print.c
unnecessary ClipRects
[wxWidgets.git] / src / tiff / tif_print.c
CommitLineData
b47c832e
RR
1/* $Header$ */
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
37static 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
50static 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/*
64 * Print the contents of the current directory
65 * to the specified stdio file stream.
66 */
67void
68TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags)
69{
70 register TIFFDirectory *td;
71 char *sep;
72 uint16 i;
73 long l, n;
74
75 fprintf(fd, "TIFF Directory at offset 0x%lx\n", (long) tif->tif_diroff);
76 td = &tif->tif_dir;
77 if (TIFFFieldSet(tif,FIELD_SUBFILETYPE)) {
78 fprintf(fd, " Subfile Type:");
79 sep = " ";
80 if (td->td_subfiletype & FILETYPE_REDUCEDIMAGE) {
81 fprintf(fd, "%sreduced-resolution image", sep);
82 sep = "/";
83 }
84 if (td->td_subfiletype & FILETYPE_PAGE) {
85 fprintf(fd, "%smulti-page document", sep);
86 sep = "/";
87 }
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);
92 }
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);
99 fprintf(fd, "\n");
100 }
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);
107 fprintf(fd, "\n");
108 }
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) {
114 case RESUNIT_NONE:
115 fprintf(fd, " (unitless)");
116 break;
117 case RESUNIT_INCH:
118 fprintf(fd, " pixels/inch");
119 break;
120 case RESUNIT_CENTIMETER:
121 fprintf(fd, " pixels/cm");
122 break;
123 default:
124 fprintf(fd, " (unit %u = 0x%x)",
125 td->td_resolutionunit,
126 td->td_resolutionunit);
127 break;
128 }
129 }
130 fprintf(fd, "\n");
131 }
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");
142 break;
143 case SAMPLEFORMAT_INT:
144 fprintf(fd, "signed integer\n");
145 break;
146 case SAMPLEFORMAT_UINT:
147 fprintf(fd, "unsigned integer\n");
148 break;
149 case SAMPLEFORMAT_IEEEFP:
150 fprintf(fd, "IEEE floating point\n");
151 break;
152 default:
153 fprintf(fd, "%u (0x%x)\n",
154 td->td_sampleformat, td->td_sampleformat);
155 break;
156 }
157 }
158 if (TIFFFieldSet(tif,FIELD_COMPRESSION)) {
159 const TIFFCodec* c = TIFFFindCODEC(td->td_compression);
160 fprintf(fd, " Compression Scheme: ");
161 if (c)
162 fprintf(fd, "%s\n", c->name);
163 else
164 fprintf(fd, "%u (0x%x)\n",
165 td->td_compression, td->td_compression);
166 }
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]);
171 else {
172 switch (td->td_photometric) {
173 case PHOTOMETRIC_LOGL:
174 fprintf(fd, "CIE Log2(L)\n");
175 break;
176 case PHOTOMETRIC_LOGLUV:
177 fprintf(fd, "CIE Log2(L) (u',v')\n");
178 break;
179 default:
180 fprintf(fd, "%u (0x%x)\n",
181 td->td_photometric, td->td_photometric);
182 break;
183 }
184 }
185 }
186 if (TIFFFieldSet(tif,FIELD_EXTRASAMPLES) && td->td_extrasamples) {
187 fprintf(fd, " Extra Samples: %u<", td->td_extrasamples);
188 sep = "";
189 for (i = 0; i < td->td_extrasamples; i++) {
190 switch (td->td_sampleinfo[i]) {
191 case EXTRASAMPLE_UNSPECIFIED:
192 fprintf(fd, "%sunspecified", sep);
193 break;
194 case EXTRASAMPLE_ASSOCALPHA:
195 fprintf(fd, "%sassoc-alpha", sep);
196 break;
197 case EXTRASAMPLE_UNASSALPHA:
198 fprintf(fd, "%sunassoc-alpha", sep);
199 break;
200 default:
201 fprintf(fd, "%s%u (0x%x)", sep,
202 td->td_sampleinfo[i], td->td_sampleinfo[i]);
203 break;
204 }
205 sep = ", ";
206 }
207 fprintf(fd, ">\n");
208 }
209 if (TIFFFieldSet(tif,FIELD_STONITS)) {
210 fprintf(fd, " Sample to Nits conversion factor: %.4e\n",
211 td->td_stonits);
212 }
213#ifdef CMYK_SUPPORT
214 if (TIFFFieldSet(tif,FIELD_INKSET)) {
215 fprintf(fd, " Ink Set: ");
216 switch (td->td_inkset) {
217 case INKSET_CMYK:
218 fprintf(fd, "CMYK\n");
219 break;
220 default:
221 fprintf(fd, "%u (0x%x)\n",
222 td->td_inkset, td->td_inkset);
223 break;
224 }
225 }
226 if (TIFFFieldSet(tif,FIELD_INKNAMES)) {
227 char* cp;
228 fprintf(fd, " Ink Names: ");
229 i = td->td_samplesperpixel;
230 sep = "";
231 for (cp = td->td_inknames; i > 0; cp = strchr(cp,'\0')+1, i--) {
232 fprintf(fd, "%s", sep);
233 _TIFFprintAscii(fd, cp);
234 sep = ", ";
235 }
236 }
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);
244#endif
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");
250 break;
251 case THRESHHOLD_HALFTONE:
252 fprintf(fd, "halftone or dithered scan\n");
253 break;
254 case THRESHHOLD_ERRORDIFFUSE:
255 fprintf(fd, "error diffused\n");
256 break;
257 default:
258 fprintf(fd, "%u (0x%x)\n",
259 td->td_threshholding, td->td_threshholding);
260 break;
261 }
262 }
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");
268 break;
269 case FILLORDER_LSB2MSB:
270 fprintf(fd, "lsb-to-msb\n");
271 break;
272 default:
273 fprintf(fd, "%u (0x%x)\n",
274 td->td_fillorder, td->td_fillorder);
275 break;
276 }
277 }
278#ifdef YCBCR_SUPPORT
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");
287 break;
288 case YCBCRPOSITION_COSITED:
289 fprintf(fd, "cosited\n");
290 break;
291 default:
292 fprintf(fd, "%u (0x%x)\n",
293 td->td_ycbcrpositioning, td->td_ycbcrpositioning);
294 break;
295 }
296 }
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]);
302#endif
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]);
326 else
327 fprintf(fd, "%u (0x%x)\n",
328 td->td_orientation, td->td_orientation);
329 }
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");
336 else
337 fprintf(fd, "%lu\n", (u_long) td->td_rowsperstrip);
338 }
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");
354 break;
355 case PLANARCONFIG_SEPARATE:
356 fprintf(fd, "separate image planes\n");
357 break;
358 default:
359 fprintf(fd, "%u (0x%x)\n",
360 td->td_planarconfig, td->td_planarconfig);
361 break;
362 }
363 }
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) {
372 fprintf(fd, "\n");
373 n = 1L<<td->td_bitspersample;
374 for (l = 0; l < n; l++)
375 fprintf(fd, " %5lu: %5u %5u %5u\n",
376 l,
377 td->td_colormap[0][l],
378 td->td_colormap[1][l],
379 td->td_colormap[2][l]);
380 } else
381 fprintf(fd, "(present)\n");
382 }
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",
396 i,
397 td->td_refblackwhite[2*i+0],
398 td->td_refblackwhite[2*i+1]);
399 }
400 if (TIFFFieldSet(tif,FIELD_TRANSFERFUNCTION)) {
401 fprintf(fd, " Transfer Function: ");
402 if (flags & TIFFPRINT_CURVES) {
403 fprintf(fd, "\n");
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++)
409 fprintf(fd, " %5u",
410 td->td_transferfunction[i][l]);
411 fputc('\n', fd);
412 }
413 } else
414 fprintf(fd, "(present)\n");
415 }
416#endif
417#ifdef ICC_SUPPORT
418 if (TIFFFieldSet(tif,FIELD_ICCPROFILE))
419 fprintf(fd, " ICC Profile: <present>, %lu bytes\n",
420 (u_long) td->td_profileLength);
421#endif
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);
426#endif
427#ifdef IPTC_SUPPORT
428 if (TIFFFieldSet(tif,FIELD_RICHTIFFIPTC))
429 fprintf(fd, " RichTIFFIPTC Data: <present>, %lu bytes\n",
430 (u_long) td->td_richtiffiptcLength);
431#endif
432#if SUBIFD_SUPPORT
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]);
437 fputc('\n', fd);
438 }
439#endif
440 if (tif->tif_printdir)
441 (*tif->tif_printdir)(tif, fd, flags);
442 if ((flags & TIFFPRINT_STRIPS) &&
443 TIFFFieldSet(tif,FIELD_STRIPOFFSETS)) {
444 tstrip_t s;
445
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",
451 (u_long) s,
452 (u_long) td->td_stripoffset[s],
453 (u_long) td->td_stripbytecount[s]);
454 }
455}
456
457void
458_TIFFprintAscii(FILE* fd, const char* cp)
459{
460 for (; *cp != '\0'; cp++) {
461 const char* tp;
462
463 if (isprint(*cp)) {
464 fputc(*cp, fd);
465 continue;
466 }
467 for (tp = "\tt\bb\rr\nn\vv"; *tp; tp++)
468 if (*tp++ == *cp)
469 break;
470 if (*tp)
471 fprintf(fd, "\\%c", *tp);
472 else
473 fprintf(fd, "\\%03o", *cp & 0xff);
474 }
475}
476
477void
478_TIFFprintAsciiTag(FILE* fd, const char* name, const char* value)
479{
480 fprintf(fd, " %s: \"", name);
481 _TIFFprintAscii(fd, value);
482 fprintf(fd, "\"\n");
483}