tif_print.c

来自「支持各种栅格图像和矢量图像读取的库」· C语言 代码 · 共 640 行 · 第 1/2 页

C
640
字号
		sep = "";		for (i = 0; i < td->td_extrasamples; i++) {			switch (td->td_sampleinfo[i]) {			case EXTRASAMPLE_UNSPECIFIED:				fprintf(fd, "%sunspecified", sep);				break;			case EXTRASAMPLE_ASSOCALPHA:				fprintf(fd, "%sassoc-alpha", sep);				break;			case EXTRASAMPLE_UNASSALPHA:				fprintf(fd, "%sunassoc-alpha", sep);				break;			default:				fprintf(fd, "%s%u (0x%x)", sep,				    td->td_sampleinfo[i], td->td_sampleinfo[i]);				break;			}			sep = ", ";		}		fprintf(fd, ">\n");	}	if (TIFFFieldSet(tif,FIELD_INKNAMES)) {		char* cp;		fprintf(fd, "  Ink Names: ");		i = td->td_samplesperpixel;		sep = "";		for (cp = td->td_inknames; i > 0; cp = strchr(cp,'\0')+1, i--) {			fputs(sep, fd);			_TIFFprintAscii(fd, cp);			sep = ", ";		}                fputs("\n", fd);	}	if (TIFFFieldSet(tif,FIELD_THRESHHOLDING)) {		fprintf(fd, "  Thresholding: ");		switch (td->td_threshholding) {		case THRESHHOLD_BILEVEL:			fprintf(fd, "bilevel art scan\n");			break;		case THRESHHOLD_HALFTONE:			fprintf(fd, "halftone or dithered scan\n");			break;		case THRESHHOLD_ERRORDIFFUSE:			fprintf(fd, "error diffused\n");			break;		default:			fprintf(fd, "%u (0x%x)\n",			    td->td_threshholding, td->td_threshholding);			break;		}	}	if (TIFFFieldSet(tif,FIELD_FILLORDER)) {		fprintf(fd, "  FillOrder: ");		switch (td->td_fillorder) {		case FILLORDER_MSB2LSB:			fprintf(fd, "msb-to-lsb\n");			break;		case FILLORDER_LSB2MSB:			fprintf(fd, "lsb-to-msb\n");			break;		default:			fprintf(fd, "%u (0x%x)\n",			    td->td_fillorder, td->td_fillorder);			break;		}	}	if (TIFFFieldSet(tif,FIELD_YCBCRSUBSAMPLING))        {            /*             * For hacky reasons (see tif_jpeg.c - JPEGFixupTestSubsampling),             * we need to fetch this rather than trust what is in our             * structures.             */            uint16 subsampling[2];            TIFFGetField( tif, TIFFTAG_YCBCRSUBSAMPLING,                           subsampling + 0, subsampling + 1 );		fprintf(fd, "  YCbCr Subsampling: %u, %u\n",                        subsampling[0], subsampling[1] );        }	if (TIFFFieldSet(tif,FIELD_YCBCRPOSITIONING)) {		fprintf(fd, "  YCbCr Positioning: ");		switch (td->td_ycbcrpositioning) {		case YCBCRPOSITION_CENTERED:			fprintf(fd, "centered\n");			break;		case YCBCRPOSITION_COSITED:			fprintf(fd, "cosited\n");			break;		default:			fprintf(fd, "%u (0x%x)\n",			    td->td_ycbcrpositioning, td->td_ycbcrpositioning);			break;		}	}	if (TIFFFieldSet(tif,FIELD_HALFTONEHINTS))		fprintf(fd, "  Halftone Hints: light %u dark %u\n",		    td->td_halftonehints[0], td->td_halftonehints[1]);	if (TIFFFieldSet(tif,FIELD_ORIENTATION)) {		fprintf(fd, "  Orientation: ");		if (td->td_orientation < NORIENTNAMES)			fprintf(fd, "%s\n", orientNames[td->td_orientation]);		else			fprintf(fd, "%u (0x%x)\n",			    td->td_orientation, td->td_orientation);	}	if (TIFFFieldSet(tif,FIELD_SAMPLESPERPIXEL))		fprintf(fd, "  Samples/Pixel: %u\n", td->td_samplesperpixel);	if (TIFFFieldSet(tif,FIELD_ROWSPERSTRIP)) {		fprintf(fd, "  Rows/Strip: ");		if (td->td_rowsperstrip == (uint32) -1)			fprintf(fd, "(infinite)\n");		else			fprintf(fd, "%lu\n", (unsigned long) td->td_rowsperstrip);	}	if (TIFFFieldSet(tif,FIELD_MINSAMPLEVALUE))		fprintf(fd, "  Min Sample Value: %u\n", td->td_minsamplevalue);	if (TIFFFieldSet(tif,FIELD_MAXSAMPLEVALUE))		fprintf(fd, "  Max Sample Value: %u\n", td->td_maxsamplevalue);	if (TIFFFieldSet(tif,FIELD_SMINSAMPLEVALUE))		fprintf(fd, "  SMin Sample Value: %g\n",		    td->td_sminsamplevalue);	if (TIFFFieldSet(tif,FIELD_SMAXSAMPLEVALUE))		fprintf(fd, "  SMax Sample Value: %g\n",		    td->td_smaxsamplevalue);	if (TIFFFieldSet(tif,FIELD_PLANARCONFIG)) {		fprintf(fd, "  Planar Configuration: ");		switch (td->td_planarconfig) {		case PLANARCONFIG_CONTIG:			fprintf(fd, "single image plane\n");			break;		case PLANARCONFIG_SEPARATE:			fprintf(fd, "separate image planes\n");			break;		default:			fprintf(fd, "%u (0x%x)\n",			    td->td_planarconfig, td->td_planarconfig);			break;		}	}	if (TIFFFieldSet(tif,FIELD_PAGENUMBER))		fprintf(fd, "  Page Number: %u-%u\n",		    td->td_pagenumber[0], td->td_pagenumber[1]);	if (TIFFFieldSet(tif,FIELD_COLORMAP)) {		fprintf(fd, "  Color Map: ");		if (flags & TIFFPRINT_COLORMAP) {			fprintf(fd, "\n");			n = 1L<<td->td_bitspersample;			for (l = 0; l < n; l++)				fprintf(fd, "   %5lu: %5u %5u %5u\n",				    l,				    td->td_colormap[0][l],				    td->td_colormap[1][l],				    td->td_colormap[2][l]);		} else			fprintf(fd, "(present)\n");	}	if (TIFFFieldSet(tif,FIELD_TRANSFERFUNCTION)) {		fprintf(fd, "  Transfer Function: ");		if (flags & TIFFPRINT_CURVES) {			fprintf(fd, "\n");			n = 1L<<td->td_bitspersample;			for (l = 0; l < n; l++) {				fprintf(fd, "    %2lu: %5u",				    l, td->td_transferfunction[0][l]);				for (i = 1; i < td->td_samplesperpixel; i++)					fprintf(fd, " %5u",					    td->td_transferfunction[i][l]);				fputc('\n', fd);			}		} else			fprintf(fd, "(present)\n");	}	if (TIFFFieldSet(tif, FIELD_SUBIFD)) {		fprintf(fd, "  SubIFD Offsets:");		for (i = 0; i < td->td_nsubifd; i++)			fprintf(fd, " %5lu", (long) td->td_subifd[i]);		fputc('\n', fd);	}        /*        ** Custom tag support.        */        {            int  i;            short count;            count = (short) TIFFGetTagListCount(tif);            for(i = 0; i < count; i++) {                ttag_t  tag = TIFFGetTagListEntry(tif, i);                const TIFFFieldInfo *fip;                uint32 value_count;                int mem_alloc = 0;                void *raw_data;                fip = TIFFFieldWithTag(tif, tag);                if(fip == NULL)			continue;		if(fip->field_passcount) {			if(TIFFGetField(tif, tag, &value_count, &raw_data) != 1)				continue;		} else {			if (fip->field_readcount == TIFF_VARIABLE			    || fip->field_readcount == TIFF_VARIABLE2)				value_count = 1;			else if (fip->field_readcount == TIFF_SPP)				value_count = td->td_samplesperpixel;			else				value_count = fip->field_readcount;			if ((fip->field_type == TIFF_ASCII			     || fip->field_readcount == TIFF_VARIABLE			     || fip->field_readcount == TIFF_VARIABLE2			     || fip->field_readcount == TIFF_SPP			     || value_count > 1)			    && fip->field_tag != TIFFTAG_PAGENUMBER			    && fip->field_tag != TIFFTAG_HALFTONEHINTS			    && fip->field_tag != TIFFTAG_YCBCRSUBSAMPLING			    && fip->field_tag != TIFFTAG_DOTRANGE) {				if(TIFFGetField(tif, tag, &raw_data) != 1)					continue;			} else if (fip->field_tag != TIFFTAG_PAGENUMBER				   && fip->field_tag != TIFFTAG_HALFTONEHINTS				   && fip->field_tag != TIFFTAG_YCBCRSUBSAMPLING				   && fip->field_tag != TIFFTAG_DOTRANGE) {				raw_data = _TIFFmalloc(					_TIFFDataSize(fip->field_type)					* value_count);				mem_alloc = 1;				if(TIFFGetField(tif, tag, raw_data) != 1) {					_TIFFfree(raw_data);					continue;				}			} else {				/* 				 * XXX: Should be fixed and removed, see the				 * notes related to TIFFTAG_PAGENUMBER,				 * TIFFTAG_HALFTONEHINTS,				 * TIFFTAG_YCBCRSUBSAMPLING and				 * TIFFTAG_DOTRANGE tags in tif_dir.c. */				char *tmp;				raw_data = _TIFFmalloc(					_TIFFDataSize(fip->field_type)					* value_count);				tmp = raw_data;				mem_alloc = 1;				if(TIFFGetField(tif, tag, tmp,				tmp + _TIFFDataSize(fip->field_type)) != 1) {					_TIFFfree(raw_data);					continue;				}			}		}		/*		 * Catch the tags which needs to be specially handled and		 * pretty print them. If tag not handled in		 * _TIFFPrettyPrintField() fall down and print it as any other		 * tag.		 */		if (_TIFFPrettyPrintField(tif, fd, tag, value_count, raw_data)) {			if(mem_alloc)				_TIFFfree(raw_data);			continue;		}		else			_TIFFPrintField(fd, fip, value_count, raw_data);		if(mem_alloc)			_TIFFfree(raw_data);            }        }        	if (tif->tif_tagmethods.printdir)		(*tif->tif_tagmethods.printdir)(tif, fd, flags);	if ((flags & TIFFPRINT_STRIPS) &&	    TIFFFieldSet(tif,FIELD_STRIPOFFSETS)) {		tstrip_t s;		fprintf(fd, "  %lu %s:\n",		    (long) td->td_nstrips,		    isTiled(tif) ? "Tiles" : "Strips");		for (s = 0; s < td->td_nstrips; s++)			fprintf(fd, "    %3lu: [%8lu, %8lu]\n",			    (unsigned long) s,			    (unsigned long) td->td_stripoffset[s],			    (unsigned long) td->td_stripbytecount[s]);	}}void_TIFFprintAscii(FILE* fd, const char* cp){	for (; *cp != '\0'; cp++) {		const char* tp;		if (isprint((int)*cp)) {			fputc(*cp, fd);			continue;		}		for (tp = "\tt\bb\rr\nn\vv"; *tp; tp++)			if (*tp++ == *cp)				break;		if (*tp)			fprintf(fd, "\\%c", *tp);		else			fprintf(fd, "\\%03o", *cp & 0xff);	}}void_TIFFprintAsciiTag(FILE* fd, const char* name, const char* value){	fprintf(fd, "  %s: \"", name);	_TIFFprintAscii(fd, value);	fprintf(fd, "\"\n");}/* vim: set ts=8 sts=8 sw=8 noet: */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?