From 560817243127475c1ec4f5e5f13196223a8f0b37 Mon Sep 17 00:00:00 2001 From: glennrp Date: Sat, 27 Aug 2011 21:48:13 +0000 Subject: [PATCH] Recognize the sRGB profile and write the sRGB chunk instead of the full profile. --- coders/png.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 72 insertions(+), 5 deletions(-) diff --git a/coders/png.c b/coders/png.c index b2b772ebd..a65a6bc64 100644 --- a/coders/png.c +++ b/coders/png.c @@ -7595,6 +7595,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; @@ -9780,8 +9845,12 @@ static MagickBooleanType WriteOnePNGImage(MngInfo *mng_info, mng_info->write_png_compression_strategy-1); - if ((ping_exclude_tEXt == MagickFalse || ping_exclude_zTXt == MagickFalse) && - (ping_exclude_iCCP == MagickFalse || ping_exclude_zCCP == MagickFalse)) + 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; ) @@ -9824,6 +9893,7 @@ static MagickBooleanType WriteOnePNGImage(MngInfo *mng_info, name=GetNextImageProfile(image); } + } } #if defined(PNG_WRITE_sRGB_SUPPORTED) @@ -9843,9 +9913,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