| AWARE [SYSTEMS] | Imaging expertise for the Delphi developer | |||||||
![]() |
TIFF and LibTiff Mailing List Archive | |||||||
LibTiff Mailing List
TIFF and LibTiff Mailing List Archive Contact
The TIFF Mailing List Homepage |
Thread2007.08.13 22:43 "16-bit palette image", by Christian HenningHi 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
|
|||||||