Skip to content

Commit 8b3bdef

Browse files
committed
Add support for drawing to more frame buffer formats
1 parent e3dd5b7 commit 8b3bdef

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

Diff for: components/fb_gfx/fb_gfx.c

+13-6
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,24 @@ typedef struct { // Data stored for FONT AS A WHOLE:
3838

3939
void fb_gfx_fillRect(fb_data_t *fb, int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color)
4040
{
41-
int32_t line_step = (fb->width - w) * 3;
42-
uint8_t *data = fb->data + ((x + (y * fb->width)) * 3);
41+
int32_t line_step = (fb->width - w) * fb->bytes_per_pixel;
42+
uint8_t *data = fb->data + ((x + (y * fb->width)) * fb->bytes_per_pixel);
4343
uint8_t c0 = color >> 16;
4444
uint8_t c1 = color >> 8;
4545
uint8_t c2 = color;
4646
for (int i=0; i<h; i++){
4747
for (int j=0; j<w; j++){
48-
data[0] = c0;
49-
data[1] = c1;
50-
data[2] = c2;
51-
data+=3;
48+
if(fb->bytes_per_pixel == 2){
49+
data[0] = c1;
50+
data[1] = c2;
51+
} else if(fb->bytes_per_pixel == 1){
52+
data[0] = c2;
53+
} else {
54+
data[0] = c0;
55+
data[1] = c1;
56+
data[2] = c2;
57+
}
58+
data+=fb->bytes_per_pixel;
5259
}
5360
data += line_step;
5461
}

Diff for: components/fb_gfx/include/fb_gfx.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ extern "C" {
1919
#endif
2020

2121
typedef enum {
22-
FB_RGB888, FB_BGR888, FB_RGB565, FB_BGR565
22+
FB_RGB888, FB_BGR888, FB_RGB565, FB_BGR565, FB_GRAY
2323
} fb_format_t;
2424

2525
typedef struct {

0 commit comments

Comments
 (0)