
Thread
2004.12.24 01:29 "[Tiff] negative values written in a "uint", 16-bit mode tiff", by S Smith
I want to write a greyscale TIFF with 16 bits per pixel. My code is below. The pixels should be labeled 0-65535, but at halfway through the image, they turn negative and count back down towards zero. I've set the image to be uint, 16 bit. What am I missing here? Thanks in advance! -s
CString foo;
tdata_t buf;
TIFF* tif;
foo.Format("c:\\testimage.tif");
tif = TIFFOpen(foo, "w");
TIFFSetField(tif, TIFFTAG_PLANARCONFIG,
PLANARCONFIG_CONTIG);
TIFFSetField(tif, TIFFTAG_IMAGELENGTH, 256);
TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, 256);
TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 16);
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 1);
TIFFSetField(tif, TIFFTAG_SAMPLEFORMAT,
SAMPLEFORMAT_UINT);
buf = _TIFFmalloc(512);
for (int linenum = 0; linenum < 256; linenum++) {
for (int col=0;col<256;col++) {
((unsigned short *) buf)[col]=(unsigned short)(col + (256*linenum));
}
TIFFWriteScanline(tif, buf, linenum);
}
TIFFClose(tif);