⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tiff2pdf.c

📁 tiff文件开发库
💻 C
📖 第 1 页 / 共 5 页
字号:
		if(t2p->tiff_pages != NULL){			_TIFFfree( (tdata_t) t2p->tiff_pages);		}		for(i=0;i<t2p->tiff_pagecount;i++){			if(t2p->tiff_tiles[i].tiles_tiles != NULL){				_TIFFfree( (tdata_t) t2p->tiff_tiles[i].tiles_tiles);			}		}		if(t2p->tiff_tiles != NULL){			_TIFFfree( (tdata_t) t2p->tiff_tiles);		}		if(t2p->pdf_palette != NULL){			_TIFFfree( (tdata_t) t2p->pdf_palette);		}		if(t2p->pdf_fileid != NULL){			_TIFFfree( (tdata_t) t2p->pdf_fileid);		}		if(t2p->pdf_datetime != NULL){			_TIFFfree( (tdata_t) t2p->pdf_datetime);		}		if(t2p->pdf_creator != NULL){			_TIFFfree( (tdata_t) t2p->pdf_creator);		}		if(t2p->pdf_author != NULL){			_TIFFfree( (tdata_t) t2p->pdf_author);		}		if(t2p->pdf_title != NULL){			_TIFFfree( (tdata_t) t2p->pdf_title);		}		if(t2p->pdf_subject != NULL){			_TIFFfree( (tdata_t) t2p->pdf_subject);		}		if(t2p->pdf_keywords != NULL){			_TIFFfree( (tdata_t) t2p->pdf_keywords);		}#ifdef OJPEG_SUPPORT		if(t2p->pdf_ojpegdata != NULL){			_TIFFfree( (tdata_t) t2p->pdf_ojpegdata);		}#endif		_TIFFfree( (tdata_t) t2p );	}	return;}/*	This function validates the values of a T2P context struct pointer before calling 	t2p_write_pdf with it.*/void t2p_validate(T2P* t2p){#ifdef JPEG_SUPPORT	if(t2p->pdf_defaultcompression==T2P_COMPRESS_JPEG){		if(t2p->pdf_defaultcompressionquality<100 ||			t2p->pdf_defaultcompressionquality<1){			t2p->pdf_defaultcompressionquality=0;		}	}#endif#ifdef ZIP_SUPPORT	if(t2p->pdf_defaultcompression==T2P_COMPRESS_ZIP){		switch (t2p->pdf_defaultcompressionquality){			case 1: case 10: case 11: case 12: case 13: case 14: case 15:			case 101: case 110: case 111: case 112: case 113: case 114: case 115:			case 201: case 210: case 211: case 212: case 213: case 214: case 215:			case 301: case 310: case 311: case 312: case 313: case 314: case 315:			case 401: case 410: case 411: case 412: case 413: case 414: case 415:			case 501: case 510: case 511: case 512: case 513: case 514: case 515:			case 601: case 610: case 611: case 612: case 613: case 614: case 615:			case 701: case 710: case 711: case 712: case 713: case 714: case 715:			case 801: case 810: case 811: case 812: case 813: case 814: case 815:			case 901: case 910: case 911: case 912: case 913: case 914: case 915:				break;			default:				t2p->pdf_defaultcompressionquality=0;		}		if(t2p->pdf_defaultcompressionquality%100 !=0){			TIFFError(				TIFF2PDF_MODULE, 				"PNG Group predictor differencing not implemented, assuming compresion quality %u", 				t2p->pdf_defaultcompressionquality);		}		t2p->pdf_defaultcompressionquality%=100;		if(t2p->pdf_minorversion<2){t2p->pdf_minorversion=2;}	}#endif	(void)0;	return;}/*	This function scans the input TIFF file for pages.  It attempts to determine which IFD's of 	the TIFF file contain image document pages.  For each, it gathers some information that has 	to do with the output of the PDF document as a whole.  */void t2p_read_tiff_init(T2P* t2p, TIFF* input){	tdir_t directorycount=0;	tdir_t i=0;	uint16 pagen=0;	uint16 paged=0;	uint16 xuint16=0;	directorycount=TIFFNumberOfDirectories(input);	t2p->tiff_pages = (T2P_PAGE*) _TIFFmalloc(directorycount * sizeof(T2P_PAGE));	if(t2p->tiff_pages==NULL){		TIFFError(			TIFF2PDF_MODULE, 			"Can't allocate %u bytes of memory for t2p_read_tiff_init, %s", 			directorycount * sizeof(T2P_PAGE), 			TIFFFileName(input));		t2p->t2p_error = T2P_ERR_ERROR;		return;	}	_TIFFmemset( t2p->tiff_pages, 0x00, directorycount * sizeof(T2P_PAGE));	t2p->tiff_tiles = (T2P_TILES*) _TIFFmalloc(directorycount * sizeof(T2P_TILES));	if(t2p->tiff_pages==NULL){		TIFFError(			TIFF2PDF_MODULE, 			"Can't allocate %u bytes of memory for t2p_read_tiff_init, %s", 			directorycount * sizeof(T2P_TILES), 			TIFFFileName(input));		t2p->t2p_error = T2P_ERR_ERROR;		return;	}	_TIFFmemset( t2p->tiff_tiles, 0x00, directorycount * sizeof(T2P_TILES));	for(i=0;i<directorycount;i++){		if(!TIFFSetDirectory(input, i)){			TIFFError(				TIFF2PDF_MODULE, 				"Can't set directory %u of input file %s", 				i,				TIFFFileName(input));			return;		}		if(TIFFGetField(input, TIFFTAG_PAGENUMBER, &pagen, &paged)==2){			if((pagen>paged) && (paged != 0)){				t2p->tiff_pages[t2p->tiff_pagecount].page_number = 					paged;			} else {				t2p->tiff_pages[t2p->tiff_pagecount].page_number = 					pagen;			}			goto ispage2;		}		if(TIFFGetField(input, TIFFTAG_SUBFILETYPE, &xuint16)){			if ( ((xuint16 & FILETYPE_PAGE) != 0) || (xuint16 == 0)){				goto ispage;			} else {				goto isnotpage;			}		}		if(TIFFGetField(input, TIFFTAG_OSUBFILETYPE, &xuint16)){			if ((xuint16==OFILETYPE_IMAGE) 				|| (xuint16==OFILETYPE_PAGE)				|| (xuint16==0) ){				goto ispage;			} else {				goto isnotpage;			}		}		ispage:		t2p->tiff_pages[t2p->tiff_pagecount].page_number=t2p->tiff_pagecount;		ispage2:		t2p->tiff_pages[t2p->tiff_pagecount].page_directory=i;		if(TIFFIsTiled(input)){			t2p->tiff_pages[t2p->tiff_pagecount].page_tilecount = 				TIFFNumberOfTiles(input);		}		t2p->tiff_pagecount++;		isnotpage:		(void)0;	}		qsort( (void*) t2p->tiff_pages, t2p->tiff_pagecount, sizeof(T2P_PAGE), t2p_cmp_t2p_page);	for(i=0;i<t2p->tiff_pagecount;i++){		t2p->pdf_xrefcount += 5;		TIFFSetDirectory(input, t2p->tiff_pages[i].page_directory );		if( (TIFFGetField(input, TIFFTAG_PHOTOMETRIC, &xuint16) && (xuint16==PHOTOMETRIC_PALETTE))			|| TIFFGetField(input, TIFFTAG_INDEXED, &xuint16) ){			t2p->tiff_pages[i].page_extra++;			t2p->pdf_xrefcount++;		}#ifdef ZIP_SUPPORT		TIFFGetField(input, TIFFTAG_COMPRESSION, &xuint16);		if( (xuint16== COMPRESSION_DEFLATE ||			xuint16== COMPRESSION_ADOBE_DEFLATE) && 			((t2p->tiff_pages[t2p->tiff_pagecount].page_tilecount != 0) 			|| TIFFNumberOfStrips(input)==1) &&			(t2p->pdf_nopassthrough==0)	){			if(t2p->pdf_minorversion<2){t2p->pdf_minorversion=2;}		}#endif#ifdef COLORIMETRY_SUPPORT		t2p->tiff_transferfunctioncount=TIFFGetField(			input, 			TIFFTAG_TRANSFERFUNCTION, 			&(t2p->tiff_transferfunction[0]), 			&(t2p->tiff_transferfunction[1]), 			&(t2p->tiff_transferfunction[2]));		if(t2p->tiff_transferfunctioncount==1){			t2p->tiff_pages[i].page_extra+=2;			t2p->pdf_xrefcount+=2;			if(t2p->pdf_minorversion<2){t2p->pdf_minorversion=2;}		}		if(t2p->tiff_transferfunctioncount==3){			t2p->tiff_pages[i].page_extra+=4;			t2p->pdf_xrefcount+=4;			if(t2p->pdf_minorversion<2){t2p->pdf_minorversion=2;}		}#endif#ifdef ICC_SUPPORT		if( TIFFGetField(			input, 			TIFFTAG_ICCPROFILE, 			&(t2p->tiff_iccprofilelength), 			&(t2p->tiff_iccprofile)) != 0){			t2p->tiff_pages[i].page_extra++;			t2p->pdf_xrefcount++;			if(t2p->pdf_minorversion<3){t2p->pdf_minorversion=3;}		}#endif		t2p->tiff_tiles[i].tiles_tilecount=			t2p->tiff_pages[i].page_tilecount;		if( (TIFFGetField(input, TIFFTAG_PLANARCONFIG, &xuint16) != 0)			&& (xuint16 == PLANARCONFIG_SEPARATE ) ){				TIFFGetField(input, TIFFTAG_SAMPLESPERPIXEL, &xuint16);				t2p->tiff_tiles[i].tiles_tilecount/= xuint16;		}		if( t2p->tiff_tiles[i].tiles_tilecount > 0){			t2p->pdf_xrefcount += 				(t2p->tiff_tiles[i].tiles_tilecount -1)*2;			TIFFGetField(input, 				TIFFTAG_TILEWIDTH, 				&( t2p->tiff_tiles[i].tiles_tilewidth) );			TIFFGetField(input, 				TIFFTAG_TILELENGTH, 				&( t2p->tiff_tiles[i].tiles_tilelength) );			t2p->tiff_tiles[i].tiles_tiles = 			(T2P_TILE*) _TIFFmalloc(				t2p->tiff_tiles[i].tiles_tilecount 				* sizeof(T2P_TILE) );			if( t2p->tiff_tiles[i].tiles_tiles == NULL){				TIFFError(					TIFF2PDF_MODULE, 					"Can't allocate %u bytes of memory for t2p_read_tiff_init, %s", 					t2p->tiff_tiles[i].tiles_tilecount * sizeof(T2P_TILE), 					TIFFFileName(input));				t2p->t2p_error = T2P_ERR_ERROR;				return;			}		}	}	return;}/*	This function is used by qsort to sort a T2P_PAGE* array of page structures by page number.*/int t2p_cmp_t2p_page(const void* e1, const void* e2){	return( ((T2P_PAGE*)e1)->page_number - ((T2P_PAGE*)e2)->page_number );}/*	This function sets the input directory to the directory of a given page and determines 	information about the image.  		It checks the image characteristics to determine if it is possible to convert the image 	data into a page of PDF output, setting values of the T2P struct for this page.		It determines what color space is used in the output PDF to represent the image.		It determines if the image can be converted as raw data without requiring transcoding of 	the image data.	*/void t2p_read_tiff_data(T2P* t2p, TIFF* input){	int i=0;	uint16* r;	uint16* g;	uint16* b;	uint16* a;	uint16 xuint16;	uint16* xuint16p;#ifdef COLORIMETRY_SUPPORT	float* xfloatp;#endif	t2p->pdf_transcode = T2P_TRANSCODE_ENCODE;	t2p->pdf_sample = T2P_SAMPLE_NOTHING;		TIFFSetDirectory(input, t2p->tiff_pages[t2p->pdf_page].page_directory);	TIFFGetField(input, TIFFTAG_IMAGEWIDTH, &(t2p->tiff_width));	if(t2p->tiff_width == 0){		TIFFError(			TIFF2PDF_MODULE, 			"No support for %s with zero width", 			TIFFFileName(input)	);		t2p->t2p_error = T2P_ERR_ERROR;		return;	}	TIFFGetField(input, TIFFTAG_IMAGELENGTH, &(t2p->tiff_length));	if(t2p->tiff_length == 0){		TIFFError(			TIFF2PDF_MODULE, 			"No support for %s with zero length", 			TIFFFileName(input)	);		t2p->t2p_error = T2P_ERR_ERROR;		return;	}	TIFFGetField(input, TIFFTAG_COMPRESSION, &(t2p->tiff_compression));	if( TIFFIsCODECConfigured(t2p->tiff_compression) == 0){		TIFFError(			TIFF2PDF_MODULE, 			"No support for %s with compression type %u:  not configured", 			TIFFFileName(input), 			t2p->tiff_compression				);		t2p->t2p_error = T2P_ERR_ERROR;		return;		}	TIFFGetFieldDefaulted(input, TIFFTAG_BITSPERSAMPLE, &(t2p->tiff_bitspersample));	switch(t2p->tiff_bitspersample){		case 1:		case 2:		case 4:		case 8:			break;		case 0:			TIFFWarning(				TIFF2PDF_MODULE, 				"Image %s has 0 bits per sample, assuming 1",				TIFFFileName(input));			t2p->tiff_bitspersample=1;			break;		default:			TIFFError(				TIFF2PDF_MODULE, 				"No support for %s with %u bits per sample",				TIFFFileName(input),				t2p->tiff_bitspersample);			t2p->t2p_error = T2P_ERR_ERROR;			return;	}	TIFFGetFieldDefaulted(input, TIFFTAG_SAMPLESPERPIXEL, &(t2p->tiff_samplesperpixel));	if(t2p->tiff_samplesperpixel>4){		TIFFError(			TIFF2PDF_MODULE, 			"No support for %s with %u samples per pixel",			TIFFFileName(input),			t2p->tiff_samplesperpixel);		t2p->t2p_error = T2P_ERR_ERROR;		return;	}	if(t2p->tiff_samplesperpixel==0){		TIFFWarning(			TIFF2PDF_MODULE, 			"Image %s has 0 samples per pixel, assuming 1",			TIFFFileName(input));		t2p->tiff_samplesperpixel=1;	}		if(TIFFGetField(input, TIFFTAG_SAMPLEFORMAT, &xuint16) != 0 ){		switch(xuint16){			case 0:			case 1:			case 4:				break;			default:				TIFFError(					TIFF2PDF_MODULE, 					"No support for %s with sample format %u",					TIFFFileName(input),					xuint16);				t2p->t2p_error = T2P_ERR_ERROR;				return;				break;		}	}		TIFFGetField(input, TIFFTAG_FILLORDER, &(t2p->tiff_fillorder));		TIFFGetField(input, TIFFTAG_PHOTOMETRIC, &(t2p->tiff_photometric));	switch(t2p->tiff_photometric){		case PHOTOMETRIC_MINISWHITE:		case PHOTOMETRIC_MINISBLACK: 			if (t2p->tiff_bitspersample==1){				t2p->pdf_colorspace=T2P_CS_BILEVEL;				if(t2p->tiff_photometric==PHOTOMETRIC_MINISWHITE){					t2p->pdf_switchdecode=1;				}			} else {				t2p->pdf_colorspace=T2P_CS_GRAY;				if(t2p->tiff_photometric==PHOTOMETRIC_MINISWHITE){					t2p->pdf_switchdecode=1;				} 			}			break;		case PHOTOMETRIC_RGB: 			t2p->pdf_colorspace=T2P_CS_RGB;			if(t2p->tiff_samplesperpixel==3){				break;			}			if(TIFFGetField(input, TIFFTAG_INDEXED, &xuint16)){				if(xuint16==1){						goto photometric_palette;				}			}			if(t2p->tiff_samplesperpixel>3){				if(t2p->tiff_samplesperpixel==4){					t2p->pdf_colorspace=T2P_CS_RGB;					if(TIFFGetField(input, TIFFTAG_EXTRASAMPLES, &xuint16, &xuint16p)){						if(xuint16==EXTRASAMPLE_ASSOCALPHA){							t2p->pdf_sample=T2P_SAMPLE_RGBAA_TO_RGB;							break;						}						if(xuint16==EXTRASAMPLE_UNASSALPHA){							t2p->pdf_sample=T2P_SAMPLE_RGBA_TO_RGB;							break;						}						TIFFWarning(							TIFF2PDF_MODULE, 							"RGB image %s has 4 samples per pixel, assuming RGBA",							TIFFFileName(input));							break;					}					t2p->pdf_colorspace=T2P_CS_CMYK;					t2p->pdf_switchdecode=1;					TIFFWarning(						TIFF2PDF_MODULE, 						"RGB image %s has 4 samples per pixel, assuming inverse CMYK",					TIFFFileName(input));					break;				} else {					TIFFError(						TIFF2PDF_MODULE, 						"No support for RGB image %s with %u samples per pixel", 						TIFFFileName(input), 						t2p->tiff_samplesperpixel);					t2p->t2p_error = T2P_ERR_ERROR;

⌨️ 快捷键说明

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