Created
August 18, 2015 13:37
-
-
Save su-v/a5a9ad4f2f3dd1e47aac to your computer and use it in GitHub Desktop.
workaround for compiler (?) bug with clang from Xcode 4.6.3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=== modified file 'src/extension/internal/image-resolution.cpp' | |
--- src/extension/internal/image-resolution.cpp 2014-10-01 07:24:30 +0000 | |
+++ src/extension/internal/image-resolution.cpp 2015-08-18 13:33:27 +0000 | |
@@ -118,17 +118,35 @@ | |
png_read_info(png_ptr, info_ptr); | |
png_uint_32 res_x, res_y; | |
+#ifdef PNG_INCH_CONVERSIONS_SUPPORTED | |
+ g_message("readpng - PNG_INCH_CONVERSIONS_SUPPORTED"); | |
+ res_x = png_get_x_pixels_per_inch(png_ptr, info_ptr); | |
+ res_y = png_get_y_pixels_per_inch(png_ptr, info_ptr); | |
+ if (res_x != 0 && res_y != 0) { | |
+ ok_ = true; | |
+ x_ = res_x * 1.0; // FIXME: implicit conversion of png_uint_32 to double ok? | |
+ y_ = res_y * 1.0; // FIXME: implicit conversion of png_uint_32 to double ok? | |
+ } | |
+#else | |
+ g_message("readpng - PNG_RESOLUTION_METER"); | |
int unit_type; | |
- png_get_pHYs(png_ptr, info_ptr, &res_x, &res_y, &unit_type); | |
- | |
- png_destroy_read_struct(&png_ptr, &info_ptr, 0); | |
- fclose(fp); | |
- | |
+ png_get_pHYs(png_ptr, info_ptr, &res_x, &res_y, &unit_type); // FIXME: fails to return expected values with clang (based on LLVM 3.2svn) from Xcode 4.6.3 (OS X 10.7.5) | |
if (unit_type == PNG_RESOLUTION_METER) { | |
ok_ = true; | |
x_ = res_x * 2.54 / 100; | |
y_ = res_y * 2.54 / 100; | |
} | |
+#endif | |
+ | |
+ png_destroy_read_struct(&png_ptr, &info_ptr, 0); | |
+ fclose(fp); | |
+ | |
+ if (ok_) { | |
+ g_message("readpng - xdpi: %f", x_); | |
+ g_message("readpng - ydpi: %f", y_); | |
+ } else { | |
+ g_message("readpng - FAILED"); | |
+ } | |
} | |
#else | |
@@ -354,6 +372,8 @@ | |
return; | |
} | |
+ g_message("readmagick - image.[xy]Resolution"); | |
+ | |
std::string const type = image.magick(); | |
x_ = image.xResolution(); | |
y_ = image.yResolution(); | |
@@ -367,6 +387,13 @@ | |
if (x_ != 0 && y_ != 0) { | |
ok_ = true; | |
} | |
+ | |
+ if (ok_) { | |
+ g_message("readmagick - xdpi: %f", x_); | |
+ g_message("readmagick - ydpi: %f", y_); | |
+ } else { | |
+ g_message("readmagick - FAILED"); | |
+ } | |
} | |
#else | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Summary
diff above allows to work around failure in Inkscape 0.91 and trunk to import certain kinds of PNG images / paste from clipboard correctly (so far only known to affect builds on OS X 10.7.5 after upgrading Xcode from 4.3.2 to 4.6.3).
Known trigger
affected PNG images have
Units: Undefined
(in the output of ImageMagick'sidentify -verbose
command).Known limitation
The current patch is only in effect with more recent versions of libpng which support PNG_INCH_CONVERSIONS (
png_get_x_pixels_per_inch()
,png_get_y_pixels_per_inch()
).Possibly cause
Underlying issue seems most likely a compiler bug (clang from Xcode 4.6.3), triggered e.g. with
-02
,-O1
, but apparently not with debug build-O0 -g
. Might be related to libpng's typedefpng_uint_32
(likely specific to OS/platform).Affected compiler (Xcode 4.6.3, OS X 10.7.5):
$ clang --version Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn) Target: x86_64-apple-darwin11.4.2 Thread model: posix
Observed symptoms
with current code (0.91, 0.91+devel):
res_x
(--> computed width is incorrect)res_y
(--> computed height is close to zero)unit_type
(1
(same as PNG_RESOLUTION_METER) despite unspecified units)Example image (PNG)