[Digikam-devel] [digikam] [Bug 320107] Flip/Mirror operation doesn't flip/mirror the entirety of the picture (there is a strip left unmirrored) [patch]

Gilles Caulier caulier.gilles at gmail.com
Wed Jun 24 16:02:52 BST 2015


https://bugs.kde.org/show_bug.cgi?id=320107

Gilles Caulier <caulier.gilles at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
      Latest Commit|                            |http://commits.kde.org/digi
                   |                            |kam/ca2f3ae955ebe88fbc4d734
                   |                            |f5249e29fbb645269
   Version Fixed In|                            |4.12.0
         Resolution|---                         |FIXED

--- Comment #37 from Gilles Caulier <caulier.gilles at gmail.com> ---
Git commit ca2f3ae955ebe88fbc4d734f5249e29fbb645269 by Gilles Caulier.
Committed on 24/06/2015 at 14:59.
Pushed by cgilles into branch 'master'.

add perfect JPEG transform checks to prevent broken image rotation/flip when
image size is not compatible with IMCU properties.
This will only work with libjpeg >= 8.0
BUGS: 320107
FIXED-IN: 4.12.0

M  +2    -1    NEWS
M  +27   -6    libs/jpegutils/jpegutils.cpp
M  +1    -1    libs/jpegutils/jpegutils.h

http://commits.kde.org/digikam/ca2f3ae955ebe88fbc4d734f5249e29fbb645269

diff --git a/NEWS b/NEWS
index a825b82..e31b848 100644
--- a/NEWS
+++ b/NEWS
@@ -30,4 +30,5 @@ BUGFIXES FROM KDE BUGZILLA
(https://www.digikam.org/changelog):
 023 ==> 345990 - 4.9.0 import from external card reader crashe.
 024 ==> 339615 - Crashed after selecting Import (sd card reader).
 025 ==> 277242 - MYSQL : using different databases for images metadata and
thumbnail cache is broken.
-026 ==>
+026 ==> 320107 - Flip/Mirror operation doesn't flip/mirror the entirety of the
picture (there is a strip left unmirrored) [patch].
+027 ==>
diff --git a/libs/jpegutils/jpegutils.cpp b/libs/jpegutils/jpegutils.cpp
index 6fd8375..1a150f9 100644
--- a/libs/jpegutils/jpegutils.cpp
+++ b/libs/jpegutils/jpegutils.cpp
@@ -7,7 +7,7 @@
  * Description : perform lossless rotation/flip to JPEG file
  *
  * Copyright (C) 2004-2005 by Renchi Raju <renchi dot raju at gmail dot com>
- * Copyright (C) 2006-2014 by Gilles Caulier <caulier dot gilles at gmail dot
com>
+ * Copyright (C) 2006-2015 by Gilles Caulier <caulier dot gilles at gmail dot
com>
  * Copyright (C) 2006-2012 by Marcel Wiesweg <marcel dot wiesweg at gmx dot
de>
  *
  * Parts of the loading code is taken from qjpeghandler.cpp, copyright
follows:
@@ -329,7 +329,8 @@ bool loadJPEGScaled(QImage& image, const QString& path, int
maximumSize)
 }

 JpegRotator::JpegRotator(const QString& file)
-    : m_file(file), m_destFile(file)
+    : m_file(file),
+      m_destFile(file)
 {
     m_metadata.load(file);
     m_orientation  = m_metadata.getImageOrientation();
@@ -412,9 +413,29 @@ bool JpegRotator::exifTransform(const RotationMatrix&
matrix)

         if (!performJpegTransform(actions[i], src, tempFile))
         {
-            ::unlink(QFile::encodeName(tempFile));
-            kError() << "JPEG transform of" << src << "failed";
-            return false;
+            kError() << "JPEG lossless transform failed for" << src;
+
+            // See bug 320107 : if lossless transform cannot be achieve, do
lossy transform.
+            DImg srcImg;
+
+            kError() << "Trying lossy transform for " << src;
+
+            if (!srcImg.load(src))
+            {
+                ::unlink(QFile::encodeName(tempFile));
+                return false;
+            }
+
+            if (actions[i] != KExiv2Iface::RotationMatrix::NoTransformation)
+            {
+                srcImg.transform(actions[i]);
+            }
+
+            if (!srcImg.save(tempFile, DImg::JPEG))
+            {
+                ::unlink(QFile::encodeName(tempFile));
+                return false;
+            }
         }

         if (i+1 != actions.size())
@@ -531,7 +552,7 @@ bool JpegRotator::performJpegTransform(TransformAction
action, const QString& sr

 #if (JPEG_LIB_VERSION >= 80)
     // we need to initialize a few more parameters, see bug 274947
-    transformoption.perfect         = false;
+    transformoption.perfect         = true;             // See bug 320107 : we
need perfect transform here.
     transformoption.crop            = false;
 #endif

diff --git a/libs/jpegutils/jpegutils.h b/libs/jpegutils/jpegutils.h
index bf2e3de..ef74676 100644
--- a/libs/jpegutils/jpegutils.h
+++ b/libs/jpegutils/jpegutils.h
@@ -7,7 +7,7 @@
  * Description : perform lossless rotation/flip to JPEG file
  *
  * Copyright (C) 2004-2005 by Renchi Raju <renchi dot raju at gmail dot com>
- * Copyright (C) 2006-2014 by Gilles Caulier <caulier dot gilles at gmail dot
com>
+ * Copyright (C) 2006-2015 by Gilles Caulier <caulier dot gilles at gmail dot
com>
  * Copyright (C) 2006-2012 by Marcel Wiesweg <marcel dot wiesweg at gmx dot
de>
  *
  * This program is free software; you can redistribute it

-- 
You are receiving this mail because:
You are the assignee for the bug.



More information about the Digikam-devel mailing list