From 73f26ca0846058d9879ab16f01b25139d2000a08 Mon Sep 17 00:00:00 2001 From: jianglianfang Date: Mon, 6 May 2024 14:59:09 +0800 Subject: [PATCH] fb: supported bpp = 24 Added new draw_rect24 function to support bpp=24 devices. Signed-off-by: jianglianfang --- examples/fb/fb_main.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/examples/fb/fb_main.c b/examples/fb/fb_main.c index 09896c94f..2d3f998dc 100644 --- a/examples/fb/fb_main.c +++ b/examples/fb/fb_main.c @@ -176,8 +176,9 @@ static int fbdev_get_pinfo(int fd, FAR struct fb_planeinfo_s *pinfo) * certain color formats are supported. */ - if (pinfo->bpp != 32 && pinfo->bpp != 16 && - pinfo->bpp != 8 && pinfo->bpp != 1) + if (pinfo->bpp != 32 && pinfo->bpp != 24 && + pinfo->bpp != 16 && pinfo->bpp != 8 && + pinfo->bpp != 1) { fprintf(stderr, "ERROR: bpp=%u not supported\n", pinfo->bpp); return EXIT_FAILURE; @@ -275,6 +276,29 @@ static void draw_rect32(FAR struct fb_state_s *state, } } +static void draw_rect24(FAR struct fb_state_s *state, + FAR struct fb_area_s *area, int color) +{ + FAR uint8_t *dest; + FAR uint8_t *row; + int x; + int y; + + row = (FAR uint8_t *)state->fbmem + state->pinfo.stride * area->y; + for (y = 0; y < area->h; y++) + { + dest = ((FAR uint8_t *)row) + area->x * 3; + for (x = 0; x < area->w; x++) + { + *dest++ = g_rgb24[color] & 0xff; + *dest++ = (g_rgb24[color] >> 8) & 0xff; + *dest++ = (g_rgb24[color] >> 16) & 0xff; + } + + row += state->pinfo.stride; + } +} + static void draw_rect16(FAR struct fb_state_s *state, FAR struct fb_area_s *area, int color) { @@ -411,6 +435,10 @@ static void draw_rect(FAR struct fb_state_s *state, draw_rect32(state, area, color); break; + case 24: + draw_rect24(state, area, color); + break; + case 16: draw_rect16(state, area, color); break;