Bug 130798

Summary: digikam editor saves some jpeg's 30% smaller than original - even with jpeg compression option set at 100
Product: [Applications] digikam Reporter: J. Westveer <jwest>
Component: Plugin-DImg-JPEGAssignee: Digikam Developers <digikam-bugs-null>
Status: RESOLVED FIXED    
Severity: normal    
Priority: NOR    
Version: 0.9.0   
Target Milestone: ---   
Platform: unspecified   
OS: Linux   
Latest Commit: Version Fixed In: 0.9.0
Sentry Crash Report:

Description J. Westveer 2006-07-14 04:54:23 UTC
Version:           0.9.0-svn (using KDE 3.5.3, Debian Package 4:3.5.3-1 (testing/unstable))
Compiler:          Target: i486-linux-gnu
OS:                Linux (i686) release 2.6.15-1-686-smp

If you open a jpeg in Digikam Image Editor, make no changes, and than save
to a different file name, the resultant jpeg is ~30% smaller than the original.

original test image (~6.2M) :
 http://www.melaque.com/tree.jpg

as saved by Digikam (~4.8M) :
 http://www.melaque.com/tree-digikam.jpg

I do have the settings option for jpeg compression set at 100.

This is unfortunate for those with shinny-new-high-megapixel-cameras.
I would have not thought that the image would be compressed.  As a test
I mailed the image to a friend with some-photo-ms-thingie, and he reports
that saving the photo with no changes results in an ~6M file.  I read somewhere
that libjpeg will set a 'default' horizontal and vertical sampling factor if
they are not set, but I have not found the spot in the Digicam code
where that might be used.  

Thanks for considering this...
Comment 1 caulier.gilles 2006-07-14 10:09:06 UTC
The digiKam JPEG interface is here :

http://websvn.kde.org/trunk/extragear/graphics/digikam/libs/dimg/loaders/jpegloader.cpp?rev=557529&view=auto

Note: i'm using always JPEG compression ratio to 100 here, and i can't reproduce this problem.

Gilles Caulier
Comment 2 J. Westveer 2006-07-15 17:34:17 UTC
Sorry, I still think something is wrong.

I am new to hacking Digikam, and I have been poke-ing around the 
digikam/libs/dimg/loaders/jpegloader.cpp file, trying to figure out
how it works.  If I take line :
jpeg_set_quality(&cinfo, quality, true);
and change it to :
jpeg_set_quality(&cinfo, 100, true);

I get two different size output images when using the same file.
I am still trying to figure out how quality is set from the slider ;-/

Thanks for the responce.

jjw
Comment 3 caulier.gilles 2006-07-15 21:59:05 UTC
SVN commit 562793 by cgilles:

digikam from trunk : add libJPEG quality compression value debug message.

CCBUGS: 130798

 M  +2 -0      jpegloader.cpp  


--- trunk/extragear/graphics/digikam/libs/dimg/loaders/jpegloader.cpp #562792:562793
@@ -484,6 +484,8 @@
     jpeg_set_quality(&cinfo, quality, true);
     jpeg_start_compress(&cinfo, true);
 
+    kdDebug() << "Using LibJPEG quality compression value: " << quality << endl;
+
     if (observer)
         observer->progressInfo(m_image, 0.1);
 
Comment 4 caulier.gilles 2006-07-15 22:03:04 UTC
The slider -> libjpeg quality conversion rule is explained to editorwindow.cpp::line 726 :

http://websvn.kde.org/trunk/extragear/graphics/digikam/utilities/imageeditor/editor/editorwindow.cpp?rev=561766&view=auto

Gilles Caulier
Comment 5 caulier.gilles 2006-07-15 22:07:22 UTC
Right, there is a small approximate error to compute libjpeg quality value using slider setting. In fact, when slider = 100, libjpeg quality = 99 !

