The background color is specified to the command as 0xttrrggbb, which is not necessarily the native color format of the framebuffer and thus gu_memset_pixel() will do color conversion.
Instead of redoing the color conversion for every line, let's just do it once in advance and then keep reusing it. Signed-off-by: Ahmad Fatoum <[email protected]> --- commands/splash.c | 9 +++++---- include/gui/graphic_utils.h | 2 ++ lib/gui/graphic_utils.c | 17 ++++++++++------- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/commands/splash.c b/commands/splash.c index 74754392e264..dffe29f92328 100644 --- a/commands/splash.c +++ b/commands/splash.c @@ -63,10 +63,11 @@ static int do_splash(int argc, char *argv[]) buf = gui_screen_render_buffer(sc); if (do_bg) { - int y; - for (y = 0; y < sc->s.height; y++) { - gu_memset_pixel(sc->info, buf + sc->info->line_length * y, - bg_color, sc->s.width); + u32 bg_color_native = gu_hex_to_pixel(sc->info, bg_color); + + for (int y = 0; y < sc->s.height; y++) { + gu_memset_pixel_native(sc->info, buf + sc->info->line_length * y, + bg_color_native, sc->s.width); } } diff --git a/include/gui/graphic_utils.h b/include/gui/graphic_utils.h index 279fdf91d33c..2128222628d4 100644 --- a/include/gui/graphic_utils.h +++ b/include/gui/graphic_utils.h @@ -19,6 +19,8 @@ void gu_set_pixel(struct fb_info *info, void *adr, u32 px); void gu_set_rgb_pixel(struct fb_info *info, void *adr, u8 r, u8 g, u8 b); void gu_set_rgba_pixel(struct fb_info *info, void *adr, u8 r, u8 g, u8 b, u8 a); void gu_memset_pixel(struct fb_info *info, void* buf, u32 color, size_t size); +void gu_memset_pixel_native(struct fb_info *info, void* buf, u32 color_native, + size_t size); struct screen *fb_create_screen(struct fb_info *info); struct screen *fb_open(const char *fbdev); void fb_close(struct screen *sc); diff --git a/lib/gui/graphic_utils.c b/lib/gui/graphic_utils.c index d9f90f3d2ea0..087eba382b93 100644 --- a/lib/gui/graphic_utils.c +++ b/lib/gui/graphic_utils.c @@ -78,27 +78,30 @@ static void memsetl(void *s, u32 c, size_t n) *tmp++ = c; } -void gu_memset_pixel(struct fb_info *info, void* buf, u32 color, size_t size) +void gu_memset_pixel_native(struct fb_info *info, void* buf, u32 color_native, + size_t size) { - u32 px; u8 *screen = buf; - px = gu_hex_to_pixel(info, color); - switch (info->bits_per_pixel) { case 8: - memset(screen, (uint8_t)px, size); + memset(screen, (uint8_t)color_native, size); break; case 16: - memsetw(screen, (uint16_t)px, size); + memsetw(screen, (uint16_t)color_native, size); break; case 32: case 24: - memsetl(screen, px, size); + memsetl(screen, color_native, size); break; } } +void gu_memset_pixel(struct fb_info *info, void* buf, u32 color, size_t size) +{ + gu_memset_pixel_native(info, buf, gu_hex_to_pixel(info, color), size); +} + static void get_rgb_pixel(struct fb_info *info, void *adr, u8 *r ,u8 *g, u8 *b) { u32 px; -- 2.47.3
