8031335: Better color profiling
authorprr
Wed, 22 Jan 2014 09:42:51 -0800
changeset 23907 42205a8f63f3
parent 23906 8f7f9cb6fe11
child 23908 fdbaab67db73
8031335: Better color profiling Reviewed-by: bae, vadim, mschoene
jdk/src/share/native/sun/java2d/cmm/lcms/cmsio0.c
--- a/jdk/src/share/native/sun/java2d/cmm/lcms/cmsio0.c	Wed Jan 22 09:39:16 2014 -0800
+++ b/jdk/src/share/native/sun/java2d/cmm/lcms/cmsio0.c	Wed Jan 22 09:42:51 2014 -0800
@@ -619,6 +619,32 @@
        return _cmsSearchTag(Icc, sig, FALSE) >= 0;
 }
 
+/*
+ * Enforces that the profile version is per. spec.
+ * Operates on the big endian bytes from the profile.
+ * Called before converting to platform endianness.
+ * Byte 0 is BCD major version, so max 9.
+ * Byte 1 is 2 BCD digits, one per nibble.
+ * Reserved bytes 2 & 3 must be 0.
+ */
+static cmsUInt32Number _validatedVersion(cmsUInt32Number DWord)
+{
+    cmsUInt8Number* pByte = (cmsUInt8Number*)&DWord;
+    cmsUInt8Number temp1;
+    cmsUInt8Number temp2;
+
+    if (*pByte > 0x09) *pByte = (cmsUInt8Number)9;
+    temp1 = *(pByte+1) & 0xf0;
+    temp2 = *(pByte+1) & 0x0f;
+    if (temp1 > 0x90) temp1 = 0x90;
+    if (temp2 > 9) temp2 = 0x09;
+    *(pByte+1) = (cmsUInt8Number)(temp1 | temp2);
+    *(pByte+2) = (cmsUInt8Number)0;
+    *(pByte+3) = (cmsUInt8Number)0;
+
+    return DWord;
+}
+
 // Read profile header and validate it
 cmsBool _cmsReadHeader(_cmsICCPROFILE* Icc)
 {
@@ -653,7 +679,7 @@
     Icc -> creator         = _cmsAdjustEndianess32(Header.creator);
 
     _cmsAdjustEndianess64(&Icc -> attributes, &Header.attributes);
-    Icc -> Version         = _cmsAdjustEndianess32(Header.version);
+    Icc -> Version         = _cmsAdjustEndianess32(_validatedVersion(Header.version));
 
     // Get size as reported in header
     HeaderSize = _cmsAdjustEndianess32(Header.size);