diff --git a/examples/widgets/canvas/lv_example_canvas_1.c b/examples/widgets/canvas/lv_example_canvas_1.c index ceada1b65..781855f2f 100644 --- a/examples/widgets/canvas/lv_example_canvas_1.c +++ b/examples/widgets/canvas/lv_example_canvas_1.c @@ -27,10 +27,10 @@ void lv_example_canvas_1(void) label_dsc.color = lv_palette_main(LV_PALETTE_ORANGE); label_dsc.text = "Some text on text canvas"; /*Create a buffer for the canvas*/ - static uint8_t cbuf[LV_CANVAS_BUF_SIZE(CANVAS_WIDTH, CANVAS_HEIGHT, 16, LV_DRAW_BUF_STRIDE_ALIGN)]; + LV_DRAW_BUF_DEFINE(draw_buf_16bpp, CANVAS_WIDTH, CANVAS_HEIGHT, LV_COLOR_FORMAT_RGB565); lv_obj_t * canvas = lv_canvas_create(lv_screen_active()); - lv_canvas_set_buffer(canvas, cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_COLOR_FORMAT_RGB565); + lv_canvas_set_draw_buf(canvas, &draw_buf_16bpp); lv_obj_center(canvas); lv_canvas_fill_bg(canvas, lv_palette_lighten(LV_PALETTE_GREY, 3), LV_OPA_COVER); @@ -46,26 +46,19 @@ void lv_example_canvas_1(void) lv_canvas_finish_layer(canvas, &layer); /*Test the rotation. It requires another buffer where the original image is stored. - *So copy the current image to buffer and rotate it to the canvas*/ - static uint8_t cbuf_tmp[LV_CANVAS_BUF_SIZE(CANVAS_WIDTH, CANVAS_HEIGHT, 32, LV_DRAW_BUF_STRIDE_ALIGN)]; - + *So use previous canvas as image and rotate it to the new canvas*/ + LV_DRAW_BUF_DEFINE(draw_buf_32bpp, CANVAS_WIDTH, CANVAS_HEIGHT, LV_COLOR_FORMAT_ARGB8888); /*Create a canvas and initialize its palette*/ canvas = lv_canvas_create(lv_screen_active()); - lv_canvas_set_buffer(canvas, cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_COLOR_FORMAT_ARGB8888); + lv_canvas_set_draw_buf(canvas, &draw_buf_32bpp); lv_canvas_fill_bg(canvas, lv_color_hex3(0xccc), LV_OPA_COVER); lv_obj_center(canvas); - lv_memcpy(cbuf_tmp, cbuf, sizeof(cbuf_tmp)); - lv_image_dsc_t img; - img.data = (void *)cbuf_tmp; - img.header.cf = LV_COLOR_FORMAT_ARGB8888; - img.header.w = CANVAS_WIDTH; - img.header.h = CANVAS_HEIGHT; - - lv_canvas_finish_layer(canvas, &layer); - lv_canvas_fill_bg(canvas, lv_palette_lighten(LV_PALETTE_GREY, 1), LV_OPA_COVER); + lv_canvas_init_layer(canvas, &layer); + lv_image_dsc_t img; + lv_draw_buf_to_image(&draw_buf_16bpp, &img); lv_draw_image_dsc_t img_dsc; lv_draw_image_dsc_init(&img_dsc); img_dsc.rotation = 120; diff --git a/examples/widgets/canvas/lv_example_canvas_2.c b/examples/widgets/canvas/lv_example_canvas_2.c index 7c546ce32..eb8fdb203 100644 --- a/examples/widgets/canvas/lv_example_canvas_2.c +++ b/examples/widgets/canvas/lv_example_canvas_2.c @@ -12,11 +12,10 @@ void lv_example_canvas_2(void) lv_obj_set_style_bg_color(lv_screen_active(), lv_palette_lighten(LV_PALETTE_RED, 5), 0); /*Create a buffer for the canvas*/ - static uint8_t cbuf[CANVAS_WIDTH * CANVAS_HEIGHT * 4]; - + LV_DRAW_BUF_DEFINE(draw_buf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_COLOR_FORMAT_ARGB8888); /*Create a canvas and initialize its palette*/ lv_obj_t * canvas = lv_canvas_create(lv_screen_active()); - lv_canvas_set_buffer(canvas, cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_COLOR_FORMAT_ARGB8888); + lv_canvas_set_draw_buf(canvas, &draw_buf); lv_obj_center(canvas); /*Red background (There is no dedicated alpha channel in indexed images so LV_OPA_COVER is ignored)*/ diff --git a/examples/widgets/canvas/lv_example_canvas_3.c b/examples/widgets/canvas/lv_example_canvas_3.c index 65ff564d6..75dbba888 100644 --- a/examples/widgets/canvas/lv_example_canvas_3.c +++ b/examples/widgets/canvas/lv_example_canvas_3.c @@ -10,11 +10,12 @@ void lv_example_canvas_3(void) { /*Create a buffer for the canvas*/ - static uint8_t cbuf[LV_CANVAS_BUF_SIZE(CANVAS_WIDTH, CANVAS_HEIGHT, 32, LV_DRAW_BUF_STRIDE_ALIGN)]; + LV_DRAW_BUF_DEFINE(draw_buf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_COLOR_FORMAT_ARGB8888); /*Create a canvas and initialize its palette*/ lv_obj_t * canvas = lv_canvas_create(lv_screen_active()); - lv_canvas_set_buffer(canvas, cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_COLOR_FORMAT_ARGB8888); + lv_canvas_set_draw_buf(canvas, &draw_buf); + lv_canvas_fill_bg(canvas, lv_color_hex3(0xccc), LV_OPA_COVER); lv_obj_center(canvas); diff --git a/examples/widgets/canvas/lv_example_canvas_4.c b/examples/widgets/canvas/lv_example_canvas_4.c index 7b9403ffc..9678abfb1 100644 --- a/examples/widgets/canvas/lv_example_canvas_4.c +++ b/examples/widgets/canvas/lv_example_canvas_4.c @@ -10,11 +10,11 @@ void lv_example_canvas_4(void) { /*Create a buffer for the canvas*/ - static uint8_t cbuf[LV_CANVAS_BUF_SIZE(CANVAS_WIDTH, CANVAS_HEIGHT, 32, LV_DRAW_BUF_STRIDE_ALIGN)]; + LV_DRAW_BUF_DEFINE(draw_buf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_COLOR_FORMAT_ARGB8888); /*Create a canvas and initialize its palette*/ lv_obj_t * canvas = lv_canvas_create(lv_screen_active()); - lv_canvas_set_buffer(canvas, cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_COLOR_FORMAT_ARGB8888); + lv_canvas_set_draw_buf(canvas, &draw_buf); lv_canvas_fill_bg(canvas, lv_color_hex3(0xccc), LV_OPA_COVER); lv_obj_center(canvas); diff --git a/examples/widgets/canvas/lv_example_canvas_5.c b/examples/widgets/canvas/lv_example_canvas_5.c index 34a52e0f8..a905e4e18 100644 --- a/examples/widgets/canvas/lv_example_canvas_5.c +++ b/examples/widgets/canvas/lv_example_canvas_5.c @@ -10,11 +10,11 @@ void lv_example_canvas_5(void) { /*Create a buffer for the canvas*/ - static uint8_t cbuf[LV_CANVAS_BUF_SIZE(CANVAS_WIDTH, CANVAS_HEIGHT, 32, LV_DRAW_BUF_STRIDE_ALIGN)]; + LV_DRAW_BUF_DEFINE(draw_buf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_COLOR_FORMAT_ARGB8888); /*Create a canvas and initialize its palette*/ lv_obj_t * canvas = lv_canvas_create(lv_screen_active()); - lv_canvas_set_buffer(canvas, cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_COLOR_FORMAT_ARGB8888); + lv_canvas_set_draw_buf(canvas, &draw_buf); lv_canvas_fill_bg(canvas, lv_color_hex3(0xccc), LV_OPA_COVER); lv_obj_center(canvas); diff --git a/examples/widgets/canvas/lv_example_canvas_6.c b/examples/widgets/canvas/lv_example_canvas_6.c index c3edf7858..fb9db9f67 100644 --- a/examples/widgets/canvas/lv_example_canvas_6.c +++ b/examples/widgets/canvas/lv_example_canvas_6.c @@ -29,8 +29,5 @@ void lv_example_canvas_6(void) lv_area_t coords = {10, 10, 10 + img_star.header.w - 1, 10 + img_star.header.h - 1}; lv_draw_image(&layer, &dsc, &coords); - - lv_canvas_finish_layer(canvas, &layer); - } #endif diff --git a/examples/widgets/canvas/lv_example_canvas_7.c b/examples/widgets/canvas/lv_example_canvas_7.c index 40a10e30a..d4e2b76ad 100644 --- a/examples/widgets/canvas/lv_example_canvas_7.c +++ b/examples/widgets/canvas/lv_example_canvas_7.c @@ -10,11 +10,11 @@ void lv_example_canvas_7(void) { /*Create a buffer for the canvas*/ - static uint8_t cbuf[LV_CANVAS_BUF_SIZE(CANVAS_WIDTH, CANVAS_HEIGHT, 32, LV_DRAW_BUF_STRIDE_ALIGN)]; + LV_DRAW_BUF_DEFINE(draw_buf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_COLOR_FORMAT_ARGB8888); /*Create a canvas and initialize its palette*/ lv_obj_t * canvas = lv_canvas_create(lv_screen_active()); - lv_canvas_set_buffer(canvas, cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_COLOR_FORMAT_ARGB8888); + lv_canvas_set_draw_buf(canvas, &draw_buf); lv_canvas_fill_bg(canvas, lv_color_hex3(0xccc), LV_OPA_COVER); lv_obj_center(canvas); diff --git a/examples/widgets/canvas/lv_example_canvas_8.c b/examples/widgets/canvas/lv_example_canvas_8.c index 3bebdf69d..e9773c2a3 100644 --- a/examples/widgets/canvas/lv_example_canvas_8.c +++ b/examples/widgets/canvas/lv_example_canvas_8.c @@ -12,11 +12,11 @@ void lv_example_canvas_8(void) { /*Create a buffer for the canvas*/ - static uint8_t cbuf[LV_CANVAS_BUF_SIZE(CANVAS_WIDTH, CANVAS_HEIGHT, 32, LV_DRAW_BUF_STRIDE_ALIGN)]; + LV_DRAW_BUF_DEFINE(draw_buf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_COLOR_FORMAT_ARGB8888); /*Create a canvas and initialize its palette*/ lv_obj_t * canvas = lv_canvas_create(lv_screen_active()); - lv_canvas_set_buffer(canvas, cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_COLOR_FORMAT_ARGB8888); + lv_canvas_set_draw_buf(canvas, &draw_buf); lv_canvas_fill_bg(canvas, lv_color_hex3(0xccc), LV_OPA_COVER); lv_obj_center(canvas);