Mercurial > octave-dspies
comparison libinterp/dldfcn/__magick_read__.cc @ 18957:87cba451fd5e stable
__magick_read__.cc: fix png check for image class in older GM (bug #42834).
author | Carnë Draug <carandraug@octave.org> |
---|---|
date | Thu, 24 Jul 2014 17:37:45 +0100 |
parents | 548643c76a88 |
children |
comparison
equal
deleted
inserted
replaced
18956:ab5983dc0587 | 18957:87cba451fd5e |
---|---|
72 // 2) A PNG file is only an indexed image if color type orig is 3 (value comes | 72 // 2) A PNG file is only an indexed image if color type orig is 3 (value comes |
73 // from libpng) | 73 // from libpng) |
74 static bool | 74 static bool |
75 is_indexed (const Magick::Image& img) | 75 is_indexed (const Magick::Image& img) |
76 { | 76 { |
77 bool retval = false; | 77 bool indexed = (img.classType () == Magick::PseudoClass); |
78 const std::string format = img.magick (); | 78 // Our problem until now is non-indexed images, being represented as indexed |
79 if (img.classType () == Magick::PseudoClass | 79 // by GM. The following attempts educated guesses to undo this optimization. |
80 && format != "JPEG" | 80 if (indexed) |
81 && (format != "PNG" | 81 { |
82 || const_cast<Magick::Image&> (img).attribute ("PNG:IHDR.color-type-orig") == "3")) | 82 const std::string fmt = img.magick (); |
83 retval = true; | 83 if (fmt == "JPEG") |
84 | 84 // The JPEG format does not support indexed images, but GM sometimes |
85 return retval; | 85 // reports grayscale JPEG as indexed. Always false for JPEG. |
86 indexed = false; | |
87 else if (fmt == "PNG") | |
88 { | |
89 // Newer versions of GM (at least does not happens with 1.3.16) will | |
90 // store values from the underlying library as image attributes. In | |
91 // the case of PNG files, this is libpng where an indexed image will | |
92 // always have a value of 3 for "color-type-orig". This property | |
93 // always has a value in libpng so if we get nothing, we assume this | |
94 // GM version does not store them and we have to go with whatever | |
95 // GM PseudoClass says. | |
96 const std::string color_type = | |
97 const_cast<Magick::Image&> (img).attribute ("PNG:IHDR.color-type-orig"); | |
98 if (! color_type.empty() && color_type != "3") | |
99 indexed = false; | |
100 } | |
101 } | |
102 return indexed; | |
86 } | 103 } |
87 | 104 |
88 // The depth from depth() is not always correct for us but seems to be the | 105 // The depth from depth() is not always correct for us but seems to be the |
89 // best value we can get. For example, a grayscale png image with 1 bit | 106 // best value we can get. For example, a grayscale png image with 1 bit |
90 // per channel should return a depth of 1 but instead we get 8. | 107 // per channel should return a depth of 1 but instead we get 8. |