Merge master.
[dcpomatic.git] / src / lib / magick_image_proxy.cc
index 0908ed9213e23b17c6b763c9a307c58a6fb5b0f9..4adf8047f6ae8af8200375b21e79f5cd88ef461a 100644 (file)
@@ -30,6 +30,7 @@
 
 #define LOG_TIMING(...) _log->microsecond_log (String::compose (__VA_ARGS__), Log::TYPE_TIMING);
 
+using std::string;
 using boost::shared_ptr;
 
 MagickImageProxy::MagickImageProxy (boost::filesystem::path path, shared_ptr<Log> log)
@@ -74,10 +75,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));
        }
 
        dcp::Size size (magick_image->columns(), magick_image->rows());