[PATCH olpc-bootanim 2/2] add undelta.py tool for splitting out individual images from deltas

Sascha Silbe silbe at activitycentral.com
Mon Mar 28 13:01:32 EDT 2011


undelta.py will create frameNN.565 files from frame00.565 and deltas.

Signed-off-by: Sascha Silbe <silbe at activitycentral.com>
---
 deltas/undelta.py |   51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 51 insertions(+), 0 deletions(-)
 create mode 100755 deltas/undelta.py

diff --git a/deltas/undelta.py b/deltas/undelta.py
new file mode 100755
index 0000000..ea8484e
--- /dev/null
+++ b/deltas/undelta.py
@@ -0,0 +1,51 @@
+#!/usr/bin/env python
+import struct
+
+LINE = 0
+FIRSTCOL = 1
+LEN = 2
+DATA = 3
+
+FB_SIZE = 1200*900
+FB_WIDTH = 1200
+FB_HEIGHT = 900
+
+
+def apply_delta(image, deltas):
+    if deltas[:4] != 'D565':
+        raise ValueError('Not a delta!')
+
+    deltas = deltas[4:]
+    while deltas and deltas[:4] != 'D565':
+        line, = struct.unpack('<H', deltas[LINE * 2:LINE * 2 + 2])
+        first_col, = struct.unpack('<H', deltas[FIRSTCOL * 2:FIRSTCOL * 2 + 2])
+        length, = struct.unpack('<H', deltas[LEN * 2:LEN * 2 + 2])
+        offset = (FB_WIDTH * line + first_col) * 2
+        new_slice = deltas[DATA * 2:DATA * 2 + length * 2]
+        if len(new_slice) != len(image[offset:offset + length * 2]):
+            raise ValueError('Incomplete delta!')
+
+        image[offset:offset + length * 2] = new_slice
+        deltas = deltas[(DATA + length) * 2:]
+
+    return deltas
+
+
+def main():
+    deltas = file('deltas', 'rb').read()
+    frame0 = file('frame00.565', 'rb').read()
+
+    header = frame0[:12]
+    image = list(frame0[12:])
+    deltas_left = deltas
+    frame_nr = 0
+
+    while deltas_left:
+        frame_nr += 1
+        print 'Processing frame #%d' % (frame_nr, )
+        deltas_left = apply_delta(image, deltas_left)
+        with file('frame%02d.565' % (frame_nr, ), 'wb') as output_file:
+            output_file.write(header + ''.join(image))
+
+
+main()
-- 
1.7.4.1




More information about the Devel mailing list