[Magick-bugs] quantize introduces black areas (confirmation of already posted bug)

Till Oliver Knoll oliver.knoll at autoform.ch
Tue Sep 11 01:52:23 PDT 2007


Hello!

I want to backup a bug which has already been reported, but probably 
turned down:

 
http://studio.imagemagick.org/pipermail/magick-bugs/2007-August/002700.html

I am using ImageMagick-6.3.5-Q8 on Windows XP SP2, binary release (as 
downloaded from 
(http://www.imagemagick.org/script/binary-releases.php#windows)


Me too observed that certain images in PNG format produce black areas.

First I could reproduce the behaviour as described in the 002700.html 
description above, see attachemenet 'problem.png':

   convert -size 256x256 gradient:blue-none -colors 256 problem.png

Another image 'test_in.png' reproduces this problem with an image of 
mine. Note again the blueish colours which are affected which could lead 
to the source of the bug.

   convert -colors 16 test_in.png test_out.png

Also note that the old version on some Linux box:

Version: ImageMagick 6.0.7 01/21/05 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2004 ImageMagick Studio LLC

with the same input image 'test_in.png' produces a good output image 
'test_out_6.0.7.png'

I have not tried yet with a recent "Q16" (16 bits per channel) version 
(note that the Linux version was a Q16 version), I deliberately 
downloaded the Q8.

I also compiled a Q8 (6.3.5) myself (by setting "#define QuantumDepth 8" 
in magick-config.h.in), same results. So this is not just a "build bug".

The "in" images (except the "gimp_scaled") are produced like this: They 
are loaded in with Qt 4.3.1 (Qt = C++ toolkit), scaled with 32bit, saved 
into a QByteArray in PNG format (= in memory), converted to a Magick 
Blob and then saved again in PNG format, for debugging purposes:

   QByteArray byteArray;
   QBuffer    buffer(&byteArray);

   // save the scaled 32bit image as PNG into buffer
   buffer.open(QIODevice::WriteOnly);
   image.save(&buffer, "PNG"); // 'image' being a QImage here, not
                               // the "Magick++ Image"!
   buffer.close();

   char *data = byteArray.data();
   int size = byteArray.size();

   // create a Blob
   Magick::Blob blob(data, size);

   // read in the image into the Magick Image
   Magick::Image magic(blob);

#ifdef _DEBUG
   magic.write("test_in.png");
#endif

After that they are quantized programmatically:

   magic.quantizeDither(false);
   magic.quantizeColors(nofColours);
   magic.quantizeTreeDepth(8);

   magic.quantize();
   magic.normalize();

Or with the Magick tool "convert" (with the above input 'test_in.png'), 
producing the same wrong results ("black areas").


Now the funny thing is that when I take the original image, load it into 
the Gimp, scale it to the same size (96x96), save it again as PNG, then 
it works, see 'test_out2_gimp_scaled.png'.

Obviously the "Qt resize" produces some funny image data, but still it 
appears to me as a valid PNG image (after all, it has been saved by the 
Magick write() method) and the images produces like this show no obvious 
anomalies, neither in Gimp nor in XnView, for example.

I've also tried setting different colour spaces, they produce different 
results, but all bad (instead of black I see green etc.)

Hope that gives you some hints as to track down the bug. Let me know if 
you need more details.

Cheers, Oliver


More information about the Magick-bugs mailing list