2020.04.18 12:15 "[Tiff] Updating zlib library", by Vincent Ripoll

2020.04.18 12:15 "[Tiff] Updating zlib library", by Vincent Ripoll

Even though the DEFLATE compression algorithm is only defined in the appendix https://www.alternatiff.com/resources/TIFFphotoshop.pdf, it is well supported and allows better compression for archiving purposes.

The current implementation used by LibTiff is, according to http://www.simplesystems.org/libtiff/internals.html, the libz library written by Jean-loup Gailly and Mark Adler.

New implementations achievingbetter compression ratio exist: https://github.com/amadvance/advancecomp/tree/master/libdeflate or https://github.com/google/zopfli to name a few. It would be worth using those.

I wrote a POC that takes a sample tiff file compressed with the DEFLATE algorithm provided by LibTiff (through ImageMagick -quality 90 that is compression level 9), extracts the content of the first "strip", decompresses it, recompresses it with a higher compression level (using the first c# lib I could find, that is https://www.nuget.org/packages/DotNetZip -- zopfli should compress even better), and updates the strip with a smaller content without altering the image.

Compressed data: 120,824 bytes
Uncompressed data: 587,568 bytes
Recompressed data: 111, 396 bytes

That's 9428 bytes saved on the first strip. Since there are 728 strips, that's potentially a lot of bytes saved. I did the same with the first 600 rows:

Compressed size: 59,255,517
Uncompressed size: 352,540,800
Recompressed size: 53,162,232

The TIFF file:

LZW: 160,091,372 bytes / Endianess: LSB
ZIP using Photoshop: 59,463,688 bytes / Endianess: LSB
ZIP using ImageMagick: 61,148,606 / Endianess: MSB
ZIP using ImageMagick -quality 90: 59,535,052 / Endianess: MSB