aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElliott Hughes2016-04-21 16:26:14 -0500
committerElliott Hughes2016-04-21 16:26:14 -0500
commit692941be79fd765f8873d810ae627a917dfd791b (patch)
treea3ed720414d0068cea8c5f1dee6b9573ff47e927 /interlace-frames.py
parentdf093c15121df40693519d2a1c703cf1684423d5 (diff)
downloadplatform-bootable-recovery-692941be79fd765f8873d810ae627a917dfd791b.tar.gz
platform-bootable-recovery-692941be79fd765f8873d810ae627a917dfd791b.tar.xz
platform-bootable-recovery-692941be79fd765f8873d810ae627a917dfd791b.zip
Go back to the old ear-wiggling Android animation.
But keep the new code so we can easily test new animations when we have them. This change includes tbao's de-interlace script, plus a one-liner that's necessary to play the animation at the correct speed when there's no progress bar showing. (This was always a bug, it's just way more noticeable when your animation only has 7 frames.) Bug: http://b/28316654 Bug: http://b/26548285 Change-Id: I32c601c352d6be235d1b44f14fca7e125defd77d
Diffstat (limited to 'interlace-frames.py')
-rwxr-xr-x[-rw-r--r--]interlace-frames.py62
1 files changed, 48 insertions, 14 deletions
diff --git a/interlace-frames.py b/interlace-frames.py
index 3e777b47..6b435aa9 100644..100755
--- a/interlace-frames.py
+++ b/interlace-frames.py
@@ -1,3 +1,4 @@
1#!/usr/bin/env python
1# Copyright (C) 2014 The Android Open Source Project 2# Copyright (C) 2014 The Android Open Source Project
2# 3#
3# Licensed under the Apache License, Version 2.0 (the "License"); 4# Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,19 +14,16 @@
13# limitations under the License. 14# limitations under the License.
14 15
15""" 16"""
16Script to take a set of frames (PNG files) for a recovery animation and turn 17Script to take a set of frames (PNG files) for a recovery animation
17it into a single output image which contains the input frames interlaced by 18and turn it into a single output image which contains the input frames
18row. Run with the names of all the input frames on the command line. Specify 19interlaced by row. Run with the names of all the input frames on the
19the name of the output file with -o (or --output), and optionally specify the 20command line, in order, followed by the name of the output file.
20number of frames per second (FPS) with --fps (default: 20).
21
22e.g.
23interlace-frames.py --fps 20 --output output.png frame0.png frame1.png frame3.png
24""" 21"""
25 22
26from __future__ import print_function 23from __future__ import print_function
27 24
28import argparse 25import argparse
26import os.path
29import sys 27import sys
30try: 28try:
31 import Image 29 import Image
@@ -35,7 +33,7 @@ except ImportError:
35 sys.exit(1) 33 sys.exit(1)
36 34
37 35
38def interlace(output, fps, inputs): 36def interlace(output, inputs):
39 frames = [Image.open(fn).convert("RGB") for fn in inputs] 37 frames = [Image.open(fn).convert("RGB") for fn in inputs]
40 assert len(frames) > 0, "Must have at least one input frame." 38 assert len(frames) > 0, "Must have at least one input frame."
41 sizes = set() 39 sizes = set()
@@ -60,21 +58,57 @@ def interlace(output, fps, inputs):
60 58
61 meta = PngImagePlugin.PngInfo() 59 meta = PngImagePlugin.PngInfo()
62 meta.add_text("Frames", str(N)) 60 meta.add_text("Frames", str(N))
63 meta.add_text("FPS", str(fps))
64 61
65 out.save(output, pnginfo=meta) 62 out.save(output, pnginfo=meta)
66 63
67 64
65def deinterlace(output, input):
66 # Truncate the output filename extension if it's '.png'.
67 if os.path.splitext(output)[1].lower() == '.png':
68 output = output[:-4]
69
70 img2 = Image.open(input)
71 print(img2.mode)
72 palette = img2.getpalette()
73 img = img2.convert("RGB")
74 num_frames = int(img.info.get('Frames', 1))
75 print('Found %d frames in %s.' % (num_frames, input))
76 assert num_frames > 0, 'Invalid Frames meta.'
77
78 # palette = img.getpalette()
79 print(palette)
80
81 width, height = img.size
82 height /= num_frames
83 for k in range(num_frames):
84 out = Image.new('RGB', (width, height))
85 out.info = img.info
86 for i in range(width):
87 for j in range(height):
88 out.putpixel((i, j), img.getpixel((i, j * num_frames + k)))
89 # out.putpalette(img.getpalette(), rawmode='RGB')
90 out2 = out.convert(mode='P', palette=palette)
91 #out2 = out
92 print(out2.mode)
93 # out2.putpalette(palette)
94 filename = '%s%02d.png' % (output, k)
95 out2.save(filename)
96 print('Frame %d written to %s.' % (k, filename))
97
98
68def main(argv): 99def main(argv):
69 parser = argparse.ArgumentParser() 100 parser = argparse.ArgumentParser(description='Parse')
70 parser.add_argument('--fps', default=20) 101 parser.add_argument('--deinterlace', '-d', action='store_true')
71 parser.add_argument('--output', '-o', required=True) 102 parser.add_argument('--output', '-o', required=True)
72 parser.add_argument('input', nargs='+') 103 parser.add_argument('input', nargs='+')
73 args = parser.parse_args(argv) 104 args = parser.parse_args(argv)
74 105
75 interlace(args.output, args.fps, args.input) 106 if args.deinterlace:
107 # args.input is a list, and we only process the first when deinterlacing.
108 deinterlace(args.output, args.input[0])
109 else:
110 interlace(args.output, args.input)
76 111
77 112
78if __name__ == '__main__': 113if __name__ == '__main__':
79 main(sys.argv[1:]) 114 main(sys.argv[1:])
80