- 2007.08.07 03:46 "[Tiff] bilevel image scrambling when size not divisible by 8", by Lee Cooper
- 2007.08.07 14:48 "Re: [Tiff] Indexed Images", by Toby Thain
- 2007.08.07 15:23 "Re: [Tiff] Indexed Images", by Frank Warmerdam
- 2007.08.13 22:43 "[Tiff] 16-bit palette image", by Christian Henning
2007.08.13 22:43 "[Tiff] 16-bit palette image", by Christian Henning
Hi there, can somebody tell what am I doing wrong when creating a 16-bit palette image. For some reason none picture viewer can read the file.
Please consider the following code creating a dummy tiff file.
int main()
{
tsize_t width = 100;
tsize_t height = 100;
tsize_t bits_per_sample = 16;
tsize_t samples_per_pixel = 1;
tsize_t palette_size = 65536;
TIFF* file = TIFFOpen( "palette.tif", "w" );
TIFFSetField( file, TIFFTAG_IMAGEWIDTH , width );
TIFFSetField( file, TIFFTAG_IMAGELENGTH , height );
TIFFSetField( file, TIFFTAG_BITSPERSAMPLE , bits_per_sample );
TIFFSetField( file, TIFFTAG_SAMPLESPERPIXEL, samples_per_pixel );
TIFFSetField( file, TIFFTAG_ROWSPERSTRIP , height );
TIFFSetField( file, TIFFTAG_PHOTOMETRIC , PHOTOMETRIC_PALETTE );
TIFFSetField( file, TIFFTAG_COMPRESSION , COMPRESSION_LZW );
TIFFSetField( file, TIFFTAG_PLANARCONFIG , PLANARCONFIG_CONTIG );
std::vector< short > palette( palette_size ); std::fill( palette.begin(), palette.end(), 0 );
TIFFSetField( file
, TIFFTAG_COLORMAP
, &palette.front()
, &palette.front()
, &palette.front() );
std::vector<short> buffer( width );
std::fill( buffer.begin(), buffer.end(), 0 );
for( int row = 0; row < height; ++row )
{
int res = TIFFWriteScanline( file
,
&buffer.front()
,
row
,
0 );
assert( res != -1 );
}
TIFFClose( file );
}
Thanks ahead,
Christian