Permalink
Browse files

misc: Add scripts to report VMS tile offsets

  • Loading branch information...
1 parent 2197715 commit 38e040ad831dd9ac4c7356f02847ea2c5641b541 @bgilbert bgilbert committed Jan 7, 2016
Showing with 77 additions and 0 deletions.
  1. +19 −0 misc/vms-dump-opt.py
  2. +58 −0 misc/vms-jpeg-find-tiles.py
View
@@ -0,0 +1,19 @@
+import struct
+import sys
+
+jpeg = 0
+last = float('inf')
+
+with open(sys.argv[1]) as fh:
+ while True:
+ buf = fh.read(40)
+ if not buf:
+ break
+ val = struct.unpack('<q32x', buf)[0]
+
+ if val < last:
+ print '=====', jpeg
+ jpeg += 1
+ last = val
+
+ print val
@@ -0,0 +1,58 @@
+import struct
+import sys
+
+class EOFError(Exception):
+ pass
+
+
+def decode(fh, fmt):
+ count = struct.calcsize(fmt)
+ buf = fh.read(count)
+ if not buf:
+ raise EOFError
+ elif len(buf) < count:
+ raise IOError('Short read')
+ return struct.unpack(fmt, buf)
+
+
+with open(sys.argv[1]) as fh:
+ try:
+ # Walk header
+ marker_byte = 0
+ while marker_byte != 0xda: # SOS
+ flag, marker_byte = decode(fh, '2B')
+ if flag != 0xff:
+ raise ValueError('Expected marker, found something else')
+ if marker_byte == 0xd8:
+ # SOI; no marker segment
+ continue
+ count = decode(fh, '>H')[0]
+ fh.seek(count - 2, 1)
+
+ # Walk entropy-coded data
+ base = fh.tell()
+ print base
+ while True:
+ buf = fh.read(4 << 10)
+ if not buf:
+ break
+ off = 0
+ while True:
+ off = buf.find('\xff', off)
+ if off == -1:
+ break
+ elif off == len(buf) - 1:
+ ch = fh.read(1)
+ if len(ch) != 1:
+ raise IOError('Short read')
+ buf += ch
+ marker_byte = struct.unpack('B', buf[off + 1])[0]
+ if marker_byte >= 0xd0 and marker_byte <= 0xd7:
+ print base + off + 2
+ off += 2
+ base += len(buf)
+ except EOFError:
+ pass
+ except Exception:
+ print 'At {}:'.format(fh.tell())
+ raise

0 comments on commit 38e040a

Please sign in to comment.