# HG changeset patch # User Carnë Draug # Date 1406219865 -3600 # Node ID 914c3ce73665fbfacc96921dd9894d7b58d99b21 # Parent c66029adf853e1bc56509927a9625b7165e023b6 __magick_read__.cc: fix png check for image class in older GM (bug #42834). diff -r c66029adf853 -r 914c3ce73665 libinterp/dldfcn/__magick_read__.cc --- a/libinterp/dldfcn/__magick_read__.cc Tue Jul 22 22:46:48 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