summaryrefslogtreecommitdiffstats
path: root/minui/resources.cpp
diff options
context:
space:
mode:
authorPatrik Torstensson <totte@google.com>2021-01-31 03:16:25 +0100
committerHaiping Yang <haiping@google.com>2021-12-06 04:09:47 +0100
commit51433b94f074de7287bcdd064996d9809c9e0de9 (patch)
tree90390b7b17a7fc232ede521fa194fa5aec47d7bc /minui/resources.cpp
parentMerge "Add erofs tools in recovery mode" am: 90064ac238 am: 0e04a02326 am: 41ec1b368a am: 9254de8e9d (diff)
downloadandroid_bootable_recovery-51433b94f074de7287bcdd064996d9809c9e0de9.tar
android_bootable_recovery-51433b94f074de7287bcdd064996d9809c9e0de9.tar.gz
android_bootable_recovery-51433b94f074de7287bcdd064996d9809c9e0de9.tar.bz2
android_bootable_recovery-51433b94f074de7287bcdd064996d9809c9e0de9.tar.lz
android_bootable_recovery-51433b94f074de7287bcdd064996d9809c9e0de9.tar.xz
android_bootable_recovery-51433b94f074de7287bcdd064996d9809c9e0de9.tar.zst
android_bootable_recovery-51433b94f074de7287bcdd064996d9809c9e0de9.zip
Diffstat (limited to '')
-rw-r--r--minui/resources.cpp56
1 files changed, 40 insertions, 16 deletions
diff --git a/minui/resources.cpp b/minui/resources.cpp
index d7b927700..1521c8f17 100644
--- a/minui/resources.cpp
+++ b/minui/resources.cpp
@@ -153,32 +153,57 @@ static void TransformRgbToDraw(const uint8_t* input_row, uint8_t* output_row, in
int width) {
const uint8_t* ip = input_row;
uint8_t* op = output_row;
+ PixelFormat pixel_format = gr_pixel_format();
switch (channels) {
case 1:
// expand gray level to RGBX
for (int x = 0; x < width; ++x) {
- *op++ = *ip;
- *op++ = *ip;
- *op++ = *ip;
- *op++ = 0xff;
+ if (pixel_format == PixelFormat::RGBA) {
+ *op++ = 0xff;
+ *op++ = *ip;
+ *op++ = *ip;
+ *op++ = *ip;
+ } else {
+ *op++ = *ip;
+ *op++ = *ip;
+ *op++ = *ip;
+ *op++ = 0xff;
+ }
ip++;
}
break;
case 3:
- // expand RGBA to RGBX
for (int x = 0; x < width; ++x) {
- *op++ = *ip++;
- *op++ = *ip++;
- *op++ = *ip++;
- *op++ = 0xff;
+ // expand RGBA to RGBX
+ if (pixel_format == PixelFormat::RGBA) {
+ *op++ = 0xff;
+ *op++ = *ip++;
+ *op++ = *ip++;
+ *op++ = *ip++;
+ } else {
+ *op++ = *ip++;
+ *op++ = *ip++;
+ *op++ = *ip++;
+ *op++ = 0xff;
+ }
}
break;
case 4:
- // copy RGBA to RGBX
- memcpy(output_row, input_row, width * 4);
+ if (pixel_format == PixelFormat::RGBA) {
+ for (int x = 0; x < width; ++x) {
+ *op++ = *(ip + 3);
+ *op++ = *ip++;
+ *op++ = *ip++;
+ *op++ = *ip++;
+ ip++;
+ }
+ } else {
+ // copy RGBA to RGBX
+ memcpy(output_row, input_row, width * 4);
+ }
break;
}
}
@@ -201,6 +226,8 @@ int res_create_display_surface(const char* name, GRSurface** pSurface) {
PixelFormat pixel_format = gr_pixel_format();
if (pixel_format == PixelFormat::ARGB || pixel_format == PixelFormat::BGRA) {
png_set_bgr(png_ptr);
+ } else if (pixel_format == PixelFormat::RGBA) {
+ png_set_swap_alpha(png_ptr);
}
for (png_uint_32 y = 0; y < height; ++y) {
@@ -273,6 +300,8 @@ int res_create_multi_display_surface(const char* name, int* frames, int* fps,
if (gr_pixel_format() == PixelFormat::ARGB || gr_pixel_format() == PixelFormat::BGRA) {
png_set_bgr(png_ptr);
+ } else if (gr_pixel_format() == PixelFormat::RGBA) {
+ png_set_swap_alpha(png_ptr);
}
for (png_uint_32 y = 0; y < height; ++y) {
@@ -316,11 +345,6 @@ int res_create_alpha_surface(const char* name, GRSurface** pSurface) {
return -8;
}
- PixelFormat pixel_format = gr_pixel_format();
- if (pixel_format == PixelFormat::ARGB || pixel_format == PixelFormat::BGRA) {
- png_set_bgr(png_ptr);
- }
-
for (png_uint_32 y = 0; y < height; ++y) {
uint8_t* p_row = surface->data() + y * surface->row_bytes;
png_read_row(png_ptr, p_row, nullptr);