summaryrefslogtreecommitdiffstats
path: root/minui
diff options
context:
space:
mode:
authorTianjie Xu <xunchang@google.com>2017-09-27 19:49:17 +0200
committerandroid-build-merger <android-build-merger@google.com>2017-09-27 19:49:17 +0200
commit5e969aa10d5ab75e52dccaebbb367473a586f642 (patch)
tree4ce018893e091c21392e022432a50b4a84eb79cd /minui
parentMerge "clang-format: Remove the override of PenaltyExcessCharacter." am: 151f0820ac (diff)
parentMerge "Add a new option in recovery menu to test the background texts" (diff)
downloadandroid_bootable_recovery-5e969aa10d5ab75e52dccaebbb367473a586f642.tar
android_bootable_recovery-5e969aa10d5ab75e52dccaebbb367473a586f642.tar.gz
android_bootable_recovery-5e969aa10d5ab75e52dccaebbb367473a586f642.tar.bz2
android_bootable_recovery-5e969aa10d5ab75e52dccaebbb367473a586f642.tar.lz
android_bootable_recovery-5e969aa10d5ab75e52dccaebbb367473a586f642.tar.xz
android_bootable_recovery-5e969aa10d5ab75e52dccaebbb367473a586f642.tar.zst
android_bootable_recovery-5e969aa10d5ab75e52dccaebbb367473a586f642.zip
Diffstat (limited to 'minui')
-rw-r--r--minui/include/minui/minui.h4
-rw-r--r--minui/resources.cpp35
2 files changed, 39 insertions, 0 deletions
diff --git a/minui/include/minui/minui.h b/minui/include/minui/minui.h
index 017ddde75..27e603136 100644
--- a/minui/include/minui/minui.h
+++ b/minui/include/minui/minui.h
@@ -21,6 +21,7 @@
#include <functional>
#include <string>
+#include <vector>
//
// Graphics.
@@ -129,6 +130,9 @@ int res_create_alpha_surface(const char* name, GRSurface** pSurface);
int res_create_localized_alpha_surface(const char* name, const char* locale,
GRSurface** pSurface);
+// Return a list of locale strings embedded in |png_name|. Return a empty list in case of failure.
+std::vector<std::string> get_locales_in_png(const std::string& png_name);
+
// Free a surface allocated by any of the res_create_*_surface()
// functions.
void res_free_surface(GRSurface* surface);
diff --git a/minui/resources.cpp b/minui/resources.cpp
index 8f8d36d27..756f29d21 100644
--- a/minui/resources.cpp
+++ b/minui/resources.cpp
@@ -396,6 +396,41 @@ bool matches_locale(const std::string& prefix, const std::string& locale) {
return std::regex_match(locale, loc_regex);
}
+std::vector<std::string> get_locales_in_png(const std::string& png_name) {
+ png_structp png_ptr = nullptr;
+ png_infop info_ptr = nullptr;
+ png_uint_32 width, height;
+ png_byte channels;
+
+ int status = open_png(png_name.c_str(), &png_ptr, &info_ptr, &width, &height, &channels);
+ if (status < 0) {
+ printf("Failed to open %s\n", png_name.c_str());
+ return {};
+ }
+ if (channels != 1) {
+ printf("Expect input png to have 1 data channel, this file has %d\n", channels);
+ png_destroy_read_struct(&png_ptr, &info_ptr, nullptr);
+ return {};
+ }
+
+ std::vector<std::string> result;
+ std::vector<unsigned char> row(width);
+ for (png_uint_32 y = 0; y < height; ++y) {
+ png_read_row(png_ptr, row.data(), nullptr);
+ int h = (row[3] << 8) | row[2];
+ std::string loc(reinterpret_cast<char*>(&row[5]));
+ if (!loc.empty()) {
+ result.push_back(loc);
+ }
+ for (int i = 0; i < h; ++i, ++y) {
+ png_read_row(png_ptr, row.data(), NULL);
+ }
+ }
+
+ png_destroy_read_struct(&png_ptr, &info_ptr, nullptr);
+ return result;
+}
+
int res_create_localized_alpha_surface(const char* name,
const char* locale,
GRSurface** pSurface) {