Bug 125779

Summary: use deflate compression for tiffs
Product: [Applications] digikam Reporter: Dennis Gnad <bluedrago>
Component: Plugin-DImg-TIFFAssignee: Digikam Developers <digikam-bugs-null>
Status: RESOLVED FIXED    
Severity: wishlist    
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: unspecified   
OS: Linux   
Latest Commit: Version Fixed In: 0.9.0
Sentry Crash Report:
Attachments: identify-log of tiff file with selected "deflate" as compression in gimp
identify-log of a digikam compressed tiff file with deflate compression

Description Dennis Gnad 2006-04-18 01:38:12 UTC
Version:           0.9.0-svn 2006-04-18 (using KDE KDE 3.5.2)

I don't know what kind of compression digikam uses for tiffs. But if you recompress them with the "deflate" method they get even smaller (2/3 to 3/4 the size).
So maybe rather use deflate if there aren't some specific problems with it?
Comment 1 caulier.gilles 2006-04-18 09:31:20 UTC
yes adobe Deflate compression method is used in digiKam. Please, read the digiKam handbook or check widgets tool tips from setup dialog if you want more informations...

Gilles
Comment 2 caulier.gilles 2006-04-18 09:32:45 UTC
I toogle this file like Invalid.

Gilles
Comment 3 Dennis Gnad 2006-04-18 10:48:45 UTC
Is the deflate method surely used? I checked the box "Compress TIFF Files".
To test it I saved my image as 8bit and opened it in gimp, then saved it again with deflate in gimp. So it should be the same size, but then it is around 2/3 or 3/4 the size.
Does gimp discard some information which is some megabytes large (would be 5MB in my example - I can't believe that!)
The Exif "Image Informations" which digikam shows, shows "Rows per Strip" "1" for the digikam-saved image and "64" for the one from gimp. "Compression" and the other stuff which could mean something, is the same.
Comment 4 Dennis Gnad 2006-04-18 18:36:33 UTC
Info about file sizes of one example 8bit file of me:

digikam no compression: 17.2 MB
digikam compressed: 15.1 MB

gimp no compression: 17.2 MB
gimp deflate compression: 10.0 MB
gimp lzw compression: 11.1MB

What is digikam doing wrong?(or correct?)
Comment 5 Dennis Gnad 2006-05-03 21:52:44 UTC
Created attachment 15896 [details]
identify-log of tiff file with selected "deflate" as compression in gimp

This is a log of what "identify -verbose" shows of the tiff file with selected
"deflate" as compression in gimp, which is just 10mb larges.. it shows
"Compression: Zip" like the deflate compressed from digikam also does.. but
digikams one is 15.1mb large... next attachment will be the "identify
-verbose"-log of the digikam deflate compressed file which is 15.1mb large
Comment 6 Dennis Gnad 2006-05-03 21:54:02 UTC
Created attachment 15897 [details]
identify-log of a digikam compressed tiff file with deflate compression
Comment 7 caulier.gilles 2006-05-10 01:31:02 UTC
SVN commit 539215 by cgilles:

digikam from trunk : DImg TIFF image loader : force to use ZLib max compression level when a new image is saved to disk using Deflate compression.

CCMAIL: digikam-devel@kde.org
CCBUGS: 125779

 M  +3 -0      tiffloader.cpp  


--- trunk/extragear/graphics/digikam/libs/dimg/loaders/tiffloader.cpp #539214:539215
@@ -399,7 +399,10 @@
     bool compress = compressAttr.isValid() ? compressAttr.toBool() : false;
     
     if (compress)
+    {
         TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_DEFLATE);
+        TIFFSetField(tif, TIFFTAG_ZIPQUALITY, 9);
+    }
     else
         TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
 
Comment 8 caulier.gilles 2006-05-26 17:19:50 UTC
Dennis,

My last fix in svn have really improved the compression result. Look below :

[gilles@portable-gc METADATA]$ ls -l _dsc*
-rw-rw-r--  1 gilles gilles  1750127 fév 23 16:52 _dsc0034.jpg
-rw-------  1 gilles gilles 11704190 mai 26 17:12 _dsc0034.tif
-rw-------  1 gilles gilles 18205760 mai 26 17:10 _dsc0034.tiff

_dsc0034.jpg  is the original file in 8 bits color depth (JPEG)
_dsc0034.tif  is a 8 bits tiff file using deflate compression
_dsc0034.tiff is a 8 bits tiff file without compression.

The original image is here :

http://digikam3rdparty.free.fr/TEST_IMAGES/METADATA/_dsc0034.jpg

Here i'm using libtiff 3.6.1. I haven't tested with last libtiff available (3.8.2)

The difference with 16 bits color depth tiff image is less impressive. I don't know if it's a problem from libtiff.

I all case, i think you can compare now result with Gimp-svn.

Please give me a feedback.

Gilles
Comment 9 Dennis Gnad 2006-05-27 11:56:22 UTC
Not with Gimp-svn but I compared with Gimp 2.3.7 ..

8bit:
Gimp-deflate: 9,3mb
Digikam-deflate: 13,6mb

something is still strange, and there is still the difference:

rows per strip:
gimp: 64
digikam: 1

compression:
gimp: (32946)
digikam: (8)
Comment 10 caulier.gilles 2006-05-29 16:34:46 UTC
SVN commit 546226 by cgilles:

digikam from trunk : DImg::TIffLoader : optimize again Deflate compression ratio like gimp tiff coder done.
The Predictor tiff tag must be set to '2' for the best results. Look below :

#ls -l _*
-rw-------  1 gilles gilles 11523474 mai 29 16:17 _dsc0034 (deflate alone).tif
-rw-------  1 gilles gilles  7553642 mai 29 16:14 _dsc0034 (deflate + horizontal predictor).tif
-rw-------  1 gilles gilles 18253872 mai 29 16:17 _dsc0034 (without compression).tif
-rw-r--r--  1 gilles gilles  1750127 mar 24 15:18 _dsc0034.jpg
-rw-r--r--  1 gilles gilles 10471516 mar 24 15:18 _dsc0034.png

_dsc0034.jpg is the original file loaded in editor and saved like tiff files following different settings.

For more details about predictor values, look here :http://www.awaresystems.be/imaging/tiff/tifftags/predictor.html

Note : the implementation is compatible with libtiff 3.6.x and 3.8.x

BUG:125779
CCMAIL: digikam-devel@kde.org

 M  +4 -0      tiffloader.cpp  


--- trunk/extragear/graphics/digikam/libs/dimg/loaders/tiffloader.cpp #546225:546226
@@ -399,6 +399,10 @@
     {
         TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_ADOBE_DEFLATE);
         TIFFSetField(tif, TIFFTAG_ZIPQUALITY,  9);
+        // NOTE : this tag values aren't defined in libtiff 3.6.1. '2' is PREDICTOR_HORIZONTAL.
+        //        This value is used to optimize Deflate compression ratio. See this url for more details:
+        //        http://www.awaresystems.be/imaging/tiff/tifftags/predictor.html
+        TIFFSetField(tif, TIFFTAG_PREDICTOR,   2); 
     }
     else
         TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_NONE);