Page 1 of 1

ImageMagick can't open some PNG files, mostly 1-bit grayscale stuff

Posted: 2015-03-14T08:11:51-07:00
by nand
Example image:
Image

Trying to read/convert this with imagemagick fails, eg.

Code: Select all

$ wget https://i.imgur.com/WyBCPty.png
...
$ convert WyBCPty.png test.ppm
$ hexdump -C test.ppm 
00000000  50 36 0a 38 37 20 38 37  0a 32 35 35 0a 00 00 00  |P6.87 87.255....|
00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000058c0
As you can see, the resulting PPM file is completely blank. Converting it to JPEG or another format does not help, nor does converting it to another PNG. Furthermore, trying to use applications like zbarimg, which rely on ImageMagick to read files, fails (it also reads completely blank images).

For comparison, the tool pngtopnm works fine here:

Code: Select all

$ pngtopnm WyBCPty.png > test.ppm
$ hexdump -C test.ppm | head
00000000  50 34 0a 38 37 20 38 37  0a 00 00 00 00 00 00 00  |P4.87 87........|
00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000080  00 00 00 00 00 00 00 00  00 00 00 00 00 00 0f ff  |................|
00000090  ff 81 c7 e3 ff ff e0 00  00 0f ff ff 81 c7 e3 ff  |................|
000000a0  ff e0 00 00 0f ff ff 81  c7 e3 ff ff e0 00 00 0e  |................|
000000b0  00 03 81 ff 03 80 00 e0  00 00 0e 00 03 81 ff 03  |................|
000000c0  80 00 e0 00 00 0e 00 03  81 ff 03 80 00 e0 00 00  |................|
000000d0  0e 3f e3 8f c7 e3 8f f8  e0 00 00 0e 3f e3 8f c7  |.?..........?...|
000000e0  e3 8f f8 e0 00 00 0e 3f  e3 8f c7 e3 8f f8 e0 00  |.......?........|
$
And converting this resulting PPM file to a PNG or JPEG again using ImageMagick also works. Therefore, I suspect that the issue is in the PNG decoder.

Code: Select all

$ convert --version
Version: ImageMagick 6.9.0-3 Q64 x86_64 2015-02-14 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2015 ImageMagick Studio LLC
Features: DPC HDRI Modules OpenCL
Delegates (built-in): bzlib cairo fontconfig freetype jbig jng jp2 jpeg lcms lqr ltdl lzma openexr pangocairo png rsvg tiff webp x xml zlib
$ eix -I imagemagick
[I] media-gfx/imagemagick
     Available versions:  6.9.0.3(0/6.9.0.3)^u {X autotrace bzip2 corefonts cxx djvu fftw fontconfig fpx graphviz hdri jbig jpeg jpeg2k lcms lqr lzma opencl openexr openmp pango perl png postscript q32 q64 q8 raw static-libs svg test tiff truetype webp wmf xml zlib}
     Installed versions:  6.9.0.3^u(10:37:06 2015-02-14)(X bzip2 cxx fontconfig hdri jbig jpeg jpeg2k lcms lqr lzma opencl openexr openmp pango perl png q64 raw svg tiff truetype webp xml zlib -autotrace -corefonts -djvu -fftw -fpx -graphviz -postscript -q32 -q8 -static-libs -test -wmf)
     Homepage:            http://www.imagemagick.org/
     Description:         A collection of tools and libraries for many image formats

Re: ImageMagick can't open some PNG files, mostly 1-bit grayscale stuff

Posted: 2015-03-14T08:41:21-07:00
by snibgo
On a slightly older version, v6.9.0-0 on Windows 8.1, that image identifies and converts with no problem.

Recent versions of IM have been somewhat volatile. You might find that upgrading to the current version solves the problem.

Re: ImageMagick can't open some PNG files, mostly 1-bit grayscale stuff

Posted: 2015-03-14T08:44:27-07:00
by magick
The conversion succeeds with the current ImageMagick release, ImageMagick 6.9.0-10.

Re: ImageMagick can't open some PNG files, mostly 1-bit grayscale stuff

Posted: 2015-03-14T13:44:22-07:00
by nand
I've reproduced the bug on the current version of imagemagick, with the same results.

Code: Select all

$ convert --version
Version: ImageMagick 6.9.0-10 Q64 x86_64 2015-03-14 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2015 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: DPC HDRI Modules OpenCL
Delegates (built-in): bzlib cairo fontconfig freetype jbig jng jp2 jpeg lcms lqr ltdl lzma openexr pangocairo png rsvg tiff webp x xml zlib
Note: I have ImageMagick built with clang, not GCC. Thinking that this might have something to do with it, I've tried re-building with GCC. Unfortunately, the results are the same.

Code: Select all

$ convert --version
Version: ImageMagick 6.9.0-10 Q64 x86_64 2015-03-14 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2015 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: DPC HDRI Modules OpenCL OpenMP
Delegates (built-in): bzlib cairo fontconfig freetype jbig jng jp2 jpeg lcms lqr ltdl lzma openexr pangocairo png rsvg tiff webp x xml zlib

