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