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
August 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.08.13 22:43 "16-bit palette image", by Christian Henning
2007.08.16 07:15 "Re: 16-bit palette image", by Reinhard Mayr Aka Czerwinski

2007.08.13 22:43 "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