introduce bitmap struct

This commit is contained in:
2022-12-28 21:32:15 +01:00
parent 9af5a84669
commit ab4119a1a9
4 changed files with 84 additions and 54 deletions
+4 -4
View File
@@ -44,18 +44,18 @@ void fb_text_P_or_RAM(fbpos_t x, fbpos_t y, const char *text, uint8_t flags, fbc
// no double, using normal format
#if IS_AVR
fb_bitmap_P(x, y, symw, symh, data, color);
fb_bitmap_ex_P(x, y, symw, symh, data, color);
#else
fb_bitmap(x, y, symw, symh, data, color);
fb_bitmap_ex(x, y, symw, symh, data, color);
#endif
if (flags & FONT_BOLD) {
x++;
#if IS_AVR
fb_bitmap_P(x, y, symw, symh, data, color);
fb_bitmap_ex_P(x, y, symw, symh, data, color);
#else
fb_bitmap(x, y, symw, symh, data, color);
fb_bitmap_ex(x, y, symw, symh, data, color);
#endif
x += symw+2;
+2 -2
View File
@@ -230,9 +230,9 @@ void fb_circle(fbpos_t x0, fbpos_t y0, fbpos_t radius, uint8_t thickness, fbcolo
}
#if IS_AVR
void fb_bitmap_P(fbpos_t x, fbpos_t y, fbpos_t w, fbpos_t h, const uint8_t *map, fbcolor_t color)
void fb_bitmap_ex_P(fbpos_t x, fbpos_t y, fbpos_t w, fbpos_t h, const uint8_t *map, fbcolor_t color)
#else
void fb_bitmap(fbpos_t x, fbpos_t y, fbpos_t w, fbpos_t h, const uint8_t *map, fbcolor_t color)
void fb_bitmap_ex(fbpos_t x, fbpos_t y, fbpos_t w, fbpos_t h, const uint8_t *map, fbcolor_t color)
#endif
{
if (x >= FBW || y >= FBH) { return; }
+24 -3
View File
@@ -13,10 +13,20 @@
#define FBSET 0xFF
#define FBCLEAR 0x00
/// Width/height type
typedef uint16_t fbsize_t;
/// Position type (X/Y)
typedef uint8_t fbpos_t;
/// Color type
typedef uint8_t fbcolor_t;
/// Bitmap struct
typedef struct {
const uint8_t *data;
fbsize_t width;
fbsize_t height;
} fb_bitmap_t;
#define FB_LEN ((FBH / 8) * FBW)
/// Framebuffer backing array.
@@ -69,11 +79,22 @@ void fb_rect(fbpos_t x, fbpos_t y, fbpos_t w, fbpos_t h, fbcolor_t color);
/// Draw a frame (unfilled rect)
void fb_frame(fbpos_t x, fbpos_t y, fbpos_t w, fbpos_t h, fbpos_t thickness, fbcolor_t color);
#if IS_AVR
/// Draw a bitmap from progmem
void fb_bitmap_P(fbpos_t x, fbpos_t y, fbpos_t w, fbpos_t h, const uint8_t *map, fbcolor_t color);
#if IS_AVR
void fb_bitmap_ex_P(fbpos_t x, fbpos_t y, fbpos_t w, fbpos_t h, const uint8_t *map, fbcolor_t color);
#else
void fb_bitmap(fbpos_t x, fbpos_t y, fbpos_t w, fbpos_t h, const uint8_t *map, fbcolor_t color);
void fb_bitmap_ex(fbpos_t x, fbpos_t y, fbpos_t w, fbpos_t h, const uint8_t *map, fbcolor_t color);
#endif
/// Draw a bitmap using the bitmap struct
#if IS_AVR
static inline void fb_bitmap_P(fbpos_t x, fbpos_t y, const fb_bitmap_t *bitmap) {
fb_bitmap_ex_P(x, y, bitmap->width, bitmap->height, bitmap->data, 1);
}
#else
static inline void fb_bitmap(fbpos_t x, fbpos_t y, const fb_bitmap_t *bitmap) {
fb_bitmap_ex(x, y, bitmap->width, bitmap->height, bitmap->data, 1);
}
#endif
/// Draw a circle