From 0d57eecc316d3f57bd2c77ebbda7fc5fc95f2523 Mon Sep 17 00:00:00 2001 From: cristy Date: Sun, 4 Sep 2011 22:13:56 +0000 Subject: [PATCH] --- coders/png.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 73 insertions(+), 6 deletions(-) diff --git a/coders/png.c b/coders/png.c index 74413cfc2..ffdd6ddc1 100644 --- a/coders/png.c +++ b/coders/png.c @@ -7604,6 +7604,71 @@ static MagickBooleanType WriteOnePNGImage(MngInfo *mng_info, ping_preserve_colormap = mng_info->ping_preserve_colormap; ping_need_colortype_warning = MagickFalse; + /* Recognize the ICC sRGB profile and convert it to the sRGB chunk, + * i.e., eliminate the ICC profile and set image->rendering_intent. + * Note that this will not involve any changes to the actual pixels + * but merely passes information to applications that read the resulting + * PNG image. + */ + if (ping_exclude_sRGB == MagickFalse) + { + char + *name; + + const StringInfo + *profile; + + ResetImageProfileIterator(image); + for (name=GetNextImageProfile(image); name != (const char *) NULL; ) + { + profile=GetImageProfile(image,name); + + if (profile != (StringInfo *) NULL) + { + if ((LocaleCompare(name,"ICC") == 0) || + (LocaleCompare(name,"ICM") == 0)) + { + unsigned char + *data; + + png_uint_32 + length; + + { + length=(png_uint_32) GetStringInfoLength(profile); + + if (length == 3144) + { + (void) LogMagickEvent(CoderEvent,GetMagickModule(), + " got a 3144-byte ICC profile (potentially sRGB)"); + + data=GetStringInfoDatum(profile); + + if (data[52]=='s' && data[53]=='R' && + data[54]=='G' && data[55]=='B') + { + (void) LogMagickEvent(CoderEvent,GetMagickModule(), + " It is sRGB)"); + if (image->rendering_intent==UndefinedIntent); + image->rendering_intent=PerceptualIntent; + } + else + (void) LogMagickEvent(CoderEvent,GetMagickModule(), + " It is not sRGB (%c%c%c%c)",data[52], + data[53],data[54],data[55]); + + } + else + (void) LogMagickEvent(CoderEvent,GetMagickModule(), + " got a %lu-byte ICC profile", + (unsigned long) length); + } + } + } + name=GetNextImageProfile(image); + } + } + number_opaque = 0; number_semitransparent = 0; number_transparent = 0; @@ -9790,9 +9855,13 @@ static MagickBooleanType WriteOnePNGImage(MngInfo *mng_info, png_set_compression_strategy(ping, mng_info->write_png_compression_strategy-1); - - if ((ping_exclude_tEXt == MagickFalse || ping_exclude_zTXt == MagickFalse) && - (ping_exclude_iCCP == MagickFalse || ping_exclude_zCCP == MagickFalse)) + /* Only write the iCCP chunk if we are not writing the sRGB chunk. */ + if (ping_exclude_sRGB != MagickFalse || + (image->rendering_intent == UndefinedIntent)) + { + if ((ping_exclude_tEXt == MagickFalse || + ping_exclude_zTXt == MagickFalse) && + (ping_exclude_iCCP == MagickFalse || ping_exclude_zCCP == MagickFalse)) { ResetImageProfileIterator(image); for (name=GetNextImageProfile(image); name != (const char *) NULL; ) @@ -9835,6 +9904,7 @@ static MagickBooleanType WriteOnePNGImage(MngInfo *mng_info, name=GetNextImageProfile(image); } + } } #if defined(PNG_WRITE_sRGB_SUPPORTED) @@ -9854,9 +9924,6 @@ static MagickBooleanType WriteOnePNGImage(MngInfo *mng_info, (void) png_set_sRGB(ping,ping_info,( Magick_RenderingIntent_to_PNG_RenderingIntent( image->rendering_intent))); - - if (ping_exclude_gAMA == MagickFalse) - png_set_gAMA(ping,ping_info,0.45455); } } -- 2.40.0