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

Martin Langhoff martin.langhoff at gmail.com
Tue Mar 29 13:09:26 EDT 2011


Thanks for hacking on this! Looks like a nice thing to have.

Needs a tad more usability -- ie: accept a parameter for the path to
the deltas file,  add a usage note to the README. Might need to be
renamed os-undelta, live in the root of the project and get installed
to /usr/bin.

cheers,


m

On Mon, Mar 28, 2011 at 1:01 PM, Sascha Silbe <silbe at activitycentral.com> wrote:
> 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
>
> _______________________________________________
> Devel mailing list
> Devel at lists.laptop.org
> http://lists.laptop.org/listinfo/devel
>



-- 
 martin.langhoff at gmail.com
 martin at laptop.org -- Software Architect - OLPC
 - ask interesting questions
 - don't get distracted with shiny stuff  - working code first
 - http://wiki.laptop.org/go/User:Martinlanghoff



More information about the Devel mailing list