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);
}
}