🎨 update the input format of fb_gfx

pull/190/head
yuanjiong 2021-10-20 20:18:52 +08:00
parent 0266875718
commit c559f7fc32
3 changed files with 67 additions and 32 deletions

View File

@ -1,5 +1,10 @@
set(COMPONENT_SRCS "fb_gfx.c")
set(COMPONENT_ADD_INCLUDEDIRS "include")
set(COMPONENT_PRIV_INCLUDEDIRS "")
set(COMPONENT_PRIV_REQUIRES newlib)
register_component()
# set(COMPONENT_SRCS "fb_gfx.c")
# set(COMPONENT_ADD_INCLUDEDIRS "include")
# set(COMPONENT_PRIV_INCLUDEDIRS "")
# set(COMPONENT_PRIV_REQUIRES newlib)
# register_component()
set(src_dirs .)
set(include_dirs .
./include)
set(requires esp32-camera)
idf_component_register(SRC_DIRS ${src_dirs} INCLUDE_DIRS ${include_dirs} REQUIRES ${requires})

View File

@ -38,10 +38,24 @@ typedef struct
#include "FreeMonoBold12pt7b.h" //14x24
#define gfxFont ((GFXfont *)(&FreeMonoBold12pt7b))
void fb_gfx_fillRect(fb_data_t *fb, int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color)
void fb_gfx_fillRect(camera_fb_t *fb, int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color)
{
int bytes_per_pixel = 0;
switch (fb->format)
{
case PIXFORMAT_GRAYSCALE:
bytes_per_pixel = 1;
break;
case PIXFORMAT_RGB565:
bytes_per_pixel = 2;
break;
case PIXFORMAT_RGB888:
bytes_per_pixel = 3;
default:
break;
}
int32_t line_step = (fb->width - w) * 3;
uint8_t *data = fb->data + ((x + (y * fb->width)) * 3);
uint8_t *data = fb->buf + ((x + (y * fb->width)) * bytes_per_pixel);
uint8_t c0 = color >> 16;
uint8_t c1 = color >> 8;
uint8_t c2 = color;
@ -49,26 +63,41 @@ void fb_gfx_fillRect(fb_data_t *fb, int32_t x, int32_t y, int32_t w, int32_t h,
{
for (int j = 0; j < w; j++)
{
switch (bytes_per_pixel)
{
case 1:
data[0] = c2;
data++;
break;
case 2:
data[0] = c1;
data[1] = c2;
data += 2;
break;
case 3:
data[0] = c0;
data[1] = c1;
data[2] = c2;
data += 3;
default:
break;
}
}
data += line_step;
}
}
void fb_gfx_drawFastHLine(fb_data_t *fb, int32_t x, int32_t y, int32_t w, uint32_t color)
void fb_gfx_drawFastHLine(camera_fb_t *fb, int32_t x, int32_t y, int32_t w, uint32_t color)
{
fb_gfx_fillRect(fb, x, y, w, 1, color);
}
void fb_gfx_drawFastVLine(fb_data_t *fb, int32_t x, int32_t y, int32_t h, uint32_t color)
void fb_gfx_drawFastVLine(camera_fb_t *fb, int32_t x, int32_t y, int32_t h, uint32_t color)
{
fb_gfx_fillRect(fb, x, y, 1, h, color);
}
uint8_t fb_gfx_putc(fb_data_t *fb, int32_t x, int32_t y, uint32_t color, unsigned char c)
uint8_t fb_gfx_putc(camera_fb_t *fb, int32_t x, int32_t y, uint32_t color, unsigned char c)
{
uint16_t line_width;
uint8_t xa = 0, bit = 0, bits = 0, xx, yy;
@ -120,7 +149,7 @@ uint8_t fb_gfx_putc(fb_data_t *fb, int32_t x, int32_t y, uint32_t color, unsigne
return xa;
}
uint32_t fb_gfx_print(fb_data_t *fb, int x, int y, uint32_t color, const char *str)
uint32_t fb_gfx_print(camera_fb_t *fb, int x, int y, uint32_t color, const char *str)
{
uint32_t l = 0;
int xc = x, yc = y, lc = fb->width - gfxFont->glyph[0].xAdvance;
@ -151,7 +180,7 @@ uint32_t fb_gfx_print(fb_data_t *fb, int x, int y, uint32_t color, const char *s
return l;
}
uint32_t fb_gfx_printf(fb_data_t *fb, int32_t x, int32_t y, uint32_t color, const char *format, ...)
uint32_t fb_gfx_printf(camera_fb_t *fb, int32_t x, int32_t y, uint32_t color, const char *format, ...)
{
char loc_buf[64];
char *temp = loc_buf;

View File

@ -13,29 +13,30 @@
// limitations under the License.
#ifndef _FB_GFX_H_
#define _FB_GFX_H_
#include "esp_camera.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
FB_RGB888, FB_BGR888, FB_RGB565, FB_BGR565
} fb_format_t;
// typedef enum {
// FB_RGB888, FB_BGR888, FB_RGB565, FB_BGR565
// } fb_format_t;
typedef struct {
int width;
int height;
int bytes_per_pixel;
fb_format_t format;
uint8_t * data;
} fb_data_t;
// typedef struct {
// int width;
// int height;
// int bytes_per_pixel;
// fb_format_t format;
// uint8_t * data;
// } fb_data_t;
void fb_gfx_fillRect (fb_data_t *fb, int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color);
void fb_gfx_drawFastHLine(fb_data_t *fb, int32_t x, int32_t y, int32_t w, uint32_t color);
void fb_gfx_drawFastVLine(fb_data_t *fb, int32_t x, int32_t y, int32_t h, uint32_t color);
uint8_t fb_gfx_putc (fb_data_t *fb, int32_t x, int32_t y, uint32_t color, unsigned char c);
uint32_t fb_gfx_print (fb_data_t *fb, int32_t x, int32_t y, uint32_t color, const char * str);
uint32_t fb_gfx_printf (fb_data_t *fb, int32_t x, int32_t y, uint32_t color, const char *format, ...);
void fb_gfx_fillRect (camera_fb_t *fb, int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color);
void fb_gfx_drawFastHLine(camera_fb_t *fb, int32_t x, int32_t y, int32_t w, uint32_t color);
void fb_gfx_drawFastVLine(camera_fb_t *fb, int32_t x, int32_t y, int32_t h, uint32_t color);
uint8_t fb_gfx_putc (camera_fb_t *fb, int32_t x, int32_t y, uint32_t color, unsigned char c);
uint32_t fb_gfx_print (camera_fb_t *fb, int32_t x, int32_t y, uint32_t color, const char * str);
uint32_t fb_gfx_printf (camera_fb_t *fb, int32_t x, int32_t y, uint32_t color, const char *format, ...);
#ifdef __cplusplus
}