2011.04.15 11:50 "[Tiff] File size too large when using custom tiff tags", by

2011.04.15 13:04 "Re: [Tiff] File size too large when using custom tiff tags", by Frank Warmerdam

On 11-04-15 07:50 AM, Urbach, Marcel [Rohmann GmbH] wrote:

Hey guys,

I’m using Libtiff to store a array of long values (32 bit) in a custom tiff tag. The type of the tag is TIFF_LONG. Everything works pretty well, except that the file size is too large by factor 2.

For example, there is an array of 361000 long values. The file size should be ~ 1.44 MB (size of data ) + 531 KB ( size of the picture) = 1.971 MB.

But the size is 3.4 MB. How could that be? Any Ideas?

voidTiffHandler::AddData( int directory, const std::vector<long>& data
)

{

      assert( m_tiff );

      assert( data.size() );

      TIFFSetTagExtender( TagExtender );

      TIFFSetErrorHandler( TIFFError );

      TIFFSetDirectory( m_tiff, directory );

      TIFFSetField( m_tiff, TIFFTAG_LAYER0, data.size(), &data[0] );

      TIFFRewriteDirectory( m_tiff );

Marcel,

Generally speaking TIFFRewriteDirectory() will cause the TIFF directory to be written again at the end of the file, and the space used by a previous write of the directory is lost track of. To avoid this either ensure all tags are set in advance of the first directory write or if working on an existing file copy the contents to a new file with the new tag values and replace the old file with the new.

Generally libtiff was not setup for "update in place" and particularly in the directory handling it suffers for my having grafted it on after the fact.

Best regards,
--

---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam@pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent