=== modified file 'src/extension/internal/image-resolution.cpp' --- src/extension/internal/image-resolution.cpp 2014-02-07 20:08:10 +0000 +++ src/extension/internal/image-resolution.cpp 2014-04-07 21:22:14 +0000 @@ -34,6 +34,27 @@ #include #endif +#define IMAGE_RESOLUTION_DEBUG +#ifdef IMAGE_RESOLUTION_DEBUG +# define debug(f, a...) { \ + g_print("%s(%d) %s: ", __FILE__,__LINE__,__FUNCTION__); \ + g_print(f, ## a); \ + g_print("\n"); \ +} +# define debug_res(x, y) { \ + g_print("x_: % f\n", x); \ + g_print("y_: % f\n", y); \ +} +# define debug_res_e(x, y) { \ + g_print("x_: % .8e\n", x); \ + g_print("y_: % .8e\n", y); \ +} +#else +# define debug(f, a...) /* */ +# define debug_res(x, y) /* */ +# define debug_res_e(x, y) /* */ +#endif + namespace Inkscape { namespace Extension { namespace Internal { @@ -54,6 +75,9 @@ if (!ok_) { readmagick(fn); } + if (!ok_) { + debug("Failed to retrieve image size based on image resolution."); + } } bool ImageResolution::ok() const { @@ -129,6 +153,15 @@ x_ = res_x * 2.54 / 100; y_ = res_y * 2.54 / 100; } + + debug("readpng"); + debug_res(x_, y_); + + if (ok_) { + debug("success"); + } else { + debug("failure"); + } } #else @@ -206,6 +239,15 @@ ok_ = true; } exif_data_free(ed); + + debug("readexif"); + debug_res(x_, y_); + + if (ok_) { + debug("success"); + } else { + debug("failure"); + } } #else @@ -331,6 +373,15 @@ } jpeg_destroy_decompress(&cinfo); fclose(ifd); + + debug("readjfif"); + debug_res(x_, y_); + + if (ok_) { + debug("success"); + } else { + debug("failure"); + } } #else @@ -353,18 +404,22 @@ g_warning("ImageResolution::readmagick: Unknown error"); return; } - Magick::Geometry geo = image.density(); - std::string type = image.magick(); - - if (type == "PNG") { // PNG only supports pixelspercentimeter - x_ = Inkscape::Util::Quantity::convert((double)geo.width(), "in", "cm"); - y_ = Inkscape::Util::Quantity::convert((double)geo.height(), "in", "cm"); + + x_ = image.xResolution(); + y_ = image.yResolution(); + + if (x_ != 0 && y_ != 0) { + ok_ = true; + } + + debug("ImageMagick fallback"); + debug_res(x_, y_); + + if (ok_) { + debug("success"); } else { - x_ = (double)geo.width(); - y_ = (double)geo.height(); + debug("failure"); } - - ok_ = true; } #else