Better ICC Profile conversion through fixing bytes/string GitOrigin-RevId: 51e07d7e2e3f6ebb63eaeb2559a2a22e36ac42b9 Change-Id: I2eecc6bf545c5eb0ce166cfcb5f84658f7330b8b
diff --git a/code/iccp.py b/code/iccp.py index d34474d..ace1678 100755 --- a/code/iccp.py +++ b/code/iccp.py
@@ -101,6 +101,7 @@ d["pcsilluminant"] = readICCXYZNumber(profile[68:80]) d["creator"] = profile[80:84] d["id"] = profile[84:100] + (ntags,) = struct.unpack_from(">L", profile, 128) d["ntags"] = ntags fmt = "4s2L" * ntags @@ -113,7 +114,7 @@ # the ICC spec. # Convert (sig,offset,size) triples into (sig,value) pairs. - rawtag = map(lambda x: (x[0], profile[x[1] : x[1] + x[2]]), tt) + rawtag = [(sig, profile[offset : offset + size]) for sig, offset, size in tt] self.rawtagtable = rawtag self.rawtagdict = dict(rawtag) tag = dict() @@ -495,7 +496,8 @@ some Python value determined by the content and type. """ - sig = s[0:4].strip() + sig = s[0:4] + sig = str(sig, "ascii").strip() f = dict( text=RDtext, XYZ=RDXYZ, @@ -512,14 +514,14 @@ """Convert ICC XYZType to rank 1 array of trimulus values.""" # See [ICC 2001] 6.5.26 - assert s[0:4] == "XYZ " + assert s[0:4] == b"XYZ " return readICCXYZNumber(s[8:]) def RDsf32(s): """Convert ICC s15Fixed16ArrayType to list of float.""" # See [ICC 2004] 10.18 - assert s[0:4] == "sf32" + assert s[0:4] == b"sf32" return s15f16l(s[8:]) @@ -530,9 +532,11 @@ the 4 byte language/country code, and *string* is the string corresponding to that code. It seems unlikely that the same language/country code will appear more than once with different - strings, but the ICC standard does not prohibit it.""" + strings, but the ICC standard does not prohibit it. + """ + # See [ICC 2004] 10.13 - assert s[0:4] == "mluc" + assert s[0:4] == b"mluc" n, sz = struct.unpack_from(">2L", s, 8) assert sz == 12 record = [] @@ -548,14 +552,14 @@ # Note: type not specified or used in [ICC 2004], only in older # [ICC 2001]. # See [ICC 2001] 6.5.18 - assert s[0:4] == "text" + assert s[0:4] == b"text" return s[8:-1] def RDcurv(s): """Convert ICC curveType.""" # See [ICC 2001] 6.5.3 - assert s[0:4] == "curv" + assert s[0:4] == b"curv" (count,) = struct.unpack_from(">L", s, 8) if count == 0: return dict(gamma=1) @@ -569,7 +573,7 @@ """Convert Apple CMVideoCardGammaType.""" # See # http://developer.apple.com/documentation/GraphicsImaging/Reference/ColorSync_Manager/Reference/reference.html#//apple_ref/c/tdef/CMVideoCardGammaType - assert s[0:4] == "vcgt" + assert s[0:4] == b"vcgt" (tagtype,) = struct.unpack_from(">L", s, 8) if tagtype != 0: return s[8:]