diff options
author | Xin Li <delphij@google.com> | 2022-08-16 21:08:21 +0200 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2022-08-16 21:08:21 +0200 |
commit | 266e0ce537b00216aa49ab61cdee8c83ebaa249e (patch) | |
tree | 4276f71c50cfa45742e050fd62c1682cacc8daad /minui/resources.cpp | |
parent | Merge "Fix misconfigured recovery host test" (diff) | |
parent | DO NOT MERGE - Merge Android 13 (diff) | |
download | android_bootable_recovery-266e0ce537b00216aa49ab61cdee8c83ebaa249e.tar android_bootable_recovery-266e0ce537b00216aa49ab61cdee8c83ebaa249e.tar.gz android_bootable_recovery-266e0ce537b00216aa49ab61cdee8c83ebaa249e.tar.bz2 android_bootable_recovery-266e0ce537b00216aa49ab61cdee8c83ebaa249e.tar.lz android_bootable_recovery-266e0ce537b00216aa49ab61cdee8c83ebaa249e.tar.xz android_bootable_recovery-266e0ce537b00216aa49ab61cdee8c83ebaa249e.tar.zst android_bootable_recovery-266e0ce537b00216aa49ab61cdee8c83ebaa249e.zip |
Diffstat (limited to '')
-rw-r--r-- | minui/resources.cpp | 56 |
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); |