From: glennrp Date: Tue, 4 Oct 2011 01:21:09 +0000 (+0000) Subject: Recognize certain sRGB profiles by their crc32. X-Git-Tag: 7.0.1-0~6905 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ee7b4c0ec5013e84a2ab2e0fe9c4beaed4b75606;p=imagemagick Recognize certain sRGB profiles by their crc32. --- diff --git a/coders/png.c b/coders/png.c index d7d244151..905e61ee9 100644 --- a/coders/png.c +++ b/coders/png.c @@ -7628,59 +7628,54 @@ static MagickBooleanType WriteOnePNGImage(MngInfo *mng_info, if ((LocaleCompare(name,"ICC") == 0) || (LocaleCompare(name,"ICM") == 0)) { - unsigned char - *data; + int + icheck; + /* 0: not a known sRGB profile + * 1: HP-Microsoft sRGB v2 + * 2: ICC sRGB v4 perceptual + * 3: ICC sRGB v2 perceptual no black-compensation + */ png_uint_32 - length; + check_crc[4] = {0, 0xf29e526dUL, 0xbbef7812UL, 0x427ebb21UL}, + check_len[4] = {0, 3144, 60960, 3052}; - length=(png_uint_32) GetStringInfoLength(profile); + png_uint_32 + length, + profile_crc; - if (length == 3144) - { - (void) LogMagickEvent(CoderEvent,GetMagickModule(), - " got a 3144-byte ICC profile (potentially sRGB)"); + unsigned char + *data; - data=GetStringInfoDatum(profile); + length=(png_uint_32) GetStringInfoLength(profile); - if (data[52]=='s' && data[53]=='R' && - data[54]=='G' && data[55]=='B') - { - (void) LogMagickEvent(CoderEvent,GetMagickModule(), - " It is the HP-Microsoft 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 if (length == 3052) + for (icheck=3; icheck > 0; icheck--) { - (void) LogMagickEvent(CoderEvent,GetMagickModule(), - " got a 3052-byte ICC profile (potentially sRGB)"); + if (length == check_len[icheck]) + { + (void) LogMagickEvent(CoderEvent,GetMagickModule(), + " Got a %lu-byte ICC profile (potentially sRGB)", + (unsigned long) length); - data=GetStringInfoDatum(profile); + data=GetStringInfoDatum(profile); + profile_crc=crc32(0,data,length); - if (data[336]=='s' && data[337]=='R' && - data[338]=='G' && data[339]=='B') - { - (void) LogMagickEvent(CoderEvent,GetMagickModule(), - " It is the ICC no-black sRGB)"); - if (image->rendering_intent==UndefinedIntent) - image->rendering_intent=PerceptualIntent; + (void) LogMagickEvent(CoderEvent,GetMagickModule(), + " with crc=%8x",profile_crc); + + if (profile_crc == check_crc[icheck]) + { + (void) LogMagickEvent(CoderEvent,GetMagickModule(), + " It is sRGB."); + if (image->rendering_intent==UndefinedIntent) + image->rendering_intent=PerceptualIntent; + break; + } } - else - (void) LogMagickEvent(CoderEvent,GetMagickModule(), - " It is not sRGB (%c%c%c%c)",data[52], - data[53],data[54],data[55]); - } - else + if (icheck == 0) (void) LogMagickEvent(CoderEvent,GetMagickModule(), - " got a %lu-byte ICC profile", + " Got a %lu-byte ICC profile", (unsigned long) length); } }