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

📄 tiffcp.c

📁 tiff文件开发库
💻 C
📖 第 1 页 / 共 3 页
字号:
				tsize_t n = scanlinesize;                                uint8* sbuf = scanline;				if (TIFFReadScanline(in, scanline, row, s) < 0 && !ignore)					goto done;				while (n-- > 0)					*bp = *sbuf++, bp += spp;			}			bufp += scanlinesize * spp;		}done:		_TIFFfree(scanline);	}}DECLAREreadFunc(readContigTilesIntoBuffer){	tdata_t tilebuf = _TIFFmalloc(TIFFTileSize(in));	uint32 imagew = TIFFScanlineSize(in);	uint32 tilew  = TIFFTileRowSize(in);	int iskew = imagew - tilew;	uint8* bufp = (uint8*) buf;	uint32 tw, tl;	uint32 row;	(void) spp;	if (tilebuf == 0)		return;	(void) TIFFGetField(in, TIFFTAG_TILEWIDTH, &tw);	(void) TIFFGetField(in, TIFFTAG_TILELENGTH, &tl);        	for (row = 0; row < imagelength; row += tl) {		uint32 nrow = (row+tl > imagelength) ? imagelength-row : tl;		uint32 colb = 0;		uint32 col;		for (col = 0; col < imagewidth; col += tw) {			if (TIFFReadTile(in, tilebuf, col, row, 0, 0) < 0 &&			    !ignore)				goto done;			if (colb + tilew > imagew) {				uint32 width = imagew - colb;				uint32 oskew = tilew - width;				cpStripToTile(bufp + colb,                                              tilebuf, nrow, width,                                              oskew + iskew, oskew );			} else				cpStripToTile(bufp + colb,                                              tilebuf, nrow, tilew,                                              iskew, 0);			colb += tilew;		}		bufp += imagew * nrow;	}done:	_TIFFfree(tilebuf);}DECLAREreadFunc(readSeparateTilesIntoBuffer){	uint32 imagew = TIFFRasterScanlineSize(in);	uint32 tilew = TIFFTileRowSize(in);	int iskew  = imagew - tilew*spp;	tdata_t tilebuf = _TIFFmalloc(TIFFTileSize(in));	uint8* bufp = (uint8*) buf;	uint32 tw, tl;	uint32 row;        uint16 bps, bytes_per_sample;	if (tilebuf == 0)		return;	(void) TIFFGetField(in, TIFFTAG_TILEWIDTH, &tw);	(void) TIFFGetField(in, TIFFTAG_TILELENGTH, &tl);	(void) TIFFGetField(in, TIFFTAG_BITSPERSAMPLE, &bps);        assert( bps % 8 == 0 );        bytes_per_sample = bps/8;	for (row = 0; row < imagelength; row += tl) {		uint32 nrow = (row+tl > imagelength) ? imagelength-row : tl;		uint32 colb = 0;		uint32 col;		for (col = 0; col < imagewidth; col += tw) {			tsample_t s;			for (s = 0; s < spp; s++) {				if (TIFFReadTile(in, tilebuf, col, row, 0, s) < 0 && !ignore)					goto done;				/*				 * Tile is clipped horizontally.  Calculate				 * visible portion and skewing factors.				 */				if (colb + tilew*spp > imagew) {					uint32 width = imagew - colb;					int oskew = tilew*spp - width;					cpSeparateBufToContigBuf(                                            bufp+colb+s*bytes_per_sample,					    tilebuf, nrow,                                            width/(spp*bytes_per_sample),					    oskew + iskew,                                            oskew/spp, spp,                                            bytes_per_sample);				} else					cpSeparateBufToContigBuf(                                            bufp+colb+s*bytes_per_sample,					    tilebuf, nrow, tw,					    iskew, 0, spp,                                            bytes_per_sample);			}			colb += tilew*spp;		}		bufp += imagew * nrow;	}done:	_TIFFfree(tilebuf);}DECLAREwriteFunc(writeBufferToContigStrips){	uint32 row, rowsperstrip;	tstrip_t strip = 0;	(void) imagewidth; (void) spp;	(void) TIFFGetFieldDefaulted(out, TIFFTAG_ROWSPERSTRIP, &rowsperstrip);	for (row = 0; row < imagelength; row += rowsperstrip) {		uint32 nrows = (row+rowsperstrip > imagelength) ?		    imagelength-row : rowsperstrip;		tsize_t stripsize = TIFFVStripSize(out, nrows);		if (TIFFWriteEncodedStrip(out, strip++, buf, stripsize) < 0)			return (FALSE);		buf += stripsize;	}	return (TRUE);}DECLAREwriteFunc(writeBufferToSeparateStrips){	uint32 rowsize = imagewidth * spp;	uint32 rowsperstrip;	tdata_t obuf = _TIFFmalloc(TIFFStripSize(out));	tstrip_t strip = 0;	tsample_t s;	if (obuf == NULL)		return (0);	(void) TIFFGetFieldDefaulted(out, TIFFTAG_ROWSPERSTRIP, &rowsperstrip);	for (s = 0; s < spp; s++) {		uint32 row;		for (row = 0; row < imagelength; row += rowsperstrip) {			uint32 nrows = (row+rowsperstrip > imagelength) ?			    imagelength-row : rowsperstrip;			tsize_t stripsize = TIFFVStripSize(out, nrows);			cpContigBufToSeparateBuf(			    obuf, (uint8*) buf + row*rowsize + s, 			    nrows, imagewidth, 0, 0, spp, 1);			if (TIFFWriteEncodedStrip(out, strip++, obuf, stripsize) < 0) {				_TIFFfree(obuf);				return (FALSE);			}		}	}	_TIFFfree(obuf);	return (TRUE);}DECLAREwriteFunc(writeBufferToContigTiles){	uint32 imagew = TIFFScanlineSize(out);	uint32 tilew  = TIFFTileRowSize(out);	int iskew = imagew - tilew;	tdata_t obuf = _TIFFmalloc(TIFFTileSize(out));	uint8* bufp = (uint8*) buf;	uint32 tl, tw;	uint32 row;	(void) spp;	if (obuf == NULL)		return (FALSE);	(void) TIFFGetField(out, TIFFTAG_TILELENGTH, &tl);	(void) TIFFGetField(out, TIFFTAG_TILEWIDTH, &tw);	for (row = 0; row < imagelength; row += tilelength) {		uint32 nrow = (row+tl > imagelength) ? imagelength-row : tl;		uint32 colb = 0;		uint32 col;		for (col = 0; col < imagewidth; col += tw) {			/*			 * Tile is clipped horizontally.  Calculate			 * visible portion and skewing factors.			 */			if (colb + tilew > imagew) {				uint32 width = imagew - colb;				int oskew = tilew - width;				cpStripToTile(obuf, bufp + colb, nrow, width,				    oskew, oskew + iskew);			} else				cpStripToTile(obuf, bufp + colb, nrow, tilew,				    0, iskew);			if (TIFFWriteTile(out, obuf, col, row, 0, 0) < 0) {				_TIFFfree(obuf);				return (FALSE);			}			colb += tilew;		}		bufp += nrow * imagew;	}	_TIFFfree(obuf);	return (TRUE);}DECLAREwriteFunc(writeBufferToSeparateTiles){	uint32 imagew = TIFFScanlineSize(out);	tsize_t tilew  = TIFFTileRowSize(out);	uint32 iimagew = TIFFRasterScanlineSize(out);	int iskew = iimagew - tilew*spp;	tdata_t obuf = _TIFFmalloc(TIFFTileSize(out));	uint8* bufp = (uint8*) buf;	uint32 tl, tw;	uint32 row;        uint16 bps, bytes_per_sample;	if (obuf == NULL)		return (FALSE);	(void) TIFFGetField(out, TIFFTAG_TILELENGTH, &tl);	(void) TIFFGetField(out, TIFFTAG_TILEWIDTH, &tw);	(void) TIFFGetField(out, TIFFTAG_BITSPERSAMPLE, &bps);        assert( bps % 8 == 0 );        bytes_per_sample = bps/8;        	for (row = 0; row < imagelength; row += tl) {		uint32 nrow = (row+tl > imagelength) ? imagelength-row : tl;		uint32 colb = 0;		uint32 col;		for (col = 0; col < imagewidth; col += tw) {			tsample_t s;			for (s = 0; s < spp; s++) {				/*				 * Tile is clipped horizontally.  Calculate				 * visible portion and skewing factors.				 */				if (colb + tilew > imagew) {					uint32 width = (imagew - colb);					int oskew = tilew - width;					cpContigBufToSeparateBuf(obuf,					    bufp + (colb*spp) + s,					    nrow, width/bytes_per_sample,					    oskew, (oskew*spp)+iskew, spp,                                            bytes_per_sample);				} else					cpContigBufToSeparateBuf(obuf,					    bufp + (colb*spp) + s,					    nrow, tilewidth,					    0, iskew, spp,                                            bytes_per_sample);				if (TIFFWriteTile(out, obuf, col, row, 0, s) < 0) {					_TIFFfree(obuf);					return (FALSE);				}			}			colb += tilew;		}		bufp += nrow * iimagew;	}	_TIFFfree(obuf);	return (TRUE);}/* * Contig strips -> contig tiles. */DECLAREcpFunc(cpContigStrips2ContigTiles){	return cpImage(in, out,	    readContigStripsIntoBuffer,	    writeBufferToContigTiles,	    imagelength, imagewidth, spp);}/* * Contig strips -> separate tiles. */DECLAREcpFunc(cpContigStrips2SeparateTiles){	return cpImage(in, out,	    readContigStripsIntoBuffer,	    writeBufferToSeparateTiles,	    imagelength, imagewidth, spp);}/* * Separate strips -> contig tiles. */DECLAREcpFunc(cpSeparateStrips2ContigTiles){	return cpImage(in, out,	    readSeparateStripsIntoBuffer,	    writeBufferToContigTiles,	    imagelength, imagewidth, spp);}/* * Separate strips -> separate tiles. */DECLAREcpFunc(cpSeparateStrips2SeparateTiles){	return cpImage(in, out,	    readSeparateStripsIntoBuffer,	    writeBufferToSeparateTiles,	    imagelength, imagewidth, spp);}/* * Contig strips -> contig tiles. */DECLAREcpFunc(cpContigTiles2ContigTiles){	return cpImage(in, out,	    readContigTilesIntoBuffer,	    writeBufferToContigTiles,	    imagelength, imagewidth, spp);}/* * Contig tiles -> separate tiles. */DECLAREcpFunc(cpContigTiles2SeparateTiles){	return cpImage(in, out,	    readContigTilesIntoBuffer,	    writeBufferToSeparateTiles,	    imagelength, imagewidth, spp);}/* * Separate tiles -> contig tiles. */DECLAREcpFunc(cpSeparateTiles2ContigTiles){	return cpImage(in, out,	    readSeparateTilesIntoBuffer,	    writeBufferToContigTiles,	    imagelength, imagewidth, spp);}/* * Separate tiles -> separate tiles (tile dimension change). */DECLAREcpFunc(cpSeparateTiles2SeparateTiles){	return cpImage(in, out,	    readSeparateTilesIntoBuffer,	    writeBufferToSeparateTiles,	    imagelength, imagewidth, spp);}/* * Contig tiles -> contig tiles (tile dimension change). */DECLAREcpFunc(cpContigTiles2ContigStrips){	return cpImage(in, out,	    readContigTilesIntoBuffer,	    writeBufferToContigStrips,	    imagelength, imagewidth, spp);}/* * Contig tiles -> separate strips. */DECLAREcpFunc(cpContigTiles2SeparateStrips){	return cpImage(in, out,	    readContigTilesIntoBuffer,	    writeBufferToSeparateStrips,	    imagelength, imagewidth, spp);}/* * Separate tiles -> contig strips. */DECLAREcpFunc(cpSeparateTiles2ContigStrips){	return cpImage(in, out,	    readSeparateTilesIntoBuffer,	    writeBufferToContigStrips,	    imagelength, imagewidth, spp);}/* * Separate tiles -> separate strips. */DECLAREcpFunc(cpSeparateTiles2SeparateStrips){	return cpImage(in, out,	    readSeparateTilesIntoBuffer,	    writeBufferToSeparateStrips,	    imagelength, imagewidth, spp);}/* * Select the appropriate copy function to use. */static copyFuncpickCopyFunc(TIFF* in, TIFF* out, uint16 bitspersample, uint16 samplesperpixel){	uint16 shortv;	uint32 w, l, tw, tl;	int bychunk;	(void) TIFFGetField(in, TIFFTAG_PLANARCONFIG, &shortv);	if (shortv != config && bitspersample != 8 && samplesperpixel > 1) {		fprintf(stderr,"%s: Cannot handle different planar configuration w/ bits/sample != 8\n",		    TIFFFileName(in));		return (NULL);	}	TIFFGetField(in, TIFFTAG_IMAGEWIDTH, &w);	TIFFGetField(in, TIFFTAG_IMAGELENGTH, &l);        if (!(TIFFIsTiled(out) || TIFFIsTiled(in))) {	    uint32 irps = (uint32) -1L;	    TIFFGetField(in, TIFFTAG_ROWSPERSTRIP, &irps);            /* if biased, force decoded copying to allow image subtraction */ 	    bychunk = !bias && (rowsperstrip == irps);	}else{  /* either in or out is tiled */            if (bias) {                  fprintf(stderr,"%s: Cannot handle tiled configuration w/bias image\n",                  TIFFFileName(in));                  return (NULL);            }	    if (TIFFIsTiled(out)) {		if (!TIFFGetField(in, TIFFTAG_TILEWIDTH, &tw))			tw = w;		if (!TIFFGetField(in, TIFFTAG_TILELENGTH, &tl))			tl = l;		bychunk = (tw == tilewidth && tl == tilelength);	    } else {  /* out's not, so in must be tiled */		TIFFGetField(in, TIFFTAG_TILEWIDTH, &tw);		TIFFGetField(in, TIFFTAG_TILELENGTH, &tl);		bychunk = (tw == w && tl == rowsperstrip);            }	}#define	T 1#define	F 0#define pack(a,b,c,d,e)	((long)(((a)<<11)|((b)<<3)|((c)<<2)|((d)<<1)|(e)))	switch(pack(shortv,config,TIFFIsTiled(in),TIFFIsTiled(out),bychunk)) {/* Strips -> Tiles */	case pack(PLANARCONFIG_CONTIG,   PLANARCONFIG_CONTIG,   F,T,F):	case pack(PLANARCONFIG_CONTIG,   PLANARCONFIG_CONTIG,   F,T,T):		return cpContigStrips2ContigTiles;	case pack(PLANARCONFIG_CONTIG,   PLANARCONFIG_SEPARATE, F,T,F):	case pack(PLANARCONFIG_CONTIG,   PLANARCONFIG_SEPARATE, F,T,T):		return cpContigStrips2SeparateTiles;        case pack(PLANARCONFIG_SEPARATE, PLANARCONFIG_CONTIG,   F,T,F):        case pack(PLANARCONFIG_SEPARATE, PLANARCONFIG_CONTIG,   F,T,T):		return cpSeparateStrips2ContigTiles;	case pack(PLANARCONFIG_SEPARATE, PLANARCONFIG_SEPARATE, F,T,F):	case pack(PLANARCONFIG_SEPARATE, PLANARCONFIG_SEPARATE, F,T,T):		return cpSeparateStrips2SeparateTiles;/* Tiles -> Tiles */	case pack(PLANARCONFIG_CONTIG,   PLANARCONFIG_CONTIG,   T,T,F):	case pack(PLANARCONFIG_CONTIG,   PLANARCONFIG_CONTIG,   T,T,T):		return cpContigTiles2ContigTiles;	case pack(PLANARCONFIG_CONTIG,   PLANARCONFIG_SEPARATE, T,T,F):	case pack(PLANARCONFIG_CONTIG,   PLANARCONFIG_SEPARATE, T,T,T):		return cpContigTiles2SeparateTiles;        case pack(PLANARCONFIG_SEPARATE, PLANARCONFIG_CONTIG,   T,T,F):        case pack(PLANARCONFIG_SEPARATE, PLANARCONFIG_CONTIG,   T,T,T):		return cpSeparateTiles2ContigTiles;	case pack(PLANARCONFIG_SEPARATE, PLANARCONFIG_SEPARATE, T,T,F):	case pack(PLANARCONFIG_SEPARATE, PLANARCONFIG_SEPARATE, T,T,T):		return cpSeparateTiles2SeparateTiles;/* Tiles -> Strips */	case pack(PLANARCONFIG_CONTIG,   PLANARCONFIG_CONTIG,   T,F,F):	case pack(PLANARCONFIG_CONTIG,   PLANARCONFIG_CONTIG,   T,F,T):		return cpContigTiles2ContigStrips;	case pack(PLANARCONFIG_CONTIG,   PLANARCONFIG_SEPARATE, T,F,F):	case pack(PLANARCONFIG_CONTIG,   PLANARCONFIG_SEPARATE, T,F,T):		return cpContigTiles2SeparateStrips;        case pack(PLANARCONFIG_SEPARATE, PLANARCONFIG_CONTIG,   T,F,F):        case pack(PLANARCONFIG_SEPARATE, PLANARCONFIG_CONTIG,   T,F,T):		return cpSeparateTiles2ContigStrips;	case pack(PLANARCONFIG_SEPARATE, PLANARCONFIG_SEPARATE, T,F,F):	case pack(PLANARCONFIG_SEPARATE, PLANARCONFIG_SEPARATE, T,F,T):		return cpSeparateTiles2SeparateStrips;/* Strips -> Strips */	case pack(PLANARCONFIG_CONTIG,   PLANARCONFIG_CONTIG,   F,F,F):		return bias ? cpBiasedContig2Contig : cpContig2ContigByRow;	case pack(PLANARCONFIG_CONTIG,   PLANARCONFIG_CONTIG,   F,F,T):		return cpDecodedStrips;	case pack(PLANARCONFIG_CONTIG, PLANARCONFIG_SEPARATE,   F,F,F):	case pack(PLANARCONFIG_CONTIG, PLANARCONFIG_SEPARATE,   F,F,T):		return cpContig2SeparateByRow;	case pack(PLANARCONFIG_SEPARATE, PLANARCONFIG_CONTIG,   F,F,F):	case pack(PLANARCONFIG_SEPARATE, PLANARCONFIG_CONTIG,   F,F,T):		return cpSeparate2ContigByRow;	case pack(PLANARCONFIG_SEPARATE, PLANARCONFIG_SEPARATE, F,F,F):	case pack(PLANARCONFIG_SEPARATE, PLANARCONFIG_SEPARATE, F,F,T):		return cpSeparate2SeparateByRow;	}#undef pack#undef F#undef T	fprintf(stderr, "tiffcp: %s: Don't know how to copy/convert image.\n",	    TIFFFileName(in));	return (NULL);}

⌨️ 快捷键说明

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