|
@ -73,4 +73,70 @@ class Image(object): |
|
|
|
|
|
|
|
|
def show(self): |
|
|
def show(self): |
|
|
skimage.io.imshow(self.data) |
|
|
skimage.io.imshow(self.data) |
|
|
skimage.io.show() |
|
|
|
|
|
|
|
|
skimage.io.show() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from io import BytesIO |
|
|
|
|
|
import array |
|
|
|
|
|
import struct |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Chunkmap(object): |
|
|
|
|
|
def __init__(self): |
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
def read(self, filename): |
|
|
|
|
|
with open(filename, "rb") as f: |
|
|
|
|
|
data = f.read(-1) |
|
|
|
|
|
self.parse(data, 1) |
|
|
|
|
|
|
|
|
|
|
|
def parse(self, data, count): |
|
|
|
|
|
data = BytesIO(data) |
|
|
|
|
|
res = {} |
|
|
|
|
|
total_count = 0 |
|
|
|
|
|
for c in range(count): |
|
|
|
|
|
lastpos = data.tell() |
|
|
|
|
|
total_count += 1 |
|
|
|
|
|
hdr = data.read(2) |
|
|
|
|
|
if not hdr: |
|
|
|
|
|
break |
|
|
|
|
|
typ = ord(hdr[0]) |
|
|
|
|
|
bname = data.read(2*ord(hdr[1])) |
|
|
|
|
|
name = bname.decode("utf16")[:-1].encode("utf8") |
|
|
|
|
|
if typ == 1: |
|
|
|
|
|
value, = struct.unpack("B", data.read(1)) |
|
|
|
|
|
elif typ in [2, 3]: |
|
|
|
|
|
value, = struct.unpack("I", data.read(4)) |
|
|
|
|
|
elif typ == 5: |
|
|
|
|
|
value, = struct.unpack("Q", data.read(8)) |
|
|
|
|
|
elif typ == 6: |
|
|
|
|
|
value, = struct.unpack("d", data.read(8)) |
|
|
|
|
|
elif typ == 8: |
|
|
|
|
|
value = data.read(2) |
|
|
|
|
|
while value[-2:] != "\x00\x00": |
|
|
|
|
|
value += data.read(2) |
|
|
|
|
|
value = value.decode("utf16")[:-1].encode("utf8") |
|
|
|
|
|
elif typ == 9: |
|
|
|
|
|
cnt, = struct.unpack("Q", data.read(8)) |
|
|
|
|
|
value = array.array("B", data.read(cnt)) |
|
|
|
|
|
elif typ == 11: |
|
|
|
|
|
curpos = data.tell() |
|
|
|
|
|
newcount, length = struct.unpack("<IQ", data.read(12)) |
|
|
|
|
|
curpos = data.tell() |
|
|
|
|
|
length -= data.tell()-lastpos |
|
|
|
|
|
nextdata = data.read(length) |
|
|
|
|
|
value = self.parse(nextdata, newcount) |
|
|
|
|
|
print("WE GOT A NEW DICT") |
|
|
|
|
|
# Skip some offsets |
|
|
|
|
|
data.read(newcount * 8) |
|
|
|
|
|
else: |
|
|
|
|
|
assert 0, "%s hdr %x:%x unknown" % (name, ord(hdr[0]), ord(hdr[1])) |
|
|
|
|
|
if not name in res: |
|
|
|
|
|
res[name] = value |
|
|
|
|
|
else: |
|
|
|
|
|
if not isinstance(res[name], list): |
|
|
|
|
|
res[name] = [res[name]] |
|
|
|
|
|
res[name].append(value) |
|
|
|
|
|
x = data.read() |
|
|
|
|
|
assert not x, "skip %d %s" % (len(x), repr(x[:30])) |
|
|
|
|
|
return res |