1 /* PDFlib GmbH cvsid:
2  * $Id: tif_print.c,v 1.12 2005/12/21 14:12:52 rjs Exp $ */
3 
4 /*
5  * Copyright (c) 1988-1997 Sam Leffler
6  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
7  *
8  * Permission to use, copy, modify, distribute, and sell this software and
9  * its documentation for any purpose is hereby granted without fee, provided
10  * that (i) the above copyright notices and this permission notice appear in
11  * all copies of the software and related documentation, and (ii) the names of
12  * Sam Leffler and Silicon Graphics may not be used in any advertising or
13  * publicity relating to the software without the specific, prior written
14  * permission of Sam Leffler and Silicon Graphics.
15  *
16  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
18  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
19  *
20  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
21  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
22  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
23  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
24  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
25  * OF THIS SOFTWARE.
26  */
27 
28 /*
29  * TIFF Library.
30  *
31  * Directory Printing Support
32  */
33 #include "tiffiop.h"
34 #include <stdio.h>
35 
36 #include <ctype.h>
37 
38 #ifdef PDFLIB_TIFFWRITE_SUPPORT
39 static const char *photoNames[] = {
40     "min-is-white",				/* PHOTOMETRIC_MINISWHITE */
41     "min-is-black",				/* PHOTOMETRIC_MINISBLACK */
42     "RGB color",				/* PHOTOMETRIC_RGB */
43     "palette color (RGB from colormap)",	/* PHOTOMETRIC_PALETTE */
44     "transparency mask",			/* PHOTOMETRIC_MASK */
45     "separated",				/* PHOTOMETRIC_SEPARATED */
46     "YCbCr",					/* PHOTOMETRIC_YCBCR */
47     "7 (0x7)",
48     "CIE L*a*b*",				/* PHOTOMETRIC_CIELAB */
49 };
50 #define	NPHOTONAMES	(sizeof (photoNames) / sizeof (photoNames[0]))
51 
52 static const char *orientNames[] = {
53     "0 (0x0)",
54     "row 0 top, col 0 lhs",			/* ORIENTATION_TOPLEFT */
55     "row 0 top, col 0 rhs",			/* ORIENTATION_TOPRIGHT */
56     "row 0 bottom, col 0 rhs",			/* ORIENTATION_BOTRIGHT */
57     "row 0 bottom, col 0 lhs",			/* ORIENTATION_BOTLEFT */
58     "row 0 lhs, col 0 top",			/* ORIENTATION_LEFTTOP */
59     "row 0 rhs, col 0 top",			/* ORIENTATION_RIGHTTOP */
60     "row 0 rhs, col 0 bottom",			/* ORIENTATION_RIGHTBOT */
61     "row 0 lhs, col 0 bottom",			/* ORIENTATION_LEFTBOT */
62 };
63 #define	NORIENTNAMES	(sizeof (orientNames) / sizeof (orientNames[0]))
64 
65 /*
66  * Print the contents of the current directory
67  * to the specified stdio file stream.
68  */
69 void
TIFFPrintDirectory(TIFF * tif,FILE * fd,long flags)70 TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags)
71 {
72 	register TIFFDirectory *td;
73 	char *sep;
74 	uint16 i;
75 	long l, n;
76 
77 	fprintf(fd, "TIFF Directory at offset 0x%lx\n",
78 		(unsigned long)tif->tif_diroff);
79 	td = &tif->tif_dir;
80 	if (TIFFFieldSet(tif,FIELD_SUBFILETYPE)) {
81 		fprintf(fd, "  Subfile Type:");
82 		sep = " ";
83 		if (td->td_subfiletype & FILETYPE_REDUCEDIMAGE) {
84 			fprintf(fd, "%sreduced-resolution image", sep);
85 			sep = "/";
86 		}
87 		if (td->td_subfiletype & FILETYPE_PAGE) {
88 			fprintf(fd, "%smulti-page document", sep);
89 			sep = "/";
90 		}
91 		if (td->td_subfiletype & FILETYPE_MASK)
92 			fprintf(fd, "%stransparency mask", sep);
93 		fprintf(fd, " (%lu = 0x%lx)\n",
94 		    (long) td->td_subfiletype, (long) td->td_subfiletype);
95 	}
96 	if (TIFFFieldSet(tif,FIELD_IMAGEDIMENSIONS)) {
97 		fprintf(fd, "  Image Width: %lu Image Length: %lu",
98 		    (unsigned long) td->td_imagewidth,
99 		    (unsigned long) td->td_imagelength);
100 		if (TIFFFieldSet(tif,FIELD_IMAGEDEPTH))
101 			fprintf(fd, " Image Depth: %lu",
102 			    (unsigned long) td->td_imagedepth);
103 		fprintf(fd, "\n");
104 	}
105 	if (TIFFFieldSet(tif,FIELD_TILEDIMENSIONS)) {
106 		fprintf(fd, "  Tile Width: %lu Tile Length: %lu",
107 		    (unsigned long) td->td_tilewidth,
108 		    (unsigned long) td->td_tilelength);
109 		if (TIFFFieldSet(tif,FIELD_TILEDEPTH))
110 			fprintf(fd, " Tile Depth: %lu",
111 			    (unsigned long) td->td_tiledepth);
112 		fprintf(fd, "\n");
113 	}
114 	if (TIFFFieldSet(tif,FIELD_RESOLUTION)) {
115 		fprintf(fd, "  Resolution: %g, %g",
116 		    td->td_xresolution, td->td_yresolution);
117 		if (TIFFFieldSet(tif,FIELD_RESOLUTIONUNIT)) {
118 			switch (td->td_resolutionunit) {
119 			case RESUNIT_NONE:
120 				fprintf(fd, " (unitless)");
121 				break;
122 			case RESUNIT_INCH:
123 				fprintf(fd, " pixels/inch");
124 				break;
125 			case RESUNIT_CENTIMETER:
126 				fprintf(fd, " pixels/cm");
127 				break;
128 			default:
129 				fprintf(fd, " (unit %u = 0x%x)",
130 				    td->td_resolutionunit,
131 				    td->td_resolutionunit);
132 				break;
133 			}
134 		}
135 		fprintf(fd, "\n");
136 	}
137 	if (TIFFFieldSet(tif,FIELD_POSITION))
138 		fprintf(fd, "  Position: %g, %g\n",
139 		    td->td_xposition, td->td_yposition);
140 	if (TIFFFieldSet(tif,FIELD_BITSPERSAMPLE))
141 		fprintf(fd, "  Bits/Sample: %u\n", td->td_bitspersample);
142 	if (TIFFFieldSet(tif,FIELD_SAMPLEFORMAT)) {
143 		fprintf(fd, "  Sample Format: ");
144 		switch (td->td_sampleformat) {
145 		case SAMPLEFORMAT_VOID:
146 			fprintf(fd, "void\n");
147 			break;
148 		case SAMPLEFORMAT_INT:
149 			fprintf(fd, "signed integer\n");
150 			break;
151 		case SAMPLEFORMAT_UINT:
152 			fprintf(fd, "unsigned integer\n");
153 			break;
154 		case SAMPLEFORMAT_IEEEFP:
155 			fprintf(fd, "IEEE floating point\n");
156 			break;
157 		case SAMPLEFORMAT_COMPLEXINT:
158 			fprintf(fd, "complex signed integer\n");
159 			break;
160 		case SAMPLEFORMAT_COMPLEXIEEEFP:
161 			fprintf(fd, "complex IEEE floating point\n");
162 			break;
163 		default:
164 			fprintf(fd, "%u (0x%x)\n",
165 			    td->td_sampleformat, td->td_sampleformat);
166 			break;
167 		}
168 	}
169 	if (TIFFFieldSet(tif,FIELD_COMPRESSION)) {
170 		const TIFFCodec* c = TIFFFindCODEC(td->td_compression);
171 		fprintf(fd, "  Compression Scheme: ");
172 		if (c)
173 			fprintf(fd, "%s\n", c->name);
174 		else
175 			fprintf(fd, "%u (0x%x)\n",
176 			    td->td_compression, td->td_compression);
177 	}
178 	if (TIFFFieldSet(tif,FIELD_PHOTOMETRIC)) {
179 		fprintf(fd, "  Photometric Interpretation: ");
180 		if (td->td_photometric < NPHOTONAMES)
181 			fprintf(fd, "%s\n", photoNames[td->td_photometric]);
182 		else {
183 			switch (td->td_photometric) {
184 			case PHOTOMETRIC_LOGL:
185 				fprintf(fd, "CIE Log2(L)\n");
186 				break;
187 			case PHOTOMETRIC_LOGLUV:
188 				fprintf(fd, "CIE Log2(L) (u',v')\n");
189 				break;
190 			default:
191 				fprintf(fd, "%u (0x%x)\n",
192 				    td->td_photometric, td->td_photometric);
193 				break;
194 			}
195 		}
196 	}
197 	if (TIFFFieldSet(tif,FIELD_EXTRASAMPLES) && td->td_extrasamples) {
198 		fprintf(fd, "  Extra Samples: %u<", td->td_extrasamples);
199 		sep = "";
200 		for (i = 0; i < td->td_extrasamples; i++) {
201 			switch (td->td_sampleinfo[i]) {
202 			case EXTRASAMPLE_UNSPECIFIED:
203 				fprintf(fd, "%sunspecified", sep);
204 				break;
205 			case EXTRASAMPLE_ASSOCALPHA:
206 				fprintf(fd, "%sassoc-alpha", sep);
207 				break;
208 			case EXTRASAMPLE_UNASSALPHA:
209 				fprintf(fd, "%sunassoc-alpha", sep);
210 				break;
211 			default:
212 				fprintf(fd, "%s%u (0x%x)", sep,
213 				    td->td_sampleinfo[i], td->td_sampleinfo[i]);
214 				break;
215 			}
216 			sep = ", ";
217 		}
218 		fprintf(fd, ">\n");
219 	}
220 	if (TIFFFieldSet(tif,FIELD_STONITS)) {
221 		fprintf(fd, "  Sample to Nits conversion factor: %.4e\n",
222 				td->td_stonits);
223 	}
224 	if (TIFFFieldSet(tif,FIELD_INKSET)) {
225 		fprintf(fd, "  Ink Set: ");
226 		switch (td->td_inkset) {
227 		case INKSET_CMYK:
228 			fprintf(fd, "CMYK\n");
229 			break;
230 		default:
231 			fprintf(fd, "%u (0x%x)\n",
232 			    td->td_inkset, td->td_inkset);
233 			break;
234 		}
235 	}
236 	if (TIFFFieldSet(tif,FIELD_INKNAMES)) {
237 		char* cp;
238 		fprintf(fd, "  Ink Names: ");
239 		i = td->td_samplesperpixel;
240 		sep = "";
241 		for (cp = td->td_inknames; i > 0; cp = strchr(cp,'\0')+1, i--) {
242 			fputs(sep, fd);
243 			_TIFFprintAscii(fd, cp);
244 			sep = ", ";
245 		}
246                 fputs("\n", fd);
247 	}
248 	if (TIFFFieldSet(tif,FIELD_NUMBEROFINKS))
249 		fprintf(fd, "  Number of Inks: %u\n", td->td_ninks);
250 	if (TIFFFieldSet(tif,FIELD_DOTRANGE))
251 		fprintf(fd, "  Dot Range: %u-%u\n",
252 		    td->td_dotrange[0], td->td_dotrange[1]);
253 	if (TIFFFieldSet(tif,FIELD_THRESHHOLDING)) {
254 		fprintf(fd, "  Thresholding: ");
255 		switch (td->td_threshholding) {
256 		case THRESHHOLD_BILEVEL:
257 			fprintf(fd, "bilevel art scan\n");
258 			break;
259 		case THRESHHOLD_HALFTONE:
260 			fprintf(fd, "halftone or dithered scan\n");
261 			break;
262 		case THRESHHOLD_ERRORDIFFUSE:
263 			fprintf(fd, "error diffused\n");
264 			break;
265 		default:
266 			fprintf(fd, "%u (0x%x)\n",
267 			    td->td_threshholding, td->td_threshholding);
268 			break;
269 		}
270 	}
271 	if (TIFFFieldSet(tif,FIELD_FILLORDER)) {
272 		fprintf(fd, "  FillOrder: ");
273 		switch (td->td_fillorder) {
274 		case FILLORDER_MSB2LSB:
275 			fprintf(fd, "msb-to-lsb\n");
276 			break;
277 		case FILLORDER_LSB2MSB:
278 			fprintf(fd, "lsb-to-msb\n");
279 			break;
280 		default:
281 			fprintf(fd, "%u (0x%x)\n",
282 			    td->td_fillorder, td->td_fillorder);
283 			break;
284 		}
285 	}
286 	if (TIFFFieldSet(tif,FIELD_YCBCRSUBSAMPLING))
287         {
288             /*
289              * For hacky reasons (see tif_jpeg.c - JPEGFixupTestSubsampling),
290              * we need to fetch this rather than trust what is in our
291              * structures.
292              */
293             uint16 subsampling[2];
294 
295             TIFFGetField( tif, TIFFTAG_YCBCRSUBSAMPLING,
296                           subsampling + 0, subsampling + 1 );
297 		fprintf(fd, "  YCbCr Subsampling: %u, %u\n",
298                         subsampling[0], subsampling[1] );
299         }
300 	if (TIFFFieldSet(tif,FIELD_YCBCRPOSITIONING)) {
301 		fprintf(fd, "  YCbCr Positioning: ");
302 		switch (td->td_ycbcrpositioning) {
303 		case YCBCRPOSITION_CENTERED:
304 			fprintf(fd, "centered\n");
305 			break;
306 		case YCBCRPOSITION_COSITED:
307 			fprintf(fd, "cosited\n");
308 			break;
309 		default:
310 			fprintf(fd, "%u (0x%x)\n",
311 			    td->td_ycbcrpositioning, td->td_ycbcrpositioning);
312 			break;
313 		}
314 	}
315 	if (TIFFFieldSet(tif,FIELD_YCBCRCOEFFICIENTS))
316 		fprintf(fd, "  YCbCr Coefficients: %g, %g, %g\n",
317 		    td->td_ycbcrcoeffs[0],
318 		    td->td_ycbcrcoeffs[1],
319 		    td->td_ycbcrcoeffs[2]);
320 	if (TIFFFieldSet(tif,FIELD_HALFTONEHINTS))
321 		fprintf(fd, "  Halftone Hints: light %u dark %u\n",
322 		    td->td_halftonehints[0], td->td_halftonehints[1]);
323 	if (TIFFFieldSet(tif,FIELD_ORIENTATION)) {
324 		fprintf(fd, "  Orientation: ");
325 		if (td->td_orientation < NORIENTNAMES)
326 			fprintf(fd, "%s\n", orientNames[td->td_orientation]);
327 		else
328 			fprintf(fd, "%u (0x%x)\n",
329 			    td->td_orientation, td->td_orientation);
330 	}
331 	if (TIFFFieldSet(tif,FIELD_SAMPLESPERPIXEL))
332 		fprintf(fd, "  Samples/Pixel: %u\n", td->td_samplesperpixel);
333 	if (TIFFFieldSet(tif,FIELD_ROWSPERSTRIP)) {
334 		fprintf(fd, "  Rows/Strip: ");
335 		if (td->td_rowsperstrip == (uint32) -1)
336 			fprintf(fd, "(infinite)\n");
337 		else
338 			fprintf(fd,"%lu\n",(unsigned long)td->td_rowsperstrip);
339 	}
340 	if (TIFFFieldSet(tif,FIELD_MINSAMPLEVALUE))
341 		fprintf(fd, "  Min Sample Value: %u\n", td->td_minsamplevalue);
342 	if (TIFFFieldSet(tif,FIELD_MAXSAMPLEVALUE))
343 		fprintf(fd, "  Max Sample Value: %u\n", td->td_maxsamplevalue);
344 	if (TIFFFieldSet(tif,FIELD_SMINSAMPLEVALUE))
345 		fprintf(fd, "  SMin Sample Value: %g\n",
346 		    td->td_sminsamplevalue);
347 	if (TIFFFieldSet(tif,FIELD_SMAXSAMPLEVALUE))
348 		fprintf(fd, "  SMax Sample Value: %g\n",
349 		    td->td_smaxsamplevalue);
350 	if (TIFFFieldSet(tif,FIELD_PLANARCONFIG)) {
351 		fprintf(fd, "  Planar Configuration: ");
352 		switch (td->td_planarconfig) {
353 		case PLANARCONFIG_CONTIG:
354 			fprintf(fd, "single image plane\n");
355 			break;
356 		case PLANARCONFIG_SEPARATE:
357 			fprintf(fd, "separate image planes\n");
358 			break;
359 		default:
360 			fprintf(fd, "%u (0x%x)\n",
361 			    td->td_planarconfig, td->td_planarconfig);
362 			break;
363 		}
364 	}
365 	if (TIFFFieldSet(tif,FIELD_PAGENUMBER))
366 		fprintf(fd, "  Page Number: %u-%u\n",
367 		    td->td_pagenumber[0], td->td_pagenumber[1]);
368 	if (TIFFFieldSet(tif,FIELD_COLORMAP)) {
369 		fprintf(fd, "  Color Map: ");
370 		if (flags & TIFFPRINT_COLORMAP) {
371 			fprintf(fd, "\n");
372 			n = 1L<<td->td_bitspersample;
373 			for (l = 0; l < n; l++)
374 				fprintf(fd, "   %5lu: %5u %5u %5u\n",
375 				    l,
376 				    td->td_colormap[0][l],
377 				    td->td_colormap[1][l],
378 				    td->td_colormap[2][l]);
379 		} else
380 			fprintf(fd, "(present)\n");
381 	}
382 	if (TIFFFieldSet(tif,FIELD_WHITEPOINT))
383 		fprintf(fd, "  White Point: %g-%g\n",
384 		    td->td_whitepoint[0], td->td_whitepoint[1]);
385 	if (TIFFFieldSet(tif,FIELD_REFBLACKWHITE)) {
386 		fprintf(fd, "  Reference Black/White:\n");
387 		for (i = 0; i < td->td_samplesperpixel; i++)
388 			fprintf(fd, "    %2d: %5g %5g\n",
389 			    i,
390 			    td->td_refblackwhite[2*i+0],
391 			    td->td_refblackwhite[2*i+1]);
392 	}
393 	if (TIFFFieldSet(tif,FIELD_TRANSFERFUNCTION)) {
394 		fprintf(fd, "  Transfer Function: ");
395 		if (flags & TIFFPRINT_CURVES) {
396 			fprintf(fd, "\n");
397 			n = 1L<<td->td_bitspersample;
398 			for (l = 0; l < n; l++) {
399 				fprintf(fd, "    %2lu: %5u",
400 				    l, td->td_transferfunction[0][l]);
401 				for (i = 1; i < td->td_samplesperpixel; i++)
402 					fprintf(fd, " %5u",
403 					    td->td_transferfunction[i][l]);
404 				fputc('\n', fd);
405 			}
406 		} else
407 			fprintf(fd, "(present)\n");
408 	}
409 	if (TIFFFieldSet(tif,FIELD_ICCPROFILE))
410 		fprintf(fd, "  ICC Profile: <present>, %lu bytes\n",
411 		    (unsigned long) td->td_profileLength);
412  	if (TIFFFieldSet(tif,FIELD_PHOTOSHOP))
413  		fprintf(fd, "  Photoshop Data: <present>, %lu bytes\n",
414  		    (unsigned long) td->td_photoshopLength);
415  	if (TIFFFieldSet(tif,FIELD_RICHTIFFIPTC))
416  		fprintf(fd, "  RichTIFFIPTC Data: <present>, %lu bytes\n",
417  		    (unsigned long) td->td_richtiffiptcLength);
418 	if (TIFFFieldSet(tif, FIELD_SUBIFD)) {
419 		fprintf(fd, "  SubIFD Offsets:");
420 		for (i = 0; i < td->td_nsubifd; i++)
421 			fprintf(fd, " %5lu", (long) td->td_subifd[i]);
422 		fputc('\n', fd);
423 	}
424  	if (TIFFFieldSet(tif,FIELD_XMLPACKET)) {
425             fprintf(fd, "  XMLPacket (XMP Metadata):\n" );
426             for( i=0; i < td->td_xmlpacketLength; i++ )
427                 fputc( ((char *)td->td_xmlpacketData)[i], fd );
428             fprintf( fd, "\n" );
429         }
430 
431         /*
432         ** Custom tag support.
433         */
434         {
435             int  ii;
436             short count;
437 
438             count = (short) TIFFGetTagListCount(tif);
439             for(ii = 0; ii < count; ii++) {
440                 ttag_t  tag = TIFFGetTagListEntry(tif, ii);
441                 const TIFFFieldInfo *fip;
442                 uint16 value_count;
443                 int j, mem_alloc = 0;
444                 void *raw_data;
445 
446                 fip = TIFFFieldWithTag(tif, tag);
447                 if(fip == NULL)
448 			continue;
449 
450 		if(fip->field_passcount) {
451 			if(TIFFGetField(tif, tag, &value_count, &raw_data) != 1)
452 				continue;
453 		} else {
454 			if (fip->field_readcount == TIFF_VARIABLE
455 			    || fip->field_readcount == TIFF_VARIABLE2)
456 				value_count = 1;
457 			else if (fip->field_readcount == TIFF_SPP)
458 				value_count = td->td_samplesperpixel;
459 			else
460 				value_count = fip->field_readcount;
461 			if (fip->field_type == TIFF_ASCII
462 			    || fip->field_readcount == TIFF_VARIABLE
463 			    || fip->field_readcount == TIFF_VARIABLE2
464 			    || fip->field_readcount == TIFF_SPP
465 			    || value_count > 1) {
466 				if(TIFFGetField(tif, tag, &raw_data) != 1)
467 					continue;
468 			} else {
469 				raw_data = _TIFFmalloc(
470 					_TIFFDataSize(fip->field_type)
471 					* value_count);
472 				mem_alloc = 1;
473 				if(TIFFGetField(tif, tag, raw_data) != 1) {
474 					_TIFFfree(raw_data);
475 					continue;
476 				}
477 			}
478 		}
479 
480 		fprintf(fd, "  %s: ", fip->field_name);
481 
482 		for(j = 0; j < value_count; j++) {
483 		    if(fip->field_type == TIFF_BYTE)
484 		        fprintf(fd, "%u", ((uint8 *) raw_data)[j]);
485 		    else if(fip->field_type == TIFF_UNDEFINED)
486 		        fprintf(fd, "0x%x",
487 				(unsigned int) ((unsigned char *) raw_data)[j]);
488 		    else if(fip->field_type == TIFF_SBYTE)
489 		        fprintf(fd, "%d", ((int8 *) raw_data)[j]);
490 		    else if(fip->field_type == TIFF_SHORT)
491 		        fprintf(fd, "%u", ((uint16 *) raw_data)[j]);
492 		    else if(fip->field_type == TIFF_SSHORT)
493 		        fprintf(fd, "%d", ((int16 *) raw_data)[j]);
494 		    else if(fip->field_type == TIFF_LONG)
495 		        fprintf(fd, "%lu",
496 		    	    (unsigned long)((uint32 *) raw_data)[j]);
497 		    else if(fip->field_type == TIFF_SLONG)
498 		        fprintf(fd, "%ld", (long)((int32 *) raw_data)[j]);
499 		    else if(fip->field_type == TIFF_RATIONAL
500 			    || fip->field_type == TIFF_SRATIONAL
501 			    || fip->field_type == TIFF_FLOAT)
502 		        fprintf(fd, "%f", ((float *) raw_data)[j]);
503 		    else if(fip->field_type == TIFF_IFD)
504 		        fprintf(fd, "0x%ulx", ((uint16 *) raw_data)[j]);
505 		    else if(fip->field_type == TIFF_ASCII) {
506 		        fprintf(fd, "%s", (char *) raw_data);
507 		        break;
508 		    }
509 		    else if(fip->field_type == TIFF_DOUBLE)
510 		        fprintf(fd, "%f", ((double *) raw_data)[j]);
511 		    else if(fip->field_type == TIFF_FLOAT)
512 		        fprintf(fd, "%f", ((float *)raw_data)[j]);
513 		    else {
514 		        fprintf(fd, "<unsupported data type in TIFFPrint>");
515 		        break;
516 		    }
517 
518 		    if(j < value_count - 1)
519 		        fprintf(fd, ",");
520 		}
521 		fprintf(fd, "\n");
522 		if(mem_alloc)
523 			_TIFFfree(raw_data);
524             }
525         }
526 
527 	if (tif->tif_tagmethods.printdir)
528 		(*tif->tif_tagmethods.printdir)(tif, fd, flags);
529 	if ((flags & TIFFPRINT_STRIPS) &&
530 	    TIFFFieldSet(tif,FIELD_STRIPOFFSETS)) {
531 		tstrip_t s;
532 
533 		fprintf(fd, "  %lu %s:\n",
534 		    (long) td->td_nstrips,
535 		    isTiled(tif) ? "Tiles" : "Strips");
536 		for (s = 0; s < td->td_nstrips; s++)
537 			fprintf(fd, "    %3lu: [%8lu, %8lu]\n",
538 			    (unsigned long) s,
539 			    (unsigned long) td->td_stripoffset[s],
540 			    (unsigned long) td->td_stripbytecount[s]);
541 	}
542 }
543 
544 void
_TIFFprintAscii(FILE * fd,const char * cp)545 _TIFFprintAscii(FILE* fd, const char* cp)
546 {
547 	for (; *cp != '\0'; cp++) {
548 		const char* tp;
549 
550 		if (isprint((int)*cp)) {
551 			fputc(*cp, fd);
552 			continue;
553 		}
554 		for (tp = "\tt\bb\rr\nn\vv"; *tp; tp++)
555 			if (*tp++ == *cp)
556 				break;
557 		if (*tp)
558 			fprintf(fd, "\\%c", *tp);
559 		else
560 			fprintf(fd, "\\%03o", *cp & 0xff);
561 	}
562 }
563 
564 void
_TIFFprintAsciiTag(FILE * fd,const char * name,const char * value)565 _TIFFprintAsciiTag(FILE* fd, const char* name, const char* value)
566 {
567 	fprintf(fd, "  %s: \"", name);
568 	_TIFFprintAscii(fd, value);
569 	fprintf(fd, "\"\n");
570 }
571 #endif /* PDFLIB_TIFFWRITE_SUPPORT */
572 
573 /* vim: set ts=8 sts=8 sw=8 noet: */
574