AWARE [SYSTEMS] Imaging expertise for the Delphi developer
AWare Systems, Imaging expertise for the Delphi developer, Home TIFF and LibTiff Mailing List Archive

LibTiff Mailing List

TIFF and LibTiff Mailing List Archive
May 2007

Previous Thread
Next Thread

Previous by Thread
Next by Thread

Previous by Date
Next by Date

Contact

The TIFF Mailing List Homepage
This list is run by Frank Warmerdam
Archive maintained by AWare Systems



Valid HTML 4.01!



Thread

2007.05.31 21:02 "question about TIFFWriteScanline", by <sbheinri@ncsu.edu>
2007.06.01 09:05 "Re: question about TIFFWriteScanline", by Joris Van Damme

2007.05.31 21:02 "question about TIFFWriteScanline", by <sbheinri@ncsu.edu>

I have verified that the format of data in the buffer returned by
TIFFReadScanline in contiguous mode follows this format:

image(row, col, chan) =  buffer[col*channels + chan];

However, when I use the same format with TIFFWriteScanline to write to a
file, it mixes up all the channels and I get garbage:

buffer[col*channels + chan] = image(row, col, chan);

As a simple test I have just read in/write out each scanline.  In comes an
image, out comes a garbled image.  So how do I need to reorganize the
buffer for writing?

TIFF *tif = TIFFOpen(fname, opt);
uint32 rows;
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &rows);

uint32 cols;
TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &cols);

uint16 _channels;
TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &channels);

uint16 config;
TIFFGetField(tif, TIFFTAG_PLANARCONFIG, &config);

if (config == PLANARCONFIG_CONTIG)
	//scanline organized as: R G B R G B ...
{
	tdata_t buf = _TIFFmalloc(TIFFScanlineSize(tif));
	uint8 *b = (uint8*)buf;

	/*open a file for writing*/
	TIFF *out = TIFFOpen("TEST.tif", "w");
	TIFFSetField(out, TIFFTAG_IMAGEWIDTH, (uint32)cols);
	TIFFSetField(out, TIFFTAG_IMAGELENGTH, (uint32)rows);
	TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, (uint16)channels);
	TIFFSetField(out, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);

	/*read/write scanlines back out to new file*/
	for(unsigned int row = 0; row < rows; row++)
	{
		TIFFReadScanline(tif, buf, row);
		TIFFWriteScanline(out, buf, row);
	}

	_TIFFfree(buf);
	TIFFClose(out);
}

TIFFClose(tif);