Fix Targa file loading.
authorCarl Hetherington <cth@carlh.net>
Mon, 8 Sep 2014 21:09:15 +0000 (22:09 +0100)
committerCarl Hetherington <cth@carlh.net>
Mon, 8 Sep 2014 21:09:15 +0000 (22:09 +0100)
ChangeLog
src/lib/image_proxy.cc

index 7cf91220546ac74ae8824eca0b0c93daa2756d65..284e5b3bd831d48e035ce49c2efbc8ef15b4f8ba 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2014-09-08  Carl Hetherington  <cth@carlh.net>
+
+       * Fix failure to load Targa files.
+
 2014-09-07  Carl Hetherington  <cth@carlh.net>
 
        * Version 1.73.3 released.
index 7c212be045a166704852e78f4453f1af06175a74..3aba6cf7c93fffd8fbb6c61cba85ad7e408c1988 100644 (file)
@@ -121,10 +121,30 @@ MagickImageProxy::image () const
        LOG_TIMING ("[%1] MagickImageProxy begins decode and convert of %2 bytes", boost::this_thread::get_id(), _blob.length());
 
        Magick::Image* magick_image = 0;
+       string error;
        try {
                magick_image = new Magick::Image (_blob);
-       } catch (...) {
-               throw DecodeError (_("Could not decode image file"));
+       } catch (Magick::Exception& e) {
+               error = e.what ();
+       }
+
+       if (!magick_image) {
+               /* ImageMagick cannot auto-detect Targa files, it seems, so try here with an
+                  explicit format.  I can't find it documented that passing a (0, 0) geometry
+                  is allowed, but it seems to work.
+               */
+               try {
+                       magick_image = new Magick::Image (_blob, Magick::Geometry (0, 0), "TGA");
+               } catch (...) {
+
+               }
+       }
+
+       if (!magick_image) {
+               /* If we failed both an auto-detect and a forced-Targa we give the error from
+                  the auto-detect.
+               */
+               throw DecodeError (String::compose (_("Could not decode image file (%1)"), error));
        }
 
        LOG_TIMING ("[%1] MagickImageProxy decode finished", boost::this_thread::get_id ());