image->columns=ping_width;
image->rows=ping_height;
- /* Note that the following sets image->gamma to 1.0, image->rendering_intent
- to Undefined, and resets image->chromaticity, overriding any ancillary
- chunk data from the PNG file.
- */
if (((int) ping_color_type == PNG_COLOR_TYPE_GRAY) ||
((int) ping_color_type == PNG_COLOR_TYPE_GRAY_ALPHA))
- SetImageColorspace(image,GRAYColorspace,exception);
+ {
+ if (!png_get_valid(ping,ping_info,PNG_INFO_gAMA) &&
+ !png_get_valid(ping,ping_info,PNG_INFO_cHRM) &&
+ !png_get_valid(ping,ping_info,PNG_INFO_sRGB))
+ {
+ /* Set image->gamma to 1.0, image->rendering_intent to Undefined,
+ * and reset image->chromaticity.
+ */
+ SetImageColorspace(image,GRAYColorspace,exception);
+ }
+
+ else
+ {
+ /* Use colorspace data from PNG ancillary chunks */
+ image->colorspace=GRAYColorspace;
+ }
+ }
if (((int) ping_color_type == PNG_COLOR_TYPE_PALETTE) ||
((int) ping_color_type == PNG_COLOR_TYPE_GRAY))