# HG changeset patch # User Carnë Draug # Date 1406219865 -3600 # Node ID 87cba451fd5eed2f0105b5be67fe57a708e1aac4 # Parent ab5983dc058743b5380c7c03c8b75a0a81f3db3b __magick_read__.cc: fix png check for image class in older GM (bug #42834). diff -r ab5983dc0587 -r 87cba451fd5e libinterp/dldfcn/__magick_read__.cc --- a/libinterp/dldfcn/__magick_read__.cc Thu Jul 24 11:11:57 2014 -0700 +++ b/libinterp/dldfcn/__magick_read__.cc Thu Jul 24 17:37:45 2014 +0100 @@ -74,15 +74,32 @@ static bool is_indexed (const Magick::Image& img) { - bool retval = false; - const std::string format = img.magick (); - if (img.classType () == Magick::PseudoClass - && format != "JPEG" - && (format != "PNG" - || const_cast (img).attribute ("PNG:IHDR.color-type-orig") == "3")) - retval = true; - - return retval; + bool indexed = (img.classType () == Magick::PseudoClass); + // Our problem until now is non-indexed images, being represented as indexed + // by GM. The following attempts educated guesses to undo this optimization. + if (indexed) + { + const std::string fmt = img.magick (); + if (fmt == "JPEG") + // The JPEG format does not support indexed images, but GM sometimes + // reports grayscale JPEG as indexed. Always false for JPEG. + indexed = false; + else if (fmt == "PNG") + { + // Newer versions of GM (at least does not happens with 1.3.16) will + // store values from the underlying library as image attributes. In + // the case of PNG files, this is libpng where an indexed image will + // always have a value of 3 for "color-type-orig". This property + // always has a value in libpng so if we get nothing, we assume this + // GM version does not store them and we have to go with whatever + // GM PseudoClass says. + const std::string color_type = + const_cast (img).attribute ("PNG:IHDR.color-type-orig"); + if (! color_type.empty() && color_type != "3") + indexed = false; + } + } + return indexed; } // The depth from depth() is not always correct for us but seems to be the