From 02ec6b88ed4e6cf40cc257572b07c7277b7b6341 Mon Sep 17 00:00:00 2001 From: Doug Zongker Date: Wed, 22 Aug 2012 17:26:40 -0700 Subject: add simple text to recovery UI - recovery takes a --locale argument, which will be passed by the main system - the locale is saved in cache, in case the --locale argument is missing (eg, when recovery is started from fastboot) - we include images that have prerendered text for many locales - we split the background states into four (installing update, erasing, no command, error) so that appropriate text can be shown. Change-Id: I731b8108e83d5ccc09a4aacfc1dbf7e86b397aaf --- minui/resources.c | 150 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) (limited to 'minui/resources.c') diff --git a/minui/resources.c b/minui/resources.c index b437a87cb..af8720a56 100644 --- a/minui/resources.c +++ b/minui/resources.c @@ -33,6 +33,8 @@ #include "minui.h" +extern char* locale; + // libpng gives "undefined reference to 'pow'" errors, and I have no // idea how to convince the build system to link with -lm. We don't // need this functionality (it's used for gamma adjustment) so provide @@ -173,6 +175,154 @@ exit: return result; } +static int matches_locale(const char* loc) { + if (locale == NULL) return 0; + + printf("matching loc=[%s] vs locale=[%s]\n", loc, locale); + + if (strcmp(loc, locale) == 0) return 1; + + // if loc does *not* have an underscore, and it matches the start + // of locale, and the next character in locale *is* an underscore, + // that's a match. For instance, loc == "en" matches locale == + // "en_US". + + int i; + for (i = 0; loc[i] != 0 && loc[i] != '_'; ++i); + if (loc[i] == '_') return 0; + printf(" partial match possible; i = %d\n", i); + + return (strncmp(locale, loc, i) == 0 && locale[i] == '_'); +} + +int res_create_localized_surface(const char* name, gr_surface* pSurface) { + char resPath[256]; + GGLSurface* surface = NULL; + int result = 0; + unsigned char header[8]; + png_structp png_ptr = NULL; + png_infop info_ptr = NULL; + + *pSurface = NULL; + + snprintf(resPath, sizeof(resPath)-1, "/res/images/%s.png", name); + resPath[sizeof(resPath)-1] = '\0'; + FILE* fp = fopen(resPath, "rb"); + if (fp == NULL) { + result = -1; + goto exit; + } + + size_t bytesRead = fread(header, 1, sizeof(header), fp); + if (bytesRead != sizeof(header)) { + result = -2; + goto exit; + } + + if (png_sig_cmp(header, 0, sizeof(header))) { + result = -3; + goto exit; + } + + png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + if (!png_ptr) { + result = -4; + goto exit; + } + + info_ptr = png_create_info_struct(png_ptr); + if (!info_ptr) { + result = -5; + goto exit; + } + + if (setjmp(png_jmpbuf(png_ptr))) { + result = -6; + goto exit; + } + + png_init_io(png_ptr, fp); + 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; + + printf("image size is %d x %d\n", width, height); + + int color_type = info_ptr->color_type; + int bit_depth = info_ptr->bit_depth; + int channels = info_ptr->channels; + printf("color_type %d bit_depth %d channels %d\n", + color_type, bit_depth, channels); + + if (!(bit_depth == 8 && + (channels == 1 && color_type == PNG_COLOR_TYPE_GRAY))) { + return -7; + printf("exiting -7\n"); + goto exit; + } + + unsigned char* row = malloc(width); + int y; + for (y = 0; y < height; ++y) { + png_read_row(png_ptr, row, NULL); + int w = (row[1] << 8) | row[0]; + int h = (row[3] << 8) | row[2]; + int len = row[4]; + char* loc = row+5; + + printf("row %d: %s %d x %d\n", y, loc, w, h); + + if (y+1+h >= height || matches_locale(loc)) { + printf(" taking this one\n"); + + surface = malloc(sizeof(GGLSurface)); + if (surface == NULL) { + result = -8; + goto exit; + } + unsigned char* pData = malloc(w*h); + + surface->version = sizeof(GGLSurface); + surface->width = w; + surface->height = h; + surface->stride = w; /* Yes, pixels, not bytes */ + surface->data = pData; + surface->format = GGL_PIXEL_FORMAT_A_8; + + int i; + for (i = 0; i < h; ++i, ++y) { + png_read_row(png_ptr, row, NULL); + memcpy(pData + i*w, row, w); + } + + *pSurface = (gr_surface) surface; + break; + } else { + printf(" skipping\n"); + int i; + for (i = 0; i < h; ++i, ++y) { + png_read_row(png_ptr, row, NULL); + } + } + } + +exit: + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + + if (fp != NULL) { + fclose(fp); + } + if (result < 0) { + if (surface) { + free(surface); + } + } + return result; +} + void res_free_surface(gr_surface surface) { GGLSurface* pSurface = (GGLSurface*) surface; if (pSurface) { -- cgit v1.2.3 From 8b240ccca1ad32cbd09d3807614f3086914ceaaf Mon Sep 17 00:00:00 2001 From: Doug Zongker Date: Wed, 29 Aug 2012 15:19:29 -0700 Subject: recovery locale handling fixes - change locale filename to "last_locale" so the main system doesn't delete it - clean up some chatty logging - update images with real German (other languages TBD) Change-Id: I2ebb4ed4e054bd1808a3042d9efbb2c18f3a044d --- minui/resources.c | 8 -------- 1 file changed, 8 deletions(-) (limited to 'minui/resources.c') diff --git a/minui/resources.c b/minui/resources.c index af8720a56..b5c99517b 100644 --- a/minui/resources.c +++ b/minui/resources.c @@ -249,18 +249,13 @@ int res_create_localized_surface(const char* name, gr_surface* pSurface) { size_t height = info_ptr->height; size_t stride = 4 * width; - printf("image size is %d x %d\n", width, height); - int color_type = info_ptr->color_type; int bit_depth = info_ptr->bit_depth; int channels = info_ptr->channels; - printf("color_type %d bit_depth %d channels %d\n", - color_type, bit_depth, channels); if (!(bit_depth == 8 && (channels == 1 && color_type == PNG_COLOR_TYPE_GRAY))) { return -7; - printf("exiting -7\n"); goto exit; } @@ -276,8 +271,6 @@ int res_create_localized_surface(const char* name, gr_surface* pSurface) { printf("row %d: %s %d x %d\n", y, loc, w, h); if (y+1+h >= height || matches_locale(loc)) { - printf(" taking this one\n"); - surface = malloc(sizeof(GGLSurface)); if (surface == NULL) { result = -8; @@ -301,7 +294,6 @@ int res_create_localized_surface(const char* name, gr_surface* pSurface) { *pSurface = (gr_surface) surface; break; } else { - printf(" skipping\n"); int i; for (i = 0; i < h; ++i, ++y) { png_read_row(png_ptr, row, NULL); -- cgit v1.2.3 From 52eeea4fa59c15ecb09c32b8e05653f4e55f5188 Mon Sep 17 00:00:00 2001 From: Doug Zongker Date: Tue, 4 Sep 2012 14:28:25 -0700 Subject: minor recovery fixes - protect against missing/malformed bitmaps: fail to display them but don't crash. - don't draw animation overlays until the overlay offset is computed. - logging cleanup Change-Id: Ieb1c155cfbb11e643000bdb5d1a57900c8757739 --- minui/resources.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'minui/resources.c') diff --git a/minui/resources.c b/minui/resources.c index ac7bdac4c..065f4317e 100644 --- a/minui/resources.c +++ b/minui/resources.c @@ -178,8 +178,6 @@ exit: static int matches_locale(const char* loc) { if (locale == NULL) return 0; - printf("matching loc=[%s] vs locale=[%s]\n", loc, locale); - if (strcmp(loc, locale) == 0) return 1; // if loc does *not* have an underscore, and it matches the start @@ -190,7 +188,6 @@ static int matches_locale(const char* loc) { int i; for (i = 0; loc[i] != 0 && loc[i] != '_'; ++i); if (loc[i] == '_') return 0; - printf(" partial match possible; i = %d\n", i); return (strncmp(locale, loc, i) == 0 && locale[i] == '_'); } @@ -268,9 +265,9 @@ int res_create_localized_surface(const char* name, gr_surface* pSurface) { int len = row[4]; char* loc = row+5; - printf("row %d: %s %d x %d\n", y, loc, w, h); - if (y+1+h >= height || matches_locale(loc)) { + printf(" %20s: %s (%d x %d @ %d)\n", name, loc, w, h, y); + surface = malloc(sizeof(GGLSurface)); if (surface == NULL) { result = -8; -- cgit v1.2.3 From 55a36ac1e01205f2cd461cd2f89d92e3b64cddd2 Mon Sep 17 00:00:00 2001 From: Doug Zongker Date: Mon, 4 Mar 2013 15:49:02 -0800 Subject: 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 --- minui/resources.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'minui/resources.c') diff --git a/minui/resources.c b/minui/resources.c index 065f4317e..72f39fbaa 100644 --- a/minui/resources.c +++ b/minui/resources.c @@ -93,22 +93,23 @@ int res_create_surface(const char* name, gr_surface* pSurface) { 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 @@ int res_create_surface(const char* name, gr_surface* pSurface) { 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 @@ int res_create_surface(const char* name, gr_surface* pSurface) { 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)) { -- cgit v1.2.3 From 94fd07ba6d911a446d1d419ad188cbeccc76129a Mon Sep 17 00:00:00 2001 From: John Reck Date: Mon, 26 Aug 2013 16:45:33 -0700 Subject: Update libpng API usage Remove usage of deprecated methods Change-Id: I747568a2c8c0c65ecbc9a3da4bac7b9cac7708ab --- minui/resources.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'minui/resources.c') diff --git a/minui/resources.c b/minui/resources.c index 72f39fbaa..c0a9ccacb 100644 --- a/minui/resources.c +++ b/minui/resources.c @@ -93,9 +93,13 @@ int res_create_surface(const char* name, gr_surface* pSurface) { png_set_sig_bytes(png_ptr, sizeof(header)); png_read_info(png_ptr, info_ptr); - int color_type = info_ptr->color_type; - int bit_depth = info_ptr->bit_depth; - int channels = info_ptr->channels; + int color_type, bit_depth; + size_t width, height; + png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, + &color_type, NULL, NULL, NULL); + + int channels = png_get_channels(png_ptr, info_ptr); + if (!(bit_depth == 8 && ((channels == 3 && color_type == PNG_COLOR_TYPE_RGB) || (channels == 4 && color_type == PNG_COLOR_TYPE_RGBA) || @@ -105,8 +109,6 @@ int res_create_surface(const char* name, gr_surface* pSurface) { 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; @@ -246,13 +248,11 @@ int res_create_localized_surface(const char* name, gr_surface* pSurface) { 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; - - int color_type = info_ptr->color_type; - int bit_depth = info_ptr->bit_depth; - int channels = info_ptr->channels; + int color_type, bit_depth; + size_t width, height; + png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, + &color_type, NULL, NULL, NULL); + int channels = png_get_channels(png_ptr, info_ptr); if (!(bit_depth == 8 && (channels == 1 && color_type == PNG_COLOR_TYPE_GRAY))) { -- cgit v1.2.3