2008.11.26 15:15 "[Tiff] TIFFWriteEncodedStrip LZW compression failing for certain input", by Paavo

2008.11.27 13:23 "Re: [Tiff] TIFFWriteEncodedStrip LZW compression failing for certain input", by Frank Warmerdam

In short, my problem is that TIFFWriteEncodedStrip in LZW mode is producing corrupt output for some image content.

I have found out it was my mistake. I read the strip back in by TIFFReadRawStrip(), but did call the wrong function to determine the initial buffer size (TIFFStripSize() instead of TIFFRawStripSize()). Thus, if the compressed data was larger than the original, I failed to capture the extra bytes.

The question remains why the image is not compressable by LZW, is it some fundamental problem with the algorithm? For example, gzip is able to compress the uncompressed TIFF file with the same image 128 times!

Paavo,

You may want to set TIFFTAG_PREDICTOR to PREDICTOR_HORIZONTAL. This changes the pixel values to be compressed to deltas from the previous pixel and may make your image much more compressible. It is generally a good idea for image data.

Note that gzip does not use LZW, it uses Deflate (also available in many builds of libtiff). It is also possible that differencing is automatically applied by gzip - I'm not that familiar with the details of how these things work.

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