aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTao Bao2015-12-11 17:18:51 -0600
committerTao Bao2015-12-16 13:35:52 -0600
commitb723f4f38f53a38502abb1a63165ac0749bc9cd9 (patch)
treec311d658de7ac03080583b24e9157cc6f502f1b4 /interlace-frames.py
parent4e72d1a81e2194caf101dc8633858efaa9bdb39b (diff)
downloadplatform-bootable-recovery-b723f4f38f53a38502abb1a63165ac0749bc9cd9.tar.gz
platform-bootable-recovery-b723f4f38f53a38502abb1a63165ac0749bc9cd9.tar.xz
platform-bootable-recovery-b723f4f38f53a38502abb1a63165ac0749bc9cd9.zip
res: Embed FPS into icon_installing.png.
We allow vendor-specific icon installing image but have defined private animation_fps that can't be overridden. This CL changes the image generator to optionally embed FPS (otherwise use the default value of 20) into the generated image. For wear devices, they are using individual images instead of the interlaced one. Change the animation_fps from private to protected so that it can be customized. Bug: 26009230 Change-Id: I9fbf64ec717029d4c54f72316f6cb079e8dbfb5e
Diffstat (limited to 'interlace-frames.py')
-rw-r--r--interlace-frames.py79
1 files changed, 53 insertions, 26 deletions
diff --git a/interlace-frames.py b/interlace-frames.py
index 243e565e..3e777b47 100644
--- a/interlace-frames.py
+++ b/interlace-frames.py
@@ -12,42 +12,69 @@
12# See the License for the specific language governing permissions and 12# See the License for the specific language governing permissions and
13# limitations under the License. 13# limitations under the License.
14 14
15"""Script to take a set of frames (PNG files) for a recovery animation 15"""
16and turn it into a single output image which contains the input frames 16Script to take a set of frames (PNG files) for a recovery animation and turn
17interlaced by row. Run with the names of all the input frames on the 17it into a single output image which contains the input frames interlaced by
18command line, in order, followed by the name of the output file.""" 18row. Run with the names of all the input frames on the command line. Specify
19the name of the output file with -o (or --output), and optionally specify the
20number of frames per second (FPS) with --fps (default: 20).
19 21
22e.g.
23interlace-frames.py --fps 20 --output output.png frame0.png frame1.png frame3.png
24"""
25
26from __future__ import print_function
27
28import argparse
20import sys 29import sys
21try: 30try:
22 import Image 31 import Image
23 import PngImagePlugin 32 import PngImagePlugin
24except ImportError: 33except ImportError:
25 print "This script requires the Python Imaging Library to be installed." 34 print("This script requires the Python Imaging Library to be installed.")
26 sys.exit(1) 35 sys.exit(1)
27 36
28frames = [Image.open(fn).convert("RGB") for fn in sys.argv[1:-1]]
29assert len(frames) > 0, "Must have at least one input frame."
30sizes = set()
31for fr in frames:
32 sizes.add(fr.size)
33 37
34assert len(sizes) == 1, "All input images must have the same size." 38def interlace(output, fps, inputs):
35w, h = sizes.pop() 39 frames = [Image.open(fn).convert("RGB") for fn in inputs]
36N = len(frames) 40 assert len(frames) > 0, "Must have at least one input frame."
41 sizes = set()
42 for fr in frames:
43 sizes.add(fr.size)
44
45 assert len(sizes) == 1, "All input images must have the same size."
46 w, h = sizes.pop()
47 N = len(frames)
48
49 out = Image.new("RGB", (w, h*N))
50 for j in range(h):
51 for i in range(w):
52 for fn, f in enumerate(frames):
53 out.putpixel((i, j*N+fn), f.getpixel((i, j)))
54
55 # When loading this image, the graphics library expects to find a text
56 # chunk that specifies how many frames this animation represents. If
57 # you post-process the output of this script with some kind of
58 # optimizer tool (eg pngcrush or zopflipng) make sure that your
59 # optimizer preserves this text chunk.
60
61 meta = PngImagePlugin.PngInfo()
62 meta.add_text("Frames", str(N))
63 meta.add_text("FPS", str(fps))
64
65 out.save(output, pnginfo=meta)
66
67
68def main(argv):
69 parser = argparse.ArgumentParser()
70 parser.add_argument('--fps', default=20)
71 parser.add_argument('--output', '-o', required=True)
72 parser.add_argument('input', nargs='+')
73 args = parser.parse_args(argv)
37 74
38out = Image.new("RGB", (w, h*N)) 75 interlace(args.output, args.fps, args.input)
39for j in range(h):
40 for i in range(w):
41 for fn, f in enumerate(frames):
42 out.putpixel((i, j*N+fn), f.getpixel((i, j)))
43 76
44# When loading this image, the graphics library expects to find a text
45# chunk that specifies how many frames this animation represents. If
46# you post-process the output of this script with some kind of
47# optimizer tool (eg pngcrush or zopflipng) make sure that your
48# optimizer preserves this text chunk.
49 77
50meta = PngImagePlugin.PngInfo() 78if __name__ == '__main__':
51meta.add_text("Frames", str(N)) 79 main(sys.argv[1:])
52 80
53out.save(sys.argv[-1], pnginfo=meta)