Cleanup code a bit

This commit is contained in:
Alexander 2020-01-19 03:15:37 +03:00
parent a520a435d6
commit 3841c96ec6

View File

@ -100,30 +100,27 @@ def APP(self, marker):
# reassemble the profile, rather than assuming that the APP2 # reassemble the profile, rather than assuming that the APP2
# markers appear in the correct sequence. # markers appear in the correct sequence.
self.icclist.append(s) self.icclist.append(s)
elif marker == 0xFFED: elif marker == 0xFFED and s[:14] == b"Photoshop 3.0\x00":
if s[:14] == b"Photoshop 3.0\x00":
blocks = s[14:]
# parse the image resource block # parse the image resource block
offset = 0 offset = 14
photoshop = {} photoshop = {}
while blocks[offset : offset + 4] == b"8BIM": while s[offset : offset + 4] == b"8BIM":
offset += 4 offset += 4
# resource code # resource code
try: try:
code = i16(blocks, offset) code = i16(s, offset)
except struct.error: except struct.error:
break break
offset += 2 offset += 2
# resource name (usually empty) # resource name (usually empty)
name_len = i8(blocks[offset]) name_len = i8(s[offset])
# name = blocks[offset+1:offset+1+name_len] # name = s[offset+1:offset+1+name_len]
offset = 1 + offset + name_len offset += 1 + name_len
if offset & 1: offset += offset & 1 # align
offset += 1
# resource data block # resource data block
size = i32(blocks, offset) size = i32(s, offset)
offset += 4 offset += 4
data = blocks[offset : offset + size] data = s[offset : offset + size]
if code == 0x03ED: # ResolutionInfo if code == 0x03ED: # ResolutionInfo
data = { data = {
"XResolution": i32(data[:4]) / 65536, "XResolution": i32(data[:4]) / 65536,
@ -132,10 +129,10 @@ def APP(self, marker):
"DisplayedUnitsY": i16(data[12:]), "DisplayedUnitsY": i16(data[12:]),
} }
photoshop[code] = data photoshop[code] = data
offset = offset + size offset += size
if offset & 1: offset += offset & 1 # align
offset += 1
self.info["photoshop"] = photoshop self.info["photoshop"] = photoshop
elif marker == 0xFFEE and s[:5] == b"Adobe": elif marker == 0xFFEE and s[:5] == b"Adobe":
self.info["adobe"] = i16(s, 5) self.info["adobe"] = i16(s, 5)
# extract Adobe custom properties # extract Adobe custom properties