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
diff --git a/minui/resources.cpp b/minui/resources.cpp
index 5e47892..63a0dff 100644
--- a/minui/resources.cpp
+++ b/minui/resources.cpp
@@ -237,14 +237,14 @@
     return result;
 }
 
-int res_create_multi_display_surface(const char* name, int* frames, GRSurface*** pSurface) {
+int res_create_multi_display_surface(const char* name, int* frames, int* fps,
+        GRSurface*** pSurface) {
     GRSurface** surface = NULL;
     int result = 0;
     png_structp png_ptr = NULL;
     png_infop info_ptr = NULL;
     png_uint_32 width, height;
     png_byte channels;
-    int i;
     png_textp text;
     int num_text;
     unsigned char* p_row;
@@ -257,14 +257,23 @@
     if (result < 0) return result;
 
     *frames = 1;
+    *fps = 20;
     if (png_get_text(png_ptr, info_ptr, &text, &num_text)) {
-        for (i = 0; i < num_text; ++i) {
+        for (int i = 0; i < num_text; ++i) {
             if (text[i].key && strcmp(text[i].key, "Frames") == 0 && text[i].text) {
                 *frames = atoi(text[i].text);
-                break;
+            } else if (text[i].key && strcmp(text[i].key, "FPS") == 0 && text[i].text) {
+                *fps = atoi(text[i].text);
             }
         }
         printf("  found frames = %d\n", *frames);
+        printf("  found fps = %d\n", *fps);
+    }
+
+    if (frames <= 0 || fps <= 0) {
+        printf("bad number of frames (%d) and/or FPS (%d)\n", *frames, *fps);
+        result = -10;
+        goto exit;
     }
 
     if (height % *frames != 0) {
@@ -278,7 +287,7 @@
         result = -8;
         goto exit;
     }
-    for (i = 0; i < *frames; ++i) {
+    for (int i = 0; i < *frames; ++i) {
         surface[i] = init_display_surface(width, height / *frames);
         if (surface[i] == NULL) {
             result = -8;
@@ -307,7 +316,7 @@
 
     if (result < 0) {
         if (surface) {
-            for (i = 0; i < *frames; ++i) {
+            for (int i = 0; i < *frames; ++i) {
                 if (surface[i]) free(surface[i]);
             }
             free(surface);