recovery: change font for menus to be an image

Instead of representing the font used for menus and log messages in
the recovery binary, load it from a resource PNG image.  This allows
different devices to substitute their own font images.

Change-Id: Ib36b86db3d01298aa7ae2b62a26ca29e6ef18014
diff --git a/minui/resources.c b/minui/resources.c
index 065f431..72f39fb 100644
--- a/minui/resources.c
+++ b/minui/resources.c
@@ -93,22 +93,23 @@
     png_set_sig_bytes(png_ptr, sizeof(header));
     png_read_info(png_ptr, info_ptr);
 
-    size_t width = info_ptr->width;
-    size_t height = info_ptr->height;
-    size_t stride = 4 * width;
-    size_t pixelSize = stride * height;
-
     int color_type = info_ptr->color_type;
     int bit_depth = info_ptr->bit_depth;
     int channels = info_ptr->channels;
     if (!(bit_depth == 8 &&
           ((channels == 3 && color_type == PNG_COLOR_TYPE_RGB) ||
            (channels == 4 && color_type == PNG_COLOR_TYPE_RGBA) ||
-           (channels == 1 && color_type == PNG_COLOR_TYPE_PALETTE)))) {
+           (channels == 1 && (color_type == PNG_COLOR_TYPE_PALETTE ||
+                              color_type == PNG_COLOR_TYPE_GRAY))))) {
         return -7;
         goto exit;
     }
 
+    size_t width = info_ptr->width;
+    size_t height = info_ptr->height;
+    size_t stride = (color_type == PNG_COLOR_TYPE_GRAY ? 1 : 4) * width;
+    size_t pixelSize = stride * height;
+
     surface = malloc(sizeof(GGLSurface) + pixelSize);
     if (surface == NULL) {
         result = -8;
@@ -120,8 +121,8 @@
     surface->height = height;
     surface->stride = width; /* Yes, pixels, not bytes */
     surface->data = pData;
-    surface->format = (channels == 3) ?
-            GGL_PIXEL_FORMAT_RGBX_8888 : GGL_PIXEL_FORMAT_RGBA_8888;
+    surface->format = (channels == 3) ? GGL_PIXEL_FORMAT_RGBX_8888 :
+        ((color_type == PNG_COLOR_TYPE_PALETTE ? GGL_PIXEL_FORMAT_RGBA_8888 : GGL_PIXEL_FORMAT_L_8));
 
     int alpha = 0;
     if (color_type == PNG_COLOR_TYPE_PALETTE) {
@@ -131,6 +132,9 @@
         png_set_tRNS_to_alpha(png_ptr);
         alpha = 1;
     }
+    if (color_type == PNG_COLOR_TYPE_GRAY) {
+        alpha = 1;
+    }
 
     unsigned int y;
     if (channels == 3 || (channels == 1 && !alpha)) {