Streamlined SIZ parsing. #130

This commit is contained in:
John Evans 2014-04-03 07:09:34 -04:00
commit 576571fa85

View file

@ -670,8 +670,8 @@ class Codestream(object):
read_buffer = fptr.read(2) read_buffer = fptr.read(2)
length, = struct.unpack('>H', read_buffer) length, = struct.unpack('>H', read_buffer)
xy_buffer = fptr.read(36) read_buffer = fptr.read(length - 2)
data = struct.unpack('>HIIIIIIIIH', xy_buffer) data = struct.unpack_from('>HIIIIIIIIH', read_buffer)
rsiz = data[0] rsiz = data[0]
if rsiz not in _KNOWN_PROFILES: if rsiz not in _KNOWN_PROFILES:
@ -685,9 +685,8 @@ class Codestream(object):
# Csiz is the number of components # Csiz is the number of components
Csiz = data[9] Csiz = data[9]
component_buffer = fptr.read(Csiz * 3) data = struct.unpack_from('>' + 'B' * (length - 36 - 2),
data = struct.unpack('>' + 'B' * len(component_buffer), read_buffer, offset=36)
component_buffer)
bitdepth = tuple(((x & 0x7f) + 1) for x in data[0::3]) bitdepth = tuple(((x & 0x7f) + 1) for x in data[0::3])
signed = tuple(((x & 0x80) > 0) for x in data[0::3]) signed = tuple(((x & 0x80) > 0) for x in data[0::3])