Ticket #1948 (closed defect: fixed)

Opened 4 years ago

Last modified 4 years ago

Update of LZW w/predictor compressed TIFF files leads to corrupted file

Reported by: rouault Owned by: warmerdam
Priority: normal Milestone: 1.4.4
Component: GDAL_Raster Version: svn-trunk
Severity: normal Keywords: lzw libtiff gtiff predictor
Cc:

Description

GDAL utilities that tries to update some LZW compressed TIFF gives wrong results. For example, nearblack on  http://veimages.gsfc.nasa.gov//2433/land_shallow_topo_2048.tif will give an image looking like a 'TV without signal' (quoting Mateusz) (This bug report primarly comes from #1936)

However, this is not reproductible on all LZW compressed TIFF. If you do :

gdal_translate -co "COMPRESS=LZW" land_shallow_topo_2048.tif tmp.tif
apps/nearblack tmp.tif

tmp.tif looks good.

But if you do :

gdal_translate -co "COMPRESS=LZW" -co "PREDICTOR=2" land_shallow_topo_2048.tif tmp.tif
apps/nearblack tmp.tif

the result is bad. (In that case, the translated tmp.tif has roughly the same size as land_shallow_topo_2048.tif since land_shallow_topo_2048.tif has PREDICTOR=2 tag)

But tmp.tif after translating is sigificantly larger than land_shallow_topo_2048.tif

(This is maybe related to #1758 as well.)

Change History

Changed 4 years ago by rouault

  • keywords lzw tiff added
  • version changed from unspecified to svn-trunk
  • component changed from default to GDAL_Raster

Changed 4 years ago by rouault

-co "PREDICTOR=2" seems to be the cause.

Similar problem can also be reproduced with  http://dl.maptools.org/dl/gdal/data/nitf/cadrg/001zc013.on1

gdal_translate -co "COMPRESS=LZW" -co "PREDICTOR=2" 001zc013.on1 001zc013.tif
nearblack 001zc013.tif

gives wrong result, whereas samething without PREDICTOR=2 works fine.

Changed 4 years ago by rouault

The same applies for COMPRESS=DEFLATE and PREDICTOR=2

Changed 4 years ago by warmerdam

  • keywords libtiff added
  • status changed from new to assigned

I have established that the libtiff predictor state is not being initialize and used for encoding when the same session uses decoding with LZW (and possibly other compression types).

Still digging in libtiff to see what the fix will be.

Changed 4 years ago by warmerdam

  • summary changed from Update of LZW compressed TIFF files leads to corrupted file to Update of LZW w/predictor compressed TIFF files leads to corrupted file

I have committed fixes to libtiff CVS head (libtiff4) to correct this. Modified tif_predict.{c,h}, as well as tif_lzw.c and tif_zip.c. Changes downstreamed into GDAL trunk as r12608.

I have also confirmed this bug occurs in 1.4 branch with libtiff3.9. I'd like to fix it there too.

Changed 4 years ago by warmerdam

I have add modified autotest/gcore/tiff_write.py (test 7) to use PREDICTOR=2 to verify this fix is in place in trunk (r12609).

Changed 4 years ago by warmerdam

Created #1965, and somewhat related bug related to predictors.

Changed 4 years ago by warmerdam

The tif_write_7 test was still failing. It turns out that the pcode function was getting mixed up between encode and decode cases. Fixed in upstream libtiff by splitting pcode into encodepcode and decodepcode functions similarly to how the previous change was made. Test script now passing.

Still need to port into libtiff 3.9, and pull the fix downstream into GDAL.

Changed 4 years ago by warmerdam

  • keywords gtiff predictor added; tiff removed
  • status changed from assigned to closed
  • resolution set to fixed
  • milestone set to 1.4.4

I have backported this into libtiff 3.9 branch, and imported that branch into GDAL's 1.4 branch. I believe our predictor problems are corrected now.

Note: See TracTickets for help on using tickets.