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

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
nand
Posts: 9
Joined: 2015-02-23T13:07:43-07:00
Authentication code: 6789

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

Post 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

snibgo
Posts: 12682
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post 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.
snibgo's IM pages: im.snibgo.com

User avatar
magick
Site Admin
Posts: 11158
Joined: 2003-05-31T11:32:55-07:00

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

Post by magick »

The conversion succeeds with the current ImageMagick release, ImageMagick 6.9.0-10.

nand
Posts: 9
Joined: 2015-02-23T13:07:43-07:00
Authentication code: 6789

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

Post 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

nand
Posts: 9
Joined: 2015-02-23T13:07:43-07:00
Authentication code: 6789

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

Post 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.

snibgo
Posts: 12682
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post 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.
snibgo's IM pages: im.snibgo.com

nand
Posts: 9
Joined: 2015-02-23T13:07:43-07:00
Authentication code: 6789

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

Post by nand »

I can confirm that the official Gentoo package works fine when set to q32 instead of q64, as well.

User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

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

Post 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

nand
Posts: 9
Joined: 2015-02-23T13:07:43-07:00
Authentication code: 6789

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

Post 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?

User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

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

Post by glennrp »

I meant Q32.

nand
Posts: 9
Joined: 2015-02-23T13:07:43-07:00
Authentication code: 6789

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

Post 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.

User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

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

Post by glennrp »

Sorry, I was looking at the wrong output. Both of my Q32 outputs are OK.

User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

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

Post by glennrp »

This bug is fixed in the upcoming IM-6.9.1-0, now available in the SVN repository, revision 18221.

Post Reply