Received: from mailgate001.isp.belgacom.be (mailgate001.isp.belgacom.be [195.238.6.86])
	by maildelivery001.isp.belgacom.be (Postfix) with ESMTP id 7436D5A8002
	for <joris.at.lebbeke@skynet.be>; Tue, 14 Aug 2007 00:59:41 +0200 (CEST)
Received: from r153.dmsolutions.ca (HELO duke.maptools.org) ([209.217.116.153])
  by in.mx.skynet.be with ESMTP; 14 Aug 2007 00:59:41 +0200
Received: from duke.maptools.org (duke.maptools.org [127.0.0.1])
	by duke.maptools.org (8.12.11/8.12.10) with ESMTP id l7DMjGSc028998;
	Mon, 13 Aug 2007 18:46:15 -0400
Received: from an-out-0708.google.com (an-out-0708.google.com [209.85.132.246])
	by duke.maptools.org (8.12.11/8.12.10) with ESMTP id l7DMhlXb028981
	for <tiff@lists.maptools.org>; Mon, 13 Aug 2007 18:43:48 -0400
Received: by an-out-0708.google.com with SMTP id d31so278279and
	for <tiff@lists.maptools.org>; Mon, 13 Aug 2007 15:43:46 -0700 (PDT)
DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta;
	h=domainkey-signature:received:received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition;
	b=Y6fi/WyrApuuV0kCJFRg+zwPwkeC5YcXnPYFbDMJn4wo1D7YuIVZGzY/5D3LCHOXTCWSydMFpAQY3V/np30NMVG5a1LTFWd6oQDPHX7VDcMIBUzQyH2uOm852kbAmUqfykDOVunoam+8dcrL+NG80hV6vvkybmDe+hlR6Vkjqhc=
DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta;
	h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition;
	b=e6Zq3OVMa8J6MaBclwomItsDMYmeekOyCH2FuYgtl108WFMYX5Q/Gw8LXteoSzlGs/zFJel92LtBubJ39Ko8WGLWSh3TjnTuu/5TbxLDboMr4F9d1N8OtB1fSpZfGNCdIaXbI+xWXuuUAqAbnBhxiGdOJI+bcMlE69kAJ7uNrhE=
Received: by 10.100.127.1 with SMTP id z1mr358023anc.1187045026726;
	Mon, 13 Aug 2007 15:43:46 -0700 (PDT)
Received: by 10.100.151.10 with HTTP; Mon, 13 Aug 2007 15:43:46 -0700 (PDT)
Message-ID: <949801310708131543w12db69fek383c7c8c6a0efe55@mail.gmail.com>
Date: Mon, 13 Aug 2007 18:43:46 -0400
From: "Christian Henning" <chhenning@gmail.com>
To: "libtiff - Liste" <tiff@lists.maptools.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Subject: [Tiff] 16-bit palette image
X-BeenThere: tiff@lists.maptools.org
X-Mailman-Version: 2.1.4
Precedence: list
List-Id: TIFF and libtiff discussion <tiff.lists.maptools.org>
List-Unsubscribe: <http://lists.maptools.org/mailman/listinfo/tiff>,
	<mailto:tiff-request@lists.maptools.org?subject=unsubscribe>
List-Archive: <http://lists.maptools.org/mailman/private/tiff>
List-Post: <mailto:tiff@lists.maptools.org>
List-Help: <mailto:tiff-request@lists.maptools.org?subject=help>
List-Subscribe: <http://lists.maptools.org/mailman/listinfo/tiff>,
	<mailto:tiff-request@lists.maptools.org?subject=subscribe>
Sender: tiff-bounces@lists.maptools.org
Errors-To: tiff-bounces@lists.maptools.org
X-UIDL: 000000000023ceae.00002715
X-MSP-STORE: Tue, 14 Aug 2007 00:59:41 --21-99
Status:   

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
_______________________________________________
Tiff mailing list: Tiff@lists.maptools.org
http://lists.maptools.org/mailman/listinfo/tiff
http://www.remotesensing.org/libtiff/