Re: ImageMagick can't open some PNG files, mostly 1-bit grayscale stuff

Posted: 2015-03-14T14:06:10-07:00
by nand
Updates:

It seems to be due to the configuration flags Gentoo was using. I've built directly from the source and it works. Then I built a second time with this configure line:

Code: Select all

./configure --prefix=/usr --build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu --mandir=/usr/share/man --infodir=/usr/share/info --datadir=/usr/share --sysconfdir=/etc --localstatedir=/var/lib --disable-dependency-tracking --disable-silent-rules --libdir=/usr/lib64 --disable-static --enable-hdri --enable-opencl --with-threads --with-modules --with-quantum-depth=64 --with-magick-plus-plus --with-perl --with-perl-options=INSTALLDIRS=vendor --with-gs-font-dir=/usr/share/fonts/urw-fonts --with-bzlib --with-x --with-zlib --without-autotrace --without-dps --without-djvu --with-dejavu-font-dir=/usr/share/fonts/dejavu --without-fftw --without-fpx --with-fontconfig --with-freetype --without-gslib --without-gvc --with-jbig --with-jpeg --with-openjp2 --without-lcms --with-lcms2 --with-lqr --with-lzma --with-openexr --with-pango --with-png --with-rsvg --with-tiff --with-webp --without-windows-font-dir --without-wmf --with-xml --disable-openmp --with-gcc-arch=no-automagic
And that triggers the issue.

Re: ImageMagick can't open some PNG files, mostly 1-bit grayscale stuff

Posted: 2015-03-14T14:15:49-07:00
by snibgo
I missed the fact that you were using Q64. (Coo!)

With my Cygwin build of Q64, v6.9.0-0 ...

Code: Select all

%IM64f%convert WyBCPty.png x.png
... gives an entirely black output. Other Quantums (8, 16, 32) do not show the problem.

Re: ImageMagick can't open some PNG files, mostly 1-bit grayscale stuff

Posted: 2015-03-14T14:27:51-07:00
by nand
I can confirm that the official Gentoo package works fine when set to q32 instead of q64, as well.

Re: ImageMagick can't open some PNG files, mostly 1-bit grayscale stuff

Posted: 2015-03-14T16:56:53-07:00
by glennrp
Probably due to this in coders/png.c (fortunately only appears once):

Code: Select all

#if (MAGICKCORE_QUANTUM_DEPTH == 16) || (MAGICKCORE_QUANTUM_DEPTH == 32)
   do something
#else
   assume quantum_depth is 8; do something else
#endif
Should be easy to fix.

EDIT: Maybe not. I changed that test to

Code: Select all

#if (MAGICKCORE_QUANTUM_DEPTH >= 16)
and rebuilt ImageMagick. Still all black. I rebuilt ImageMagick again using the "-m64" compiler option. Still the converted image is all black.

EDIT2: I also tried converting to png64:file.png but it's still all black.

EDIT3: A Q32 build produces the correct result when the output is png64:file.png but an all-black
image when the output file is just q32.png

Re: ImageMagick can't open some PNG files, mostly 1-bit grayscale stuff

Posted: 2015-03-15T16:14:36-07:00
by nand
EDIT3: A Q32 build produces the correct result when the output is png64:file.png but an all-black
image when the output file is just q32.png
Do you mean Q64?

Re: ImageMagick can't open some PNG files, mostly 1-bit grayscale stuff

Posted: 2015-03-15T19:27:50-07:00
by glennrp
I meant Q32.

Re: ImageMagick can't open some PNG files, mostly 1-bit grayscale stuff

Posted: 2015-03-16T02:50:45-07:00
by nand
In that case, I'm getting different results:

Code: Select all

$ convert -version
Version: ImageMagick 6.9.0-10 Q32 x86_64 2015-03-14 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2015 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: DPC HDRI Modules OpenCL
Delegates (built-in): bzlib cairo fontconfig freetype jbig jng jp2 jpeg lcms lqr ltdl lzma openexr pangocairo png rsvg tiff webp x xml zlib

$ convert WyBCPty.png q32.png
$ convert WyBCPty.png png64:q64.png
$ sxiv q32.png q64.png
Both look fine, although q32.png is 1-bit grayscale and q64.png is 16-bit RGBA.

Re: ImageMagick can't open some PNG files, mostly 1-bit grayscale stuff

Posted: 2015-03-16T05:05:07-07:00
by glennrp
Sorry, I was looking at the wrong output. Both of my Q32 outputs are OK.

Re: ImageMagick can't open some PNG files, mostly 1-bit grayscale stuff

Posted: 2015-03-16T07:25:25-07:00
by glennrp
This bug is fixed in the upcoming IM-6.9.1-0, now available in the SVN repository, revision 18221.