2007.08.07 14:41 "[Tiff] Indexed Images", by Christian Henning

2007.08.16 07:15 "Re: [Tiff] 16-bit palette image", by Reinhard Mayr aka Czerwinski

Hi Christian,

since there was no answer, yet, I try to give one as a non-expert...

As far as I figured out, bits_per_sample may only assume the values 4 and 8 - at least these values occur in the specs 6.0. Basically, I see no *technical* reason why it can not be 16 bit, however, this seems to be outside of the specification and therefore the reason why readers fail with this situation.

Please correct if this is not true!

Hth,

Cz.

-------- Original-Nachricht --------
Datum: Mon, 13 Aug 2007 18:43:46 -0400
Von: "Christian Henning" <chhenning@gmail.com>
An: "libtiff - Liste" <tiff@lists.maptools.org>
Betreff: [Tiff] 16-bit palette image

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,

--

Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!

Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer