Page 1 of 1

7.0.2-9 - stream does not work for PNG

Posted: 2016-08-22T10:32:11-07:00
by rydberg
Hello,

I'm trying to use ImageMagick to write a program that would make a thumbnail of a PNG file in the environment with limited memory. Since convert uses a lot of memory (I don't have 100MB to spare) I decided to try the stream command. Unfortunately I can't make it work for 8-bit PNG files (e.g. http://people.sc.fsu.edu/~jburkardt/dat ... uarium.png) on my Ubuntu PC.

Code: Select all

stream -map rgb aquarium.png output.rgb 
produces a file with only zeros in it.

Code: Select all

convert aquarium.png output.rgb
works fine.

So far I tried:
- different values of --with-quantum-depth in the configuration
- stream -depth parameter (however from the source code it looks like it's ignored)
- setting depth in ImageInfo structure (http://www.imagemagick.org/api/MagickWa ... am_8h.html)

Regards,
Pawel

Re: 7.0.2-9 - stream does not work with 8-bit PNG

Posted: 2016-08-22T16:14:29-07:00
by snibgo
As far as I know, the output from "stream" is a dump of the pixels in your choice of channel order and storage type (integer, double, etc), with no header. That's the output you get, and giving the filename an extension of .png or .jpg or whatever makes no difference.

See http://www.imagemagick.org/script/stream.php

Re: 7.0.2-9 - stream does not work with 8-bit PNG

Posted: 2016-08-23T00:15:10-07:00
by rydberg
I don't expect "stream" to produce me another PNG file. Please also note that in

Code: Select all

stream -map rgb aquarium.png output.rgb
output is written to "output.rgb". For PNGs files with bit depth higher than 8 bits "stream" produces valid output, e.g . 3 bytes per pixel with RGB components. I can display the output using "display" command or simply convert my RGB output to PNG or other format.

My problem is that for 8-bit PNGs "stream" produces RGB output that consists only zeros, i.e. the image is black.

Re: 7.0.2-9 - stream does not work with 8-bit PNG

Posted: 2016-08-23T00:41:02-07:00
by snibgo
Ah, sorry, I misunderstood.

I get the same result (all bytes are zero) on v6.9.5-3.

Re: 7.0.2-9 - stream does not work with 8-bit PNG

Posted: 2016-08-23T01:30:29-07:00
by rydberg
What is more, there are some differences in how "stream" works for PNGs with other bit depths between 7.0.2-9 and 6.7.7.10 (default Ubuntu).

Basically 6.7.7.10 works fine for all PNGs I tried (besides 8-bit PNGs). However, 7.0.2-9 version does a strange interlacing. For example, consider "123.png" file that is just an image with all pixels set to R:0 G:1 B:2 and 24 bits depth.

The output of "stream":

Code: Select all

stream -map rgb 123.png red_ubuntu.rgb
from 6.7.7.10 version goes like that:

Code: Select all

00 01 02 00 01 02 00 01 02 ....
which is expected.

However the output of "stream" from 7.0.2-9 version is:

Code: Select all

 00 01 02 01 02 00 02 00 01 00 01 02  .. 
which is RGBGBRBRG order.

Re: 7.0.2-9 - stream does not work for PNG

Posted: 2016-08-23T13:53:11-07:00
by rydberg
I think I found a bug in MagickCore/stream.c in StreamImagePixels function. In all loops that fill stream_info->pixels, for example:

Code: Select all

      
      if (LocaleCompare(stream_info->map,"RGB") == 0)
        {
          p=GetAuthenticPixelQueue(image);
          if (p == (const Quantum *) NULL)
            break;
          for (x=0; x < (ssize_t) GetImageExtent(image); x++)
          {
            *q++=ScaleQuantumToChar(GetPixelRed(image,p));
            *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
            *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
            p++;
          }
          break;
        }
        
p is incremented by one. I think it should be incremented like that:

Code: Select all

p += image->number_channels;
This makes "stream" work for some PNGs, including "123.png" from my previous post and for example http://people.sc.fsu.edu/~jburkardt/data/png/dragon.png. However, 8-bit PNGs are all still black.

Re: 7.0.2-9 - stream does not work for PNG

Posted: 2016-08-25T12:45:46-07:00
by rydberg
In ReadOnePNGImage function (coders/png.c) function ImportQuantumPixels is only called when:

Code: Select all

if (image->storage_class == DirectClass)
Why is that? When I called these functions also in:

Code: Select all

else /* image->storage_class != DirectClass */
"stream" starts to work for my 8-bit PNGs.

Re: 7.0.2-9 - stream does not work for PNG

Posted: 2016-08-25T16:19:42-07:00
by magick
Thanks for the problem report. We can reproduce it and will have a patch to fix it in GIT master branch @ https://github.com/ImageMagick/ImageMagick later today. The patch will be available in the beta releases of ImageMagick @ http://www.imagemagick.org/download/beta/ by sometime tomorrow.

Re: 7.0.2-9 - stream does not work for PNG

Posted: 2016-08-27T07:09:46-07:00
by rydberg
I saw https://github.com/ImageMagick/ImageMag ... it/5cb9208 change. Thanks!

What about the second problem with 8-bit PNGs (example image http://people.sc.fsu.edu/~jburkardt/dat ... uarium.png)? Do you plan to fix that as well or maybe you'd like me to provide more data?

Re: 7.0.2-9 - stream does not work for PNG

Posted: 2016-08-27T10:03:42-07:00
by magick
We may very well fix that problem-- however, there are about 30 bugs and enhancement requests pending so it may take a few weeks to get to the PNG problem.