[PATCH v2 olpc-bootanim 2/2] Add os-undelta tool for splitting out individual images from deltas
Sascha Silbe
silbe at activitycentral.com
Sat Jun 18 09:34:21 EDT 2011
This can be used to "reverse engineer" the boot animation in case the source
is lost.
Signed-off-by: Sascha Silbe <silbe at activitycentral.com>
---
v1->v2:
- add usage instructions
- use directory given on command line instead of current working dir
- rename to os-undelta, move to root of project
- install (to /usr/bin)
Makefile.am | 1 +
os-undelta | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 79 insertions(+), 0 deletions(-)
create mode 100755 os-undelta
diff --git a/Makefile.am b/Makefile.am
index 56e261e..5ef2a78 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -8,6 +8,7 @@ dist_noinst_HEADERS = utils.h
sbin_PROGRAMS = boot-anim-start boot-anim-stop boot-anim-helper boot-anim-running ul-warning
bin_PROGRAMS = plymouth
+dist_bin_SCRIPTS = os-undelta
boot-anim-start: utils.c boot-anim-start.c
boot-anim-stop: utils.c boot-anim-stop.c
diff --git a/os-undelta b/os-undelta
new file mode 100755
index 0000000..863652c
--- /dev/null
+++ b/os-undelta
@@ -0,0 +1,78 @@
+#!/usr/bin/env python
+import os.path
+import struct
+import sys
+
+
+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 print_usage(my_name):
+ print """Usage: %(my_name)s <directory containing frame00.565 and deltas>
+ Convert olpc-bootanim deltas file back to individual images
+
+ Example: %(my_name)s /usr/share/boot-anim
+
+ The following shell snippet can be used to convert the resulting
+ raw bitmap files to PNG files:
+
+ for x in $(seq -f %%02.f 1 25) ; do
+ ffmpeg -vcodec rawvideo -f rawvideo -pix_fmt rgb565 -s 1200x900 \\
+ -i frame"$x".565 -f image2 -vcodec png frame"$x".png
+ done
+ """.replace('\n ', '\n') % locals()
+
+ return 1
+
+
+def main(my_name, args):
+ if not args or '--help' in args:
+ return print_usage(my_name)
+
+ directory_name = args[0]
+ deltas = file(os.path.join(directory_name, 'deltas'), 'rb').read()
+ frame0 = file(os.path.join(directory_name, '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))
+
+ return 0
+
+
+sys.exit(main(sys.argv[0], sys.argv[1:]))
--
1.7.4.1
More information about the Devel
mailing list