From 5a75b3f90a53941f04f32dc8f22c25f2f855ad2e Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Sun, 12 May 2013 14:49:26 +0200 Subject: Fix for Bug #1085949 (Use ImageMagick fallback when importing bitmap resolution). Fixed bugs: - https://launchpad.net/bugs/1085949 (bzr r12330) --- src/extension/internal/image-resolution.cpp | 33 +++++++++++++++++++++++++++++ src/extension/internal/image-resolution.h | 23 ++++++++++---------- 2 files changed, 45 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/extension/internal/image-resolution.cpp b/src/extension/internal/image-resolution.cpp index 51a3fe9c1..3c254a59c 100644 --- a/src/extension/internal/image-resolution.cpp +++ b/src/extension/internal/image-resolution.cpp @@ -21,6 +21,9 @@ #ifdef HAVE_JPEG #define IR_TRY_JFIF 1 #endif +#ifdef WITH_IMAGE_MAGICK +#include +#endif namespace Inkscape { namespace Extension { @@ -39,6 +42,9 @@ ImageResolution::ImageResolution(char const *fn) { if (!ok_) { readexif(fn); } + if (!ok_) { + readmagick(fn); + } } bool ImageResolution::ok() const { @@ -328,6 +334,33 @@ void ImageResolution::readjfif(char const *) { #endif +#ifdef WITH_IMAGE_MAGICK +void ImageResolution::readmagick(char const *fn) { + Magick::Image image; + try { + image.read(fn); + } catch (...) {} + Magick::Geometry geo = image.density(); + std::string type = image.magick(); + + if (type == "PNG") { // PNG only supports pixelspercentimeter + x_ = (double)geo.width() * 2.54; + y_ = (double)geo.height() * 2.54; + } else { + x_ = (double)geo.width(); + y_ = (double)geo.height(); + } + ok_ = true; +} + +#else + +// Dummy implementation +void ImageResolution::readmagick(char const *) { +} + +#endif /* WITH_IMAGE_MAGICK */ + } } } diff --git a/src/extension/internal/image-resolution.h b/src/extension/internal/image-resolution.h index c42260f7d..6c4928a35 100644 --- a/src/extension/internal/image-resolution.h +++ b/src/extension/internal/image-resolution.h @@ -18,19 +18,20 @@ namespace Internal { class ImageResolution { public: - ImageResolution(char const *fn); - bool ok() const; - double x() const; - double y() const; + ImageResolution(char const *fn); + bool ok() const; + double x() const; + double y() const; private: - bool ok_; - double x_; - double y_; + bool ok_; + double x_; + double y_; private: - void readpng(char const *fn); - void readexif(char const *fn); - void readexiv(char const *fn); - void readjfif(char const *fn); + void readpng(char const *fn); + void readexif(char const *fn); + void readexiv(char const *fn); + void readjfif(char const *fn); + void readmagick(char const *fn); }; } -- cgit v1.2.3