aboutsummaryrefslogtreecommitdiffstats
path: root/interlace-frames.py
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2015-12-11 15:18:51 -0800
committerTao Bao <tbao@google.com>2015-12-16 11:35:52 -0800
commitb723f4f38f53a38502abb1a63165ac0749bc9cd9 (patch)
treec311d658de7ac03080583b24e9157cc6f502f1b4 /interlace-frames.py
parent4e72d1a81e2194caf101dc8633858efaa9bdb39b (diff)
downloadandroid_bootable_recovery-b723f4f38f53a38502abb1a63165ac0749bc9cd9.tar.gz
android_bootable_recovery-b723f4f38f53a38502abb1a63165ac0749bc9cd9.tar.bz2
android_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 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-"""Script to take a set of frames (PNG files) for a recovery animation
-and turn it into a single output image which contains the input frames
-interlaced by row. Run with the names of all the input frames on the
-command line, in order, followed by the name of the output file."""
+"""
+Script to take a set of frames (PNG files) for a recovery animation and turn
+it into a single output image which contains the input frames interlaced by
+row. Run with the names of all the input frames on the command line. Specify
+the name of the output file with -o (or --output), and optionally specify the
+number of frames per second (FPS) with --fps (default: 20).
+e.g.
+interlace-frames.py --fps 20 --output output.png frame0.png frame1.png frame3.png
+"""
+
+from __future__ import print_function
+
+import argparse
import sys
try:
import Image
import PngImagePlugin
except ImportError:
- print "This script requires the Python Imaging Library to be installed."
+ print("This script requires the Python Imaging Library to be installed.")
sys.exit(1)
-frames = [Image.open(fn).convert("RGB") for fn in sys.argv[1:-1]]
-assert len(frames) > 0, "Must have at least one input frame."
-sizes = set()
-for fr in frames:
- sizes.add(fr.size)
-assert len(sizes) == 1, "All input images must have the same size."
-w, h = sizes.pop()
-N = len(frames)
+def interlace(output, fps, inputs):
+ frames = [Image.open(fn).convert("RGB") for fn in inputs]
+ assert len(frames) > 0, "Must have at least one input frame."
+ sizes = set()
+ for fr in frames:
+ sizes.add(fr.size)
+
+ assert len(sizes) == 1, "All input images must have the same size."
+ w, h = sizes.pop()
+ N = len(frames)
+
+ out = Image.new("RGB", (w, h*N))
+ for j in range(h):
+ for i in range(w):
+ for fn, f in enumerate(frames):
+ out.putpixel((i, j*N+fn), f.getpixel((i, j)))
+
+ # When loading this image, the graphics library expects to find a text
+ # chunk that specifies how many frames this animation represents. If
+ # you post-process the output of this script with some kind of
+ # optimizer tool (eg pngcrush or zopflipng) make sure that your
+ # optimizer preserves this text chunk.
+
+ meta = PngImagePlugin.PngInfo()
+ meta.add_text("Frames", str(N))
+ meta.add_text("FPS", str(fps))
+
+ out.save(output, pnginfo=meta)
+
+
+def main(argv):
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--fps', default=20)
+ parser.add_argument('--output', '-o', required=True)
+ parser.add_argument('input', nargs='+')
+ args = parser.parse_args(argv)
-out = Image.new("RGB", (w, h*N))
-for j in range(h):
- for i in range(w):
- for fn, f in enumerate(frames):
- out.putpixel((i, j*N+fn), f.getpixel((i, j)))
+ interlace(args.output, args.fps, args.input)
-# When loading this image, the graphics library expects to find a text
-# chunk that specifies how many frames this animation represents. If
-# you post-process the output of this script with some kind of
-# optimizer tool (eg pngcrush or zopflipng) make sure that your
-# optimizer preserves this text chunk.
-meta = PngImagePlugin.PngInfo()
-meta.add_text("Frames", str(N))
+if __name__ == '__main__':
+ main(sys.argv[1:])
-out.save(sys.argv[-1], pnginfo=meta)