X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fmagick_image_proxy.cc;h=e5265187f57e3a67458d72a3a9f66e0133366f4b;hb=13083177a3be4c6bb5fa5dfca6d8f9d7785c73e4;hp=0908ed9213e23b17c6b763c9a307c58a6fb5b0f9;hpb=fc56dc97103d00437843a31e1ef0c4915900ad1a;p=dcpomatic.git diff --git a/src/lib/magick_image_proxy.cc b/src/lib/magick_image_proxy.cc index 0908ed921..e5265187f 100644 --- a/src/lib/magick_image_proxy.cc +++ b/src/lib/magick_image_proxy.cc @@ -30,7 +30,10 @@ #define LOG_TIMING(...) _log->microsecond_log (String::compose (__VA_ARGS__), Log::TYPE_TIMING); +using std::string; +using std::cout; using boost::shared_ptr; +using boost::dynamic_pointer_cast; MagickImageProxy::MagickImageProxy (boost::filesystem::path path, shared_ptr log) : ImageProxy (log) @@ -74,10 +77,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()); @@ -96,7 +119,7 @@ MagickImageProxy::image () const delete magick_image; LOG_TIMING ("[%1] MagickImageProxy completes decode and convert of %2 bytes", boost::this_thread::get_id(), _blob.length()); - + return _image; } @@ -112,3 +135,18 @@ MagickImageProxy::send_binary (shared_ptr socket) const socket->write (_blob.length ()); socket->write ((uint8_t *) _blob.data (), _blob.length ()); } + +bool +MagickImageProxy::same (shared_ptr other) const +{ + shared_ptr mp = dynamic_pointer_cast (other); + if (!mp) { + return false; + } + + if (_blob.length() != mp->_blob.length()) { + return false; + } + + return memcmp (_blob.data(), mp->_blob.data(), _blob.length()) == 0; +}