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
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
-rw-r--r--interlace-frames.py79
-rw-r--r--minui/minui.h4
-rw-r--r--minui/resources.cpp21
-rw-r--r--res-hdpi/images/icon_installing.pngbin118562 -> 129975 bytes
-rw-r--r--res-mdpi/images/icon_installing.pngbin118562 -> 129975 bytes
-rw-r--r--res-xhdpi/images/icon_installing.pngbin118562 -> 129975 bytes
-rw-r--r--res-xxhdpi/images/icon_installing.pngbin118562 -> 129975 bytes
-rw-r--r--res-xxxhdpi/images/icon_installing.pngbin118562 -> 129975 bytes
-rw-r--r--screen_ui.cpp9
-rw-r--r--screen_ui.h4
-rw-r--r--wear_ui.cpp2
-rw-r--r--wear_ui.h5
12 files changed, 82 insertions, 42 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)
diff --git a/minui/minui.h b/minui/minui.h
index bdde083f..e3bc0054 100644
--- a/minui/minui.h
+++ b/minui/minui.h
@@ -101,8 +101,8 @@ int res_create_display_surface(const char* name, GRSurface** pSurface);
101// should have a 'Frames' text chunk whose value is the number of 101// should have a 'Frames' text chunk whose value is the number of
102// frames this image represents. The pixel data itself is interlaced 102// frames this image represents. The pixel data itself is interlaced
103// by row. 103// by row.
104int res_create_multi_display_surface(const char* name, 104int res_create_multi_display_surface(const char* name, int* frames,
105 int* frames, GRSurface*** pSurface); 105 int* fps, GRSurface*** pSurface);
106 106
107// Load a single alpha surface from a grayscale PNG image. 107// Load a single alpha surface from a grayscale PNG image.
108int res_create_alpha_surface(const char* name, GRSurface** pSurface); 108int res_create_alpha_surface(const char* name, GRSurface** pSurface);
diff --git a/minui/resources.cpp b/minui/resources.cpp
index 5e478927..63a0dff2 100644
--- a/minui/resources.cpp
+++ b/minui/resources.cpp
@@ -237,14 +237,14 @@ int res_create_display_surface(const char* name, GRSurface** pSurface) {
237 return result; 237 return result;
238} 238}
239 239
240int res_create_multi_display_surface(const char* name, int* frames, GRSurface*** pSurface) { 240int res_create_multi_display_surface(const char* name, int* frames, int* fps,
241 GRSurface*** pSurface) {
241 GRSurface** surface = NULL; 242 GRSurface** surface = NULL;
242 int result = 0; 243 int result = 0;
243 png_structp png_ptr = NULL; 244 png_structp png_ptr = NULL;
244 png_infop info_ptr = NULL; 245 png_infop info_ptr = NULL;
245 png_uint_32 width, height; 246 png_uint_32 width, height;
246 png_byte channels; 247 png_byte channels;
247 int i;
248 png_textp text; 248 png_textp text;
249 int num_text; 249 int num_text;
250 unsigned char* p_row; 250 unsigned char* p_row;
@@ -257,14 +257,23 @@ int res_create_multi_display_surface(const char* name, int* frames, GRSurface***
257 if (result < 0) return result; 257 if (result < 0) return result;
258 258
259 *frames = 1; 259 *frames = 1;
260 *fps = 20;
260 if (png_get_text(png_ptr, info_ptr, &text, &num_text)) { 261 if (png_get_text(png_ptr, info_ptr, &text, &num_text)) {
261 for (i = 0; i < num_text; ++i) { 262 for (int i = 0; i < num_text; ++i) {
262 if (text[i].key && strcmp(text[i].key, "Frames") == 0 && text[i].text) { 263 if (text[i].key && strcmp(text[i].key, "Frames") == 0 && text[i].text) {
263 *frames = atoi(text[i].text); 264 *frames = atoi(text[i].text);
264 break; 265 } else if (text[i].key && strcmp(text[i].key, "FPS") == 0 && text[i].text) {
266 *fps = atoi(text[i].text);
265 } 267 }
266 } 268 }
267 printf(" found frames = %d\n", *frames); 269 printf(" found frames = %d\n", *frames);
270 printf(" found fps = %d\n", *fps);
271 }
272
273 if (frames <= 0 || fps <= 0) {
274 printf("bad number of frames (%d) and/or FPS (%d)\n", *frames, *fps);
275 result = -10;
276 goto exit;
268 } 277 }
269 278
270 if (height % *frames != 0) { 279 if (height % *frames != 0) {
@@ -278,7 +287,7 @@ int res_create_multi_display_surface(const char* name, int* frames, GRSurface***
278 result = -8; 287 result = -8;
279 goto exit; 288 goto exit;
280 } 289 }
281 for (i = 0; i < *frames; ++i) { 290 for (int i = 0; i < *frames; ++i) {
282 surface[i] = init_display_surface(width, height / *frames); 291 surface[i] = init_display_surface(width, height / *frames);
283 if (surface[i] == NULL) { 292 if (surface[i] == NULL) {
284 result = -8; 293 result = -8;
@@ -307,7 +316,7 @@ exit:
307 316
308 if (result < 0) { 317 if (result < 0) {
309 if (surface) { 318 if (surface) {
310 for (i = 0; i < *frames; ++i) { 319 for (int i = 0; i < *frames; ++i) {
311 if (surface[i]) free(surface[i]); 320 if (surface[i]) free(surface[i]);
312 } 321 }
313 free(surface); 322 free(surface);
diff --git a/res-hdpi/images/icon_installing.png b/res-hdpi/images/icon_installing.png
index c2c02016..0fcfbc23 100644
--- a/res-hdpi/images/icon_installing.png
+++ b/res-hdpi/images/icon_installing.png
Binary files differ
diff --git a/res-mdpi/images/icon_installing.png b/res-mdpi/images/icon_installing.png
index c2c02016..0fcfbc23 100644
--- a/res-mdpi/images/icon_installing.png
+++ b/res-mdpi/images/icon_installing.png
Binary files differ
diff --git a/res-xhdpi/images/icon_installing.png b/res-xhdpi/images/icon_installing.png
index c2c02016..0fcfbc23 100644
--- a/res-xhdpi/images/icon_installing.png
+++ b/res-xhdpi/images/icon_installing.png
Binary files differ
diff --git a/res-xxhdpi/images/icon_installing.png b/res-xxhdpi/images/icon_installing.png
index c2c02016..0fcfbc23 100644
--- a/res-xxhdpi/images/icon_installing.png
+++ b/res-xxhdpi/images/icon_installing.png
Binary files differ
diff --git a/res-xxxhdpi/images/icon_installing.png b/res-xxxhdpi/images/icon_installing.png
index c2c02016..0fcfbc23 100644
--- a/res-xxxhdpi/images/icon_installing.png
+++ b/res-xxxhdpi/images/icon_installing.png
Binary files differ
diff --git a/screen_ui.cpp b/screen_ui.cpp
index 23fc9015..522aa6b2 100644
--- a/screen_ui.cpp
+++ b/screen_ui.cpp
@@ -73,7 +73,7 @@ ScreenRecoveryUI::ScreenRecoveryUI() :
73 menu_items(0), 73 menu_items(0),
74 menu_sel(0), 74 menu_sel(0),
75 file_viewer_text_(nullptr), 75 file_viewer_text_(nullptr),
76 animation_fps(20), 76 animation_fps(-1),
77 installing_frames(-1), 77 installing_frames(-1),
78 stage(-1), 78 stage(-1),
79 max_stage(-1) { 79 max_stage(-1) {
@@ -367,8 +367,9 @@ void ScreenRecoveryUI::LoadBitmap(const char* filename, GRSurface** surface) {
367 } 367 }
368} 368}
369 369
370void ScreenRecoveryUI::LoadBitmapArray(const char* filename, int* frames, GRSurface*** surface) { 370void ScreenRecoveryUI::LoadBitmapArray(const char* filename, int* frames, int* fps,
371 int result = res_create_multi_display_surface(filename, frames, surface); 371 GRSurface*** surface) {
372 int result = res_create_multi_display_surface(filename, frames, fps, surface);
372 if (result < 0) { 373 if (result < 0) {
373 LOGE("missing bitmap %s\n(Code %d)\n", filename, result); 374 LOGE("missing bitmap %s\n(Code %d)\n", filename, result);
374 } 375 }
@@ -405,7 +406,7 @@ void ScreenRecoveryUI::Init() {
405 text_top_ = 1; 406 text_top_ = 1;
406 407
407 backgroundIcon[NONE] = nullptr; 408 backgroundIcon[NONE] = nullptr;
408 LoadBitmapArray("icon_installing", &installing_frames, &installation); 409 LoadBitmapArray("icon_installing", &installing_frames, &animation_fps, &installation);
409 backgroundIcon[INSTALLING_UPDATE] = installing_frames ? installation[0] : nullptr; 410 backgroundIcon[INSTALLING_UPDATE] = installing_frames ? installation[0] : nullptr;
410 backgroundIcon[ERASING] = backgroundIcon[INSTALLING_UPDATE]; 411 backgroundIcon[ERASING] = backgroundIcon[INSTALLING_UPDATE];
411 LoadBitmap("icon_error", &backgroundIcon[ERROR]); 412 LoadBitmap("icon_error", &backgroundIcon[ERROR]);
diff --git a/screen_ui.h b/screen_ui.h
index 8e18864d..08a5f44a 100644
--- a/screen_ui.h
+++ b/screen_ui.h
@@ -109,6 +109,8 @@ class ScreenRecoveryUI : public RecoveryUI {
109 109
110 pthread_t progress_thread_; 110 pthread_t progress_thread_;
111 111
112 // The following two are parsed from the image file
113 // (e.g. '/res/images/icon_installing.png').
112 int animation_fps; 114 int animation_fps;
113 int installing_frames; 115 int installing_frames;
114 116
@@ -135,7 +137,7 @@ class ScreenRecoveryUI : public RecoveryUI {
135 void DrawTextLines(int* y, const char* const* lines); 137 void DrawTextLines(int* y, const char* const* lines);
136 138
137 void LoadBitmap(const char* filename, GRSurface** surface); 139 void LoadBitmap(const char* filename, GRSurface** surface);
138 void LoadBitmapArray(const char* filename, int* frames, GRSurface*** surface); 140 void LoadBitmapArray(const char* filename, int* frames, int* fps, GRSurface*** surface);
139 void LoadLocalizedBitmap(const char* filename, GRSurface** surface); 141 void LoadLocalizedBitmap(const char* filename, GRSurface** surface);
140}; 142};
141 143
diff --git a/wear_ui.cpp b/wear_ui.cpp
index 3ee38e8a..50aeb384 100644
--- a/wear_ui.cpp
+++ b/wear_ui.cpp
@@ -61,10 +61,10 @@ WearRecoveryUI::WearRecoveryUI() :
61 menu_unusable_rows(0), 61 menu_unusable_rows(0),
62 intro_frames(22), 62 intro_frames(22),
63 loop_frames(60), 63 loop_frames(60),
64 animation_fps(30),
64 currentIcon(NONE), 65 currentIcon(NONE),
65 intro_done(false), 66 intro_done(false),
66 current_frame(0), 67 current_frame(0),
67 animation_fps(30),
68 rtl_locale(false), 68 rtl_locale(false),
69 progressBarType(EMPTY), 69 progressBarType(EMPTY),
70 progressScopeStart(0), 70 progressScopeStart(0),
diff --git a/wear_ui.h b/wear_ui.h
index 839a2643..63c1b6e6 100644
--- a/wear_ui.h
+++ b/wear_ui.h
@@ -79,6 +79,9 @@ class WearRecoveryUI : public RecoveryUI {
79 int intro_frames; 79 int intro_frames;
80 int loop_frames; 80 int loop_frames;
81 81
82 // Number of frames per sec (default: 30) for both of intro and loop.
83 int animation_fps;
84
82 private: 85 private:
83 Icon currentIcon; 86 Icon currentIcon;
84 87
@@ -86,8 +89,6 @@ class WearRecoveryUI : public RecoveryUI {
86 89
87 int current_frame; 90 int current_frame;
88 91
89 int animation_fps;
90
91 bool rtl_locale; 92 bool rtl_locale;
92 93
93 pthread_mutex_t updateMutex; 94 pthread_mutex_t updateMutex;