arch(driver): new driver architecture with new color format support

This commit is contained in:
Gabor Kiss-Vamosi
2023-02-20 20:50:58 +01:00
parent df789ed3c7
commit 124f9b0f9f
425 changed files with 25232 additions and 24168 deletions

View File

@@ -29,8 +29,8 @@
**********************/
static void lv_canvas_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj);
static void lv_canvas_destructor(const lv_obj_class_t * class_p, lv_obj_t * obj);
static void init_fake_disp(lv_obj_t * canvas, lv_disp_t * disp, lv_disp_drv_t * drv, lv_area_t * clip_area);
static void deinit_fake_disp(lv_obj_t * canvas, lv_disp_t * disp);
static lv_draw_ctx_t * init_fake_disp(lv_obj_t * canvas, lv_area_t * clip_area);
static void deinit_fake_disp(lv_obj_t * canvas, lv_draw_ctx_t * draw_ctx);
/**********************
* STATIC VARIABLES
@@ -62,7 +62,7 @@ lv_obj_t * lv_canvas_create(lv_obj_t * parent)
* Setter functions
*====================*/
void lv_canvas_set_buffer(lv_obj_t * obj, void * buf, lv_coord_t w, lv_coord_t h, lv_img_cf_t cf)
void lv_canvas_set_buffer(lv_obj_t * obj, void * buf, lv_coord_t w, lv_coord_t h, lv_color_format_t cf)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
LV_ASSERT_NULL(buf);
@@ -78,27 +78,34 @@ void lv_canvas_set_buffer(lv_obj_t * obj, void * buf, lv_coord_t w, lv_coord_t h
lv_img_cache_invalidate_src(&canvas->dsc);
}
void lv_canvas_set_px_color(lv_obj_t * obj, lv_coord_t x, lv_coord_t y, lv_color_t c)
void lv_canvas_set_px(lv_obj_t * obj, lv_coord_t x, lv_coord_t y, lv_color_t color, lv_opa_t opa)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
lv_canvas_t * canvas = (lv_canvas_t *)obj;
if(canvas->dsc.header.cf >= LV_COLOR_FORMAT_I1 && canvas->dsc.header.cf <= LV_COLOR_FORMAT_I8) {
uint32_t stride = (canvas->dsc.header.w + 7) >> 3;
uint8_t * buf = (uint8_t *)canvas->dsc.data;
buf += 8;
buf += y * stride;
buf += x >> 3;
uint32_t bit = 7 - (x & 0x7);
uint32_t c_int = lv_color_to_int(color);
lv_img_buf_set_px_color(&canvas->dsc, x, y, c);
*buf &= ~(1 << bit);
*buf |= c_int << bit;
}
else {
uint8_t px_size = lv_color_format_get_size(canvas->dsc.header.cf);
uint32_t px = canvas->dsc.header.w * y * px_size + x * px_size;
uint32_t native_color = lv_color_to_int(color);
native_color += opa << (LV_COLOR_FORMAT_NATIVE_ALPHA_OFS * 8);
lv_color_from_native_alpha((uint8_t *)&native_color, (uint8_t *)canvas->dsc.data + px, canvas->dsc.header.cf, 1);
}
lv_obj_invalidate(obj);
}
void lv_canvas_set_px_opa(lv_obj_t * obj, lv_coord_t x, lv_coord_t y, lv_opa_t opa)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
lv_canvas_t * canvas = (lv_canvas_t *)obj;
lv_img_buf_set_px_alpha(&canvas->dsc, x, y, opa);
lv_obj_invalidate(obj);
}
void lv_canvas_set_palette(lv_obj_t * obj, uint8_t id, lv_color_t c)
void lv_canvas_set_palette(lv_obj_t * obj, uint8_t id, lv_color32_t c)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
@@ -112,14 +119,15 @@ void lv_canvas_set_palette(lv_obj_t * obj, uint8_t id, lv_color_t c)
* Getter functions
*====================*/
lv_color_t lv_canvas_get_px(lv_obj_t * obj, lv_coord_t x, lv_coord_t y)
void lv_canvas_get_px(lv_obj_t * obj, lv_coord_t x, lv_coord_t y, lv_color_t * color, lv_opa_t * opa)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
lv_color_t alpha_color = lv_obj_get_style_img_recolor(obj, LV_PART_MAIN);
lv_canvas_t * canvas = (lv_canvas_t *)obj;
lv_color_t color = lv_obj_get_style_img_recolor(obj, LV_PART_MAIN);
return lv_img_buf_get_px_color(&canvas->dsc, x, y, color);
uint8_t px_size = lv_color_format_get_size(canvas->dsc.header.cf);
uint32_t px = canvas->dsc.header.w * y * px_size + x * px_size;
lv_color_to_native((uint8_t *)canvas->dsc.data + px, canvas->dsc.header.cf, color, opa, alpha_color, 1);
}
lv_img_dsc_t * lv_canvas_get_img(lv_obj_t * obj)
@@ -146,7 +154,7 @@ void lv_canvas_copy_buf(lv_obj_t * obj, const void * to_copy, lv_coord_t x, lv_c
return;
}
uint32_t px_size = lv_img_cf_get_px_size(canvas->dsc.header.cf) >> 3;
uint32_t px_size = lv_color_format_get_size(canvas->dsc.header.cf) >> 3;
uint32_t px = canvas->dsc.header.w * y * px_size + x * px_size;
uint8_t * to_copy8 = (uint8_t *)to_copy;
lv_coord_t i;
@@ -161,7 +169,7 @@ void lv_canvas_transform(lv_obj_t * obj, lv_img_dsc_t * src_img, int16_t angle,
lv_coord_t offset_y,
int32_t pivot_x, int32_t pivot_y, bool antialias)
{
#if LV_USE_DRAW_MASKS
#if LV_USE_DRAW_MASKS && 0
LV_ASSERT_OBJ(obj, MY_CLASS);
LV_ASSERT_NULL(src_img);
@@ -194,8 +202,7 @@ void lv_canvas_transform(lv_obj_t * obj, lv_img_dsc_t * src_img, int16_t angle,
for(x = 0; x < dest_img->header.w; x++) {
if(abuf[x]) {
lv_img_buf_set_px_color(dest_img, x, y, cbuf[x]);
lv_img_buf_set_px_alpha(dest_img, x, y, abuf[x]);
lv_canvas_set_px(dest_img, x, y, cbuf[x], abuf[x]);
}
}
@@ -225,255 +232,237 @@ void lv_canvas_transform(lv_obj_t * obj, lv_img_dsc_t * src_img, int16_t angle,
void lv_canvas_blur_hor(lv_obj_t * obj, const lv_area_t * area, uint16_t r)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
if(r == 0) return;
lv_canvas_t * canvas = (lv_canvas_t *)obj;
lv_area_t a;
if(area) {
lv_area_copy(&a, area);
if(a.x1 < 0) a.x1 = 0;
if(a.y1 < 0) a.y1 = 0;
if(a.x2 > canvas->dsc.header.w - 1) a.x2 = canvas->dsc.header.w - 1;
if(a.y2 > canvas->dsc.header.h - 1) a.y2 = canvas->dsc.header.h - 1;
}
else {
a.x1 = 0;
a.y1 = 0;
a.x2 = canvas->dsc.header.w - 1;
a.y2 = canvas->dsc.header.h - 1;
}
lv_color_t color = lv_obj_get_style_img_recolor(obj, LV_PART_MAIN);
uint16_t r_back = r / 2;
uint16_t r_front = r / 2;
if((r & 0x1) == 0) r_back--;
bool has_alpha = lv_img_cf_has_alpha(canvas->dsc.header.cf);
lv_coord_t line_w = lv_img_buf_get_img_size(canvas->dsc.header.w, 1, canvas->dsc.header.cf);
uint8_t * line_buf = lv_malloc(line_w);
lv_img_dsc_t line_img;
line_img.data = line_buf;
line_img.header.always_zero = 0;
line_img.header.w = canvas->dsc.header.w;
line_img.header.h = 1;
line_img.header.cf = canvas->dsc.header.cf;
lv_coord_t x;
lv_coord_t y;
lv_coord_t x_safe;
for(y = a.y1; y <= a.y2; y++) {
uint32_t asum = 0;
uint32_t rsum = 0;
uint32_t gsum = 0;
uint32_t bsum = 0;
lv_color_t c;
lv_opa_t opa = LV_OPA_TRANSP;
lv_memcpy(line_buf, &canvas->dsc.data[y * line_w], line_w);
for(x = a.x1 - r_back; x <= a.x1 + r_front; x++) {
x_safe = x < 0 ? 0 : x;
x_safe = x_safe > canvas->dsc.header.w - 1 ? canvas->dsc.header.w - 1 : x_safe;
c = lv_img_buf_get_px_color(&line_img, x_safe, 0, color);
if(has_alpha) opa = lv_img_buf_get_px_alpha(&line_img, x_safe, 0);
rsum += c.ch.red;
gsum += c.ch.green;
bsum += c.ch.blue;
if(has_alpha) asum += opa;
}
/*Just to indicate that the px is visible*/
if(has_alpha == false) asum = LV_OPA_COVER;
for(x = a.x1; x <= a.x2; x++) {
if(asum) {
c.ch.red = rsum / r;
c.ch.green = gsum / r;
c.ch.blue = bsum / r;
if(has_alpha) opa = asum / r;
lv_img_buf_set_px_color(&canvas->dsc, x, y, c);
}
if(has_alpha) lv_img_buf_set_px_alpha(&canvas->dsc, x, y, opa);
x_safe = x - r_back;
x_safe = x_safe < 0 ? 0 : x_safe;
c = lv_img_buf_get_px_color(&line_img, x_safe, 0, color);
if(has_alpha) opa = lv_img_buf_get_px_alpha(&line_img, x_safe, 0);
rsum -= c.ch.red;
gsum -= c.ch.green;
bsum -= c.ch.blue;
if(has_alpha) asum -= opa;
x_safe = x + 1 + r_front;
x_safe = x_safe > canvas->dsc.header.w - 1 ? canvas->dsc.header.w - 1 : x_safe;
c = lv_img_buf_get_px_color(&line_img, x_safe, 0, lv_color_white());
if(has_alpha) opa = lv_img_buf_get_px_alpha(&line_img, x_safe, 0);
rsum += c.ch.red;
gsum += c.ch.green;
bsum += c.ch.blue;
if(has_alpha) asum += opa;
}
}
lv_obj_invalidate(obj);
lv_free(line_buf);
LV_UNUSED(obj);
LV_UNUSED(area);
LV_UNUSED(r);
//
// if(r == 0) return;
//
// lv_canvas_t * canvas = (lv_canvas_t *)obj;
//
// lv_area_t a;
// if(area) {
// lv_area_copy(&a, area);
// if(a.x1 < 0) a.x1 = 0;
// if(a.y1 < 0) a.y1 = 0;
// if(a.x2 > canvas->dsc.header.w - 1) a.x2 = canvas->dsc.header.w - 1;
// if(a.y2 > canvas->dsc.header.h - 1) a.y2 = canvas->dsc.header.h - 1;
// }
// else {
// a.x1 = 0;
// a.y1 = 0;
// a.x2 = canvas->dsc.header.w - 1;
// a.y2 = canvas->dsc.header.h - 1;
// }
//
// lv_color_t color = lv_obj_get_style_img_recolor(obj, LV_PART_MAIN);
//
// uint16_t r_back = r / 2;
// uint16_t r_front = r / 2;
//
// if((r & 0x1) == 0) r_back--;
//
// bool has_alpha = lv_color_format_has_alpha(canvas->dsc.header.cf);
//
// lv_coord_t line_w = lv_img_buf_get_img_size(canvas->dsc.header.w, 1, canvas->dsc.header.cf);
// uint8_t * line_buf = lv_malloc(line_w);
//
// lv_img_dsc_t line_img;
// line_img.data = line_buf;
// line_img.header.always_zero = 0;
// line_img.header.w = canvas->dsc.header.w;
// line_img.header.h = 1;
// line_img.header.cf = canvas->dsc.header.cf;
//
// lv_coord_t x;
// lv_coord_t y;
// lv_coord_t x_safe;
//
// for(y = a.y1; y <= a.y2; y++) {
// /*Initialize the buffers*/
// uint32_t asum = 0;
// uint32_t rsum = 0;
// uint32_t gsum = 0;
// uint32_t bsum = 0;
//
// lv_color_t c;
// lv_opa_t opa = LV_OPA_TRANSP;
// lv_memcpy(line_buf, &canvas->dsc.data[y * line_w], line_w);
//
// for(x = a.x1 - r_back; x <= a.x1 + r_front; x++) {
// x_safe = x < 0 ? 0 : x;
// x_safe = x_safe > canvas->dsc.header.w - 1 ? canvas->dsc.header.w - 1 : x_safe;
//
// lv_canvas_get_px(obj, x_safe, 0, &c, &opa);
//
// rsum += c.red;
// gsum += c.green;
// bsum += c.blue;
// if(has_alpha) asum += opa;
// }
//
// /*Just to indicate that the px is visible*/
// if(has_alpha == false) asum = LV_OPA_COVER;
//
// /*Blur all pixels of the line*/
// for(x = a.x1; x <= a.x2; x++) {
// if(asum) {
// c.red = rsum / r;
// c.green = gsum / r;
// c.blue = bsum / r;
// if(has_alpha) opa = asum / r;
//
// lv_canvas_set_px(&canvas->dsc, x, y, c, opa);
// }
//
// x_safe = x - r_back;
// x_safe = x_safe < 0 ? 0 : x_safe;
// lv_canvas_get_px(obj, x_safe, 0, &c, &opa);
//
// rsum -= c.red;
// gsum -= c.green;
// bsum -= c.blue;
// if(has_alpha) asum -= opa;
//
// x_safe = x + 1 + r_front;
// x_safe = x_safe > canvas->dsc.header.w - 1 ? canvas->dsc.header.w - 1 : x_safe;
// lv_canvas_get_px(obj, x_safe, 0, &c, &opa);
//
// rsum += c.red;
// gsum += c.green;
// bsum += c.blue;
// if(has_alpha) asum += opa;
// }
// }
// lv_obj_invalidate(obj);
//
// lv_free(line_buf);
}
void lv_canvas_blur_ver(lv_obj_t * obj, const lv_area_t * area, uint16_t r)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
LV_UNUSED(obj);
LV_UNUSED(area);
LV_UNUSED(r);
if(r == 0) return;
// if(r == 0) return;
//
// lv_canvas_t * canvas = (lv_canvas_t *)obj;
//
// lv_area_t a;
// if(area) {
// lv_area_copy(&a, area);
// if(a.x1 < 0) a.x1 = 0;
// if(a.y1 < 0) a.y1 = 0;
// if(a.x2 > canvas->dsc.header.w - 1) a.x2 = canvas->dsc.header.w - 1;
// if(a.y2 > canvas->dsc.header.h - 1) a.y2 = canvas->dsc.header.h - 1;
// }
// else {
// a.x1 = 0;
// a.y1 = 0;
// a.x2 = canvas->dsc.header.w - 1;
// a.y2 = canvas->dsc.header.h - 1;
// }
//
// lv_color_t color = lv_obj_get_style_img_recolor(obj, LV_PART_MAIN);
//
// uint16_t r_back = r / 2;
// uint16_t r_front = r / 2;
//
// if((r & 0x1) == 0) r_back--;
//
// bool has_alpha = lv_color_format_has_alpha(canvas->dsc.header.cf);
//
// lv_coord_t x;
// lv_coord_t y;
// lv_coord_t y_safe;
//
// for(x = a.x1; x <= a.x2; x++) {
// uint32_t asum = 0;
// uint32_t rsum = 0;
// uint32_t gsum = 0;
// uint32_t bsum = 0;
//
// lv_color_t c;
// lv_opa_t opa = LV_OPA_COVER;
//
// for(y = a.y1 - r_back; y <= a.y1 + r_front; y++) {
// y_safe = y < 0 ? 0 : y;
// y_safe = y_safe > canvas->dsc.header.h - 1 ? canvas->dsc.header.h - 1 : y_safe;
//
//// c = canvas->dsc[x_safe];
//
//// c = lv_img_buf_get_px_color(&canvas->dsc, x, y_safe, color);
//// if(has_alpha) opa = lv_img_buf_get_px_alpha(&canvas->dsc, x, y_safe);
//
//// lv_img_buf_set_px_color(&line_img, 0, y_safe, c);
//// if(has_alpha) lv_img_buf_set_px_alpha(&line_img, 0, y_safe, opa);
//
// rsum += c.red;
// gsum += c.green;
// bsum += c.blue;
// if(has_alpha) asum += opa;
// }
//
// /*Just to indicate that the px is visible*/
// if(has_alpha == false) asum = LV_OPA_COVER;
//
// for(y = a.y1; y <= a.y2; y++) {
// if(asum) {
// c.red = rsum / r;
// c.green = gsum / r;
// c.blue = bsum / r;
// if(has_alpha) opa = asum / r;
//
// lv_img_buf_set_px_color(&canvas->dsc, x, y, c);
// }
// if(has_alpha) lv_img_buf_set_px_alpha(&canvas->dsc, x, y, opa);
//
// y_safe = y - r_back;
// y_safe = y_safe < 0 ? 0 : y_safe;
//// c = lv_img_buf_get_px_color(&line_img, 0, y_safe, color);
//// if(has_alpha) opa = lv_img_buf_get_px_alpha(&line_img, 0, y_safe);
//
// rsum -= c.red;
// gsum -= c.green;
// bsum -= c.blue;
// if(has_alpha) asum -= opa;
//
// y_safe = y + 1 + r_front;
// y_safe = y_safe > canvas->dsc.header.h - 1 ? canvas->dsc.header.h - 1 : y_safe;
//
//// c = lv_img_buf_get_px_color(&canvas->dsc, x, y_safe, color);
//// if(has_alpha) opa = lv_img_buf_get_px_alpha(&canvas->dsc, x, y_safe);
//
//// lv_img_buf_set_px_color(&line_img, 0, y_safe, c);
//// if(has_alpha) lv_img_buf_set_px_alpha(&line_img, 0, y_safe, opa);
//
// rsum += c.red;
// gsum += c.green;
// bsum += c.blue;
// if(has_alpha) asum += opa;
// }
// }
//
// lv_obj_invalidate(obj);
}
lv_canvas_t * canvas = (lv_canvas_t *)obj;
void lv_canvas_fill_bg(lv_obj_t * obj, lv_color_t color, lv_opa_t opa)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
lv_area_t a;
if(area) {
lv_area_copy(&a, area);
if(a.x1 < 0) a.x1 = 0;
if(a.y1 < 0) a.y1 = 0;
if(a.x2 > canvas->dsc.header.w - 1) a.x2 = canvas->dsc.header.w - 1;
if(a.y2 > canvas->dsc.header.h - 1) a.y2 = canvas->dsc.header.h - 1;
}
else {
a.x1 = 0;
a.y1 = 0;
a.x2 = canvas->dsc.header.w - 1;
a.y2 = canvas->dsc.header.h - 1;
}
lv_img_dsc_t * dsc = lv_canvas_get_img(obj);
lv_color_t color = lv_obj_get_style_img_recolor(obj, LV_PART_MAIN);
uint16_t r_back = r / 2;
uint16_t r_front = r / 2;
if((r & 0x1) == 0) r_back--;
bool has_alpha = lv_img_cf_has_alpha(canvas->dsc.header.cf);
lv_coord_t col_w = lv_img_buf_get_img_size(1, canvas->dsc.header.h, canvas->dsc.header.cf);
uint8_t * col_buf = lv_malloc(col_w);
lv_img_dsc_t line_img;
line_img.data = col_buf;
line_img.header.always_zero = 0;
line_img.header.w = 1;
line_img.header.h = canvas->dsc.header.h;
line_img.header.cf = canvas->dsc.header.cf;
lv_coord_t x;
lv_coord_t y;
lv_coord_t y_safe;
for(x = a.x1; x <= a.x2; x++) {
uint32_t asum = 0;
uint32_t rsum = 0;
uint32_t gsum = 0;
uint32_t bsum = 0;
lv_color_t c;
lv_opa_t opa = LV_OPA_COVER;
for(y = a.y1 - r_back; y <= a.y1 + r_front; y++) {
y_safe = y < 0 ? 0 : y;
y_safe = y_safe > canvas->dsc.header.h - 1 ? canvas->dsc.header.h - 1 : y_safe;
c = lv_img_buf_get_px_color(&canvas->dsc, x, y_safe, color);
if(has_alpha) opa = lv_img_buf_get_px_alpha(&canvas->dsc, x, y_safe);
lv_img_buf_set_px_color(&line_img, 0, y_safe, c);
if(has_alpha) lv_img_buf_set_px_alpha(&line_img, 0, y_safe, opa);
rsum += c.ch.red;
gsum += c.ch.green;
bsum += c.ch.blue;
if(has_alpha) asum += opa;
}
/*Just to indicate that the px is visible*/
if(has_alpha == false) asum = LV_OPA_COVER;
for(y = a.y1; y <= a.y2; y++) {
if(asum) {
c.ch.red = rsum / r;
c.ch.green = gsum / r;
c.ch.blue = bsum / r;
if(has_alpha) opa = asum / r;
lv_img_buf_set_px_color(&canvas->dsc, x, y, c);
}
if(has_alpha) lv_img_buf_set_px_alpha(&canvas->dsc, x, y, opa);
y_safe = y - r_back;
y_safe = y_safe < 0 ? 0 : y_safe;
c = lv_img_buf_get_px_color(&line_img, 0, y_safe, color);
if(has_alpha) opa = lv_img_buf_get_px_alpha(&line_img, 0, y_safe);
rsum -= c.ch.red;
gsum -= c.ch.green;
bsum -= c.ch.blue;
if(has_alpha) asum -= opa;
y_safe = y + 1 + r_front;
y_safe = y_safe > canvas->dsc.header.h - 1 ? canvas->dsc.header.h - 1 : y_safe;
c = lv_img_buf_get_px_color(&canvas->dsc, x, y_safe, color);
if(has_alpha) opa = lv_img_buf_get_px_alpha(&canvas->dsc, x, y_safe);
lv_img_buf_set_px_color(&line_img, 0, y_safe, c);
if(has_alpha) lv_img_buf_set_px_alpha(&line_img, 0, y_safe, opa);
rsum += c.ch.red;
gsum += c.ch.green;
bsum += c.ch.blue;
if(has_alpha) asum += opa;
uint32_t x;
uint32_t y;
for(y = 0; y < dsc->header.h; y++) {
for(x = 0; x < dsc->header.w; x++) {
lv_canvas_set_px(obj, x, y, color, opa);
}
}
lv_obj_invalidate(obj);
lv_free(col_buf);
}
void lv_canvas_fill_bg(lv_obj_t * canvas, lv_color_t color, lv_opa_t opa)
{
LV_ASSERT_OBJ(canvas, MY_CLASS);
lv_img_dsc_t * dsc = lv_canvas_get_img(canvas);
if(dsc->header.cf == LV_IMG_CF_INDEXED_1BIT) {
uint32_t row_byte_cnt = (dsc->header.w + 7) >> 3;
/*+8 skip the palette*/
lv_memset((uint8_t *)dsc->data + 8, color.full ? 0xff : 0x00, row_byte_cnt * dsc->header.h);
}
else if(dsc->header.cf == LV_IMG_CF_ALPHA_1BIT) {
uint32_t row_byte_cnt = (dsc->header.w + 7) >> 3;
lv_memset((uint8_t *)dsc->data, opa > LV_OPA_50 ? 0xff : 0x00, row_byte_cnt * dsc->header.h);
}
else {
uint32_t x;
uint32_t y;
for(y = 0; y < dsc->header.h; y++) {
for(x = 0; x < dsc->header.w; x++) {
lv_img_buf_set_px_color(dsc, x, y, color);
lv_img_buf_set_px_alpha(dsc, x, y, opa);
}
}
}
lv_obj_invalidate(canvas);
}
void lv_canvas_draw_rect(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_coord_t w, lv_coord_t h,
@@ -483,27 +472,15 @@ void lv_canvas_draw_rect(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_coord
lv_img_dsc_t * dsc = lv_canvas_get_img(canvas);
if(dsc->header.cf >= LV_IMG_CF_INDEXED_1BIT && dsc->header.cf <= LV_IMG_CF_INDEXED_8BIT) {
LV_LOG_WARN("can't draw to LV_IMG_CF_INDEXED canvas");
if(dsc->header.cf != LV_COLOR_FORMAT_NATIVE) {
LV_LOG_WARN("can draw only with LV_COLOR_FORMAT_NATIVE");
return;
}
/*Create a dummy display to fool the lv_draw function.
*It will think it draws to real screen.*/
lv_disp_t fake_disp;
lv_disp_drv_t driver;
lv_area_t clip_area;
init_fake_disp(canvas, &fake_disp, &driver, &clip_area);
lv_disp_t * refr_ori = _lv_refr_get_disp_refreshing();
_lv_refr_set_disp_refreshing(&fake_disp);
/*Disable anti-aliasing if drawing with transparent color to chroma keyed canvas*/
lv_color_t ctransp = lv_disp_get_chroma_key_color(refr_ori);
if(dsc->header.cf == LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED &&
draw_dsc->bg_color.full == ctransp.full) {
fake_disp.driver->antialiasing = 0;
}
lv_draw_ctx_t * draw_ctx = init_fake_disp(canvas, &clip_area);
lv_area_t coords;
coords.x1 = x;
@@ -511,11 +488,9 @@ void lv_canvas_draw_rect(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_coord
coords.x2 = x + w - 1;
coords.y2 = y + h - 1;
lv_draw_rect(driver.draw_ctx, draw_dsc, &coords);
lv_draw_rect(draw_ctx, draw_dsc, &coords);
_lv_refr_set_disp_refreshing(refr_ori);
deinit_fake_disp(canvas, &fake_disp);
deinit_fake_disp(canvas, draw_ctx);
lv_obj_invalidate(canvas);
}
@@ -527,31 +502,24 @@ void lv_canvas_draw_text(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_coord
lv_img_dsc_t * dsc = lv_canvas_get_img(canvas);
if(dsc->header.cf >= LV_IMG_CF_INDEXED_1BIT && dsc->header.cf <= LV_IMG_CF_INDEXED_8BIT) {
LV_LOG_WARN("can't draw to LV_IMG_CF_INDEXED canvas");
if(dsc->header.cf != LV_COLOR_FORMAT_NATIVE) {
LV_LOG_WARN("can draw only with LV_COLOR_FORMAT_NATIVE");
return;
}
/*Create a dummy display to fool the lv_draw function.
*It will think it draws to real screen.*/
lv_disp_t fake_disp;
lv_disp_drv_t driver;
lv_area_t clip_area;
init_fake_disp(canvas, &fake_disp, &driver, &clip_area);
lv_disp_t * refr_ori = _lv_refr_get_disp_refreshing();
_lv_refr_set_disp_refreshing(&fake_disp);
lv_draw_ctx_t * draw_ctx = init_fake_disp(canvas, &clip_area);
lv_area_t coords;
coords.x1 = x;
coords.y1 = y;
coords.x2 = x + max_w - 1;
coords.y2 = dsc->header.h - 1;
lv_draw_label(driver.draw_ctx, draw_dsc, &coords, txt, NULL);
lv_draw_label(draw_ctx, draw_dsc, &coords, txt, NULL);
_lv_refr_set_disp_refreshing(refr_ori);
deinit_fake_disp(canvas, &fake_disp);
deinit_fake_disp(canvas, draw_ctx);
lv_obj_invalidate(canvas);
}
@@ -563,8 +531,8 @@ void lv_canvas_draw_img(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, const voi
lv_img_dsc_t * dsc = lv_canvas_get_img(canvas);
if(dsc->header.cf >= LV_IMG_CF_INDEXED_1BIT && dsc->header.cf <= LV_IMG_CF_INDEXED_8BIT) {
LV_LOG_WARN("can't draw to LV_IMG_CF_INDEXED canvas");
if(dsc->header.cf != LV_COLOR_FORMAT_NATIVE) {
LV_LOG_WARN("can draw only with LV_COLOR_FORMAT_NATIVE");
return;
}
@@ -576,13 +544,8 @@ void lv_canvas_draw_img(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, const voi
}
/*Create a dummy display to fool the lv_draw function.
*It will think it draws to real screen.*/
lv_disp_t fake_disp;
lv_disp_drv_t driver;
lv_area_t clip_area;
init_fake_disp(canvas, &fake_disp, &driver, &clip_area);
lv_disp_t * refr_ori = _lv_refr_get_disp_refreshing();
_lv_refr_set_disp_refreshing(&fake_disp);
lv_draw_ctx_t * draw_ctx = init_fake_disp(canvas, &clip_area);
lv_area_t coords;
coords.x1 = x;
@@ -590,11 +553,9 @@ void lv_canvas_draw_img(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, const voi
coords.x2 = x + header.w - 1;
coords.y2 = y + header.h - 1;
lv_draw_img(driver.draw_ctx, draw_dsc, &coords, src);
lv_draw_img(draw_ctx, draw_dsc, &coords, src);
_lv_refr_set_disp_refreshing(refr_ori);
deinit_fake_disp(canvas, &fake_disp);
deinit_fake_disp(canvas, draw_ctx);
lv_obj_invalidate(canvas);
}
@@ -606,37 +567,22 @@ void lv_canvas_draw_line(lv_obj_t * canvas, const lv_point_t points[], uint32_t
lv_img_dsc_t * dsc = lv_canvas_get_img(canvas);
if(dsc->header.cf >= LV_IMG_CF_INDEXED_1BIT && dsc->header.cf <= LV_IMG_CF_INDEXED_8BIT) {
LV_LOG_WARN("can't draw to LV_IMG_CF_INDEXED canvas");
if(dsc->header.cf != LV_COLOR_FORMAT_NATIVE) {
LV_LOG_WARN("can draw only with LV_COLOR_FORMAT_NATIVE");
return;
}
/*Create a dummy display to fool the lv_draw function.
*It will think it draws to real screen.*/
lv_disp_t fake_disp;
lv_disp_drv_t driver;
lv_area_t clip_area;
init_fake_disp(canvas, &fake_disp, &driver, &clip_area);
lv_disp_t * refr_ori = _lv_refr_get_disp_refreshing();
_lv_refr_set_disp_refreshing(&fake_disp);
/*Disable anti-aliasing if drawing with transparent color to chroma keyed canvas*/
lv_color_t ctransp = lv_disp_get_chroma_key_color(refr_ori);
if(dsc->header.cf == LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED &&
draw_dsc->color.full == ctransp.full) {
fake_disp.driver->antialiasing = 0;
}
lv_draw_ctx_t * draw_ctx = init_fake_disp(canvas, &clip_area);
uint32_t i;
for(i = 0; i < point_cnt - 1; i++) {
lv_draw_line(driver.draw_ctx, draw_dsc, &points[i], &points[i + 1]);
lv_draw_line(draw_ctx, draw_dsc, &points[i], &points[i + 1]);
}
_lv_refr_set_disp_refreshing(refr_ori);
deinit_fake_disp(canvas, &fake_disp);
deinit_fake_disp(canvas, draw_ctx);
lv_obj_invalidate(canvas);
}
@@ -648,33 +594,19 @@ void lv_canvas_draw_polygon(lv_obj_t * canvas, const lv_point_t points[], uint32
lv_img_dsc_t * dsc = lv_canvas_get_img(canvas);
if(dsc->header.cf >= LV_IMG_CF_INDEXED_1BIT && dsc->header.cf <= LV_IMG_CF_INDEXED_8BIT) {
LV_LOG_WARN("can't draw to LV_IMG_CF_INDEXED canvas");
if(dsc->header.cf != LV_COLOR_FORMAT_NATIVE) {
LV_LOG_WARN("can draw only with LV_COLOR_FORMAT_NATIVE");
return;
}
/*Create a dummy display to fool the lv_draw function.
*It will think it draws to real screen.*/
lv_disp_t fake_disp;
lv_disp_drv_t driver;
lv_area_t clip_area;
init_fake_disp(canvas, &fake_disp, &driver, &clip_area);
lv_draw_ctx_t * draw_ctx = init_fake_disp(canvas, &clip_area);
lv_disp_t * refr_ori = _lv_refr_get_disp_refreshing();
_lv_refr_set_disp_refreshing(&fake_disp);
lv_draw_polygon(draw_ctx, draw_dsc, points, point_cnt);
/*Disable anti-aliasing if drawing with transparent color to chroma keyed canvas*/
lv_color_t ctransp = lv_disp_get_chroma_key_color(refr_ori);
if(dsc->header.cf == LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED &&
draw_dsc->bg_color.full == ctransp.full) {
fake_disp.driver->antialiasing = 0;
}
lv_draw_polygon(driver.draw_ctx, draw_dsc, points, point_cnt);
_lv_refr_set_disp_refreshing(refr_ori);
deinit_fake_disp(canvas, &fake_disp);
deinit_fake_disp(canvas, draw_ctx);
lv_obj_invalidate(canvas);
}
@@ -687,27 +619,20 @@ void lv_canvas_draw_arc(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_coord_
lv_img_dsc_t * dsc = lv_canvas_get_img(canvas);
if(dsc->header.cf >= LV_IMG_CF_INDEXED_1BIT && dsc->header.cf <= LV_IMG_CF_INDEXED_8BIT) {
LV_LOG_WARN("can't draw to LV_IMG_CF_INDEXED canvas");
if(dsc->header.cf != LV_COLOR_FORMAT_NATIVE) {
LV_LOG_WARN("can draw only with LV_COLOR_FORMAT_NATIVE");
return;
}
/*Create a dummy display to fool the lv_draw function.
*It will think it draws to real screen.*/
lv_disp_t fake_disp;
lv_disp_drv_t driver;
lv_area_t clip_area;
init_fake_disp(canvas, &fake_disp, &driver, &clip_area);
lv_disp_t * refr_ori = _lv_refr_get_disp_refreshing();
_lv_refr_set_disp_refreshing(&fake_disp);
lv_draw_ctx_t * draw_ctx = init_fake_disp(canvas, &clip_area);
lv_point_t p = {x, y};
lv_draw_arc(driver.draw_ctx, draw_dsc, &p, r, start_angle, end_angle);
lv_draw_arc(draw_ctx, draw_dsc, &p, r, start_angle, end_angle);
_lv_refr_set_disp_refreshing(refr_ori);
deinit_fake_disp(canvas, &fake_disp);
deinit_fake_disp(canvas, draw_ctx);
lv_obj_invalidate(canvas);
#else
@@ -734,7 +659,7 @@ static void lv_canvas_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj
lv_canvas_t * canvas = (lv_canvas_t *)obj;
canvas->dsc.header.always_zero = 0;
canvas->dsc.header.cf = LV_IMG_CF_TRUE_COLOR;
canvas->dsc.header.cf = LV_COLOR_FORMAT_NATIVE;
canvas->dsc.header.h = 0;
canvas->dsc.header.w = 0;
canvas->dsc.data_size = 0;
@@ -755,7 +680,7 @@ static void lv_canvas_destructor(const lv_obj_class_t * class_p, lv_obj_t * obj)
}
static void init_fake_disp(lv_obj_t * canvas, lv_disp_t * disp, lv_disp_drv_t * drv, lv_area_t * clip_area)
static lv_draw_ctx_t * init_fake_disp(lv_obj_t * canvas, lv_area_t * clip_area)
{
lv_img_dsc_t * dsc = lv_canvas_get_img(canvas);
@@ -764,49 +689,23 @@ static void init_fake_disp(lv_obj_t * canvas, lv_disp_t * disp, lv_disp_drv_t *
clip_area->y1 = 0;
clip_area->y2 = dsc->header.h - 1;
/*Allocate the fake driver on the stack as the entire display doesn't outlive this function*/
lv_memzero(disp, sizeof(lv_disp_t));
disp->driver = drv;
lv_disp_drv_init(disp->driver);
disp->driver->hor_res = dsc->header.w;
disp->driver->ver_res = dsc->header.h;
lv_draw_ctx_t * draw_ctx = lv_malloc(sizeof(lv_draw_sw_ctx_t));
LV_ASSERT_MALLOC(draw_ctx);
if(draw_ctx == NULL) return;
lv_draw_sw_init_ctx(drv, draw_ctx);
disp->driver->draw_ctx = draw_ctx;
if(draw_ctx == NULL) return NULL;
lv_draw_sw_init_ctx(NULL, draw_ctx);
draw_ctx->clip_area = clip_area;
draw_ctx->buf_area = clip_area;
draw_ctx->buf = (void *)dsc->data;
draw_ctx->color_format = dsc->header.cf;
switch(dsc->header.cf) {
case LV_IMG_CF_ALPHA_1BIT:
draw_ctx->color_format = LV_COLOR_FORMAT_L1;
break;
case LV_IMG_CF_ALPHA_2BIT:
draw_ctx->color_format = LV_COLOR_FORMAT_L2;
break;
case LV_IMG_CF_ALPHA_4BIT:
draw_ctx->color_format = LV_COLOR_FORMAT_L4;
break;
case LV_IMG_CF_ALPHA_8BIT:
draw_ctx->color_format = LV_COLOR_FORMAT_L8;
break;
default:
break;
}
if(dsc->header.cf != LV_IMG_CF_TRUE_COLOR_ALPHA) draw_ctx->render_with_alpha = false;
else draw_ctx->render_with_alpha = true;
return draw_ctx;
}
static void deinit_fake_disp(lv_obj_t * canvas, lv_disp_t * disp)
static void deinit_fake_disp(lv_obj_t * canvas, lv_draw_ctx_t * draw_ctx)
{
LV_UNUSED(canvas);
lv_draw_sw_deinit_ctx(disp->driver, disp->driver->draw_ctx);
lv_free(disp->driver->draw_ctx);
lv_draw_sw_deinit_ctx(NULL, draw_ctx);
lv_free(draw_ctx);
}