diff options
authorDoug Zongker2014-03-11 14:39:33 -0500
committerDoug Zongker2014-03-11 14:39:33 -0500
commit5120c9fbb60d6625ec2588d77f13953884bb1a93 (patch)
tree6266e3e3d2d1c8c329b4e09ed8c164b152534d66 /interlace-frames.py
parent39cf417e17011a72dd39acfe4cc8c90af26bdbaf (diff)
update tools for making recovery images
We no longer render animations as a base image with a possibly-partially-transparent overlay drawn over it, so delete the make-overlay.py tool. Now we represent them as series of images that are interlaced by row (with a special text chunk in the PNG file specifying the number of frames) so add the interlace-frames.py tool to make those. Change-Id: I79443f125f9c7d8d61cd09e3434745e0ef38893f
Diffstat (limited to 'interlace-frames.py')
1 files changed, 53 insertions, 0 deletions
diff --git a/interlace-frames.py b/interlace-frames.py
new file mode 100644
index 00000000..243e565e
--- /dev/null
+++ b/interlace-frames.py
@@ -0,0 +1,53 @@
1# Copyright (C) 2014 The Android Open Source Project
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
7# http://www.apache.org/licenses/LICENSE-2.0
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
15"""Script to take a set of frames (PNG files) for a recovery animation
16and turn it into a single output image which contains the input frames
17interlaced by row. Run with the names of all the input frames on the
18command line, in order, followed by the name of the output file."""
20import sys
22 import Image
23 import PngImagePlugin
24except ImportError:
25 print "This script requires the Python Imaging Library to be installed."
26 sys.exit(1)
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)
34assert len(sizes) == 1, "All input images must have the same size."
35w, h = sizes.pop()
36N = len(frames)
38out = Image.new("RGB", (w, h*N))
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)))
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.
50meta = PngImagePlugin.PngInfo()
51meta.add_text("Frames", str(N))
53out.save(sys.argv[-1], pnginfo=meta)