Gilles Caulier
Comment 6 J. Westveer 2006-07-15 22:22:24 UTC
Humm, If the slider returns a value from 0-100, and libjpeg
only accepts 25-100, would it not be simpler to just get the
sliders value, and if less than 25, just set quality to 25.

I love the integer logic though.  It made my brain hurt, and
I had to go take a nap.......

Ciao,

Jim Westveer jwest@debian.org 
------------------------------------------------------------ 
I wish there was a button on my computer for intelligence. There's a button called `brightness', but it doesn't work. ------------------------------------------------------------ 
Comment 7 caulier.gilles 2006-07-16 09:21:30 UTC
SVN commit 562897 by cgilles:

digiKam from trunk: fix libjpeg quality value used to save a new file if setup jpeg compression ratio is 100.
BUG: 130798


 M  +5 -2      NEWS  
 M  +0 -2      TODO  
 M  +2 -2      utilities/imageeditor/editor/editorwindow.cpp  


--- trunk/extragear/graphics/digikam/NEWS #562896:562897
@@ -131,7 +131,8 @@
 068 ==> 121367 : Add properties tab to digiKam and (especially) Image Editor.
 069 ==> 125926 : Directories with a '#' in their name are not properly detected when created outside digikam.
 070 ==> 125733 : Enabling 'Always apply ICM profiles' can lead to suprising results.
-071 ==> 126326 : camera download: auto-rotated images loose EXIF info when 'No EXIF information found.' is written to console.
+071 ==> 126326 : camera download: auto-rotated images loose EXIF info when 'No EXIF information found.' 
+                 is written to console.
 072 ==> 121242 : mimelnk/x-image-raw.desktop conflicts with kdegraphics-3.5.x.
 073 ==> 127374 : unsharp mask: max. radius way too small.
 074 ==> 116485 : Mimimize button missing on "Compaq Flash Reader" camera window.
@@ -167,6 +168,8 @@
 104 ==> 130381 : Automatic colorbalance and camera color balance checkboxes swapped.
 105 ==> 117248 : Opening default app when camera inserted return KIOExec error.
 106 ==> 130883 : Overexposure indicator in color management is saved as part of the picture
-107 ==> 
+107 ==> 130798 : Editor saves some jpeg's 30% smaller than original,
+                 even with jpeg compression option set at 100.
+108 ==> 
 
 ----------------------------------------------------------------------------------------------------
--- trunk/extragear/graphics/digikam/TODO #562896:562897
@@ -34,8 +34,6 @@
 ==> 111446 : Image Editor   : bad behaviour when out of disk space
 ==> 128104 : Image Editor   : digiKam Crash when browsing photos in Image Editor
 ==> 130525 : Image Editor   : Saving large (>5M) jpg's result in corrupt file
-==> 130798 : Image Editor   : Editor saves some jpeg's 30% smaller than original,
-                              even with jpeg compression option set at 100.
 
 ==> 127583 : Main interface : keywords, copyright, photographer info not saved to IPTC
 ==> 127179 : Main interface : thumbnails does not adhere to the Rotate Images setting in Configure digiKam
--- trunk/extragear/graphics/digikam/utilities/imageeditor/editor/editorwindow.cpp #562896:562897
@@ -724,8 +724,8 @@
     config->setGroup("ImageViewer Settings");
 
     // JPEG quality slider settings : 0 - 100 ==> libjpeg settings : 25 - 100.
-    m_IOFileSettings->JPEGCompression  = (int)((75.0/99.0)*(float)config->readNumEntry("JPEGCompression", 75)
-                                               + 25.0 - (75.0/99.0));
+    m_IOFileSettings->JPEGCompression  = (int)((75.0/100.0)*(float)config->readNumEntry("JPEGCompression", 75)
+                                               + 26.0 - (75.0/100.0));
 
     // PNG compression slider settings : 1 - 9 ==> libpng settings : 100 - 1.
     m_IOFileSettings->PNGCompression   = (int)(((1.0-100.0)/8.0)*(float)config->readNumEntry("PNGCompression", 1)