7.0.2-9 - stream does not work for PNG

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
rydberg
Posts: 6
Joined: 2016-08-22T10:05:29-07:00
Authentication code: 1151

7.0.2-9 - stream does not work for PNG

Post 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
Last edited by rydberg on 2016-08-23T04:38:12-07:00, edited 1 time in total.

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

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

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

rydberg
Posts: 6
Joined: 2016-08-22T10:05:29-07:00
Authentication code: 1151

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

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

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

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

Post by snibgo »

Ah, sorry, I misunderstood.

I get the same result (all bytes are zero) on v6.9.5-3.
snibgo's IM pages: im.snibgo.com

rydberg
Posts: 6
Joined: 2016-08-22T10:05:29-07:00
Authentication code: 1151

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

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

rydberg
Posts: 6
Joined: 2016-08-22T10:05:29-07:00
Authentication code: 1151

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

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

rydberg
Posts: 6
Joined: 2016-08-22T10:05:29-07:00
Authentication code: 1151

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

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

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

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

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

rydberg
Posts: 6
Joined: 2016-08-22T10:05:29-07:00
Authentication code: 1151

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

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

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

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

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

bluearcus
Posts: 1
Joined: 2020-02-17T06:37:47-07:00
Authentication code: 1152

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

Post by bluearcus »

Distressingly, the 8-bit PNG doesn't stream variant of this bug is *STILL* present in latest ImageMagick 7.

Is there a possibility this will be fixed in the near future? I even built from the latest source, only to find I still can't extract RGB pixel data only in order from 8bit PNG images. Current options seem to be switching file format (haven't found one that works yet though) or running off to Gimp to do the extract.

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

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

Post 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 @ https://www.imagemagick.org/download/beta/ by sometime tomorrow.

Post Reply