1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00

feat(draw_buf): add draw_buf init API (#5132)

Signed-off-by: Xu Xingliang <xuxingliang@xiaomi.com>
This commit is contained in:
Neo Xu 2024-01-05 21:45:42 +08:00 committed by GitHub
parent 0b54a69c36
commit 1d73e73a93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 9 deletions

View File

@ -135,6 +135,27 @@ void lv_draw_buf_copy(void * dest_buf, uint32_t dest_w, uint32_t dest_h, const l
}
}
lv_result_t lv_draw_buf_init(lv_draw_buf_t * draw_buf, uint32_t w, uint32_t h, lv_color_format_t cf, uint32_t stride,
void * data, uint32_t data_size)
{
LV_ASSERT_NULL(draw_buf);
if(draw_buf == NULL) return LV_RESULT_INVALID;
lv_memzero(draw_buf, sizeof(lv_draw_buf_t));
if(stride == 0) stride = lv_draw_buf_width_to_stride(w, cf);
if(stride * h > data_size) {
LV_LOG_WARN("Data size too small, required: %" LV_PRId32 ", provided: %" LV_PRId32, stride * h,
data_size);
return LV_RESULT_INVALID;
}
lv_image_header_init(&draw_buf->header, w, h, cf, stride, 0);
draw_buf->data = lv_draw_buf_align(data, cf);
draw_buf->unaligned_data = data;
draw_buf->data_size = data_size;
return LV_RESULT_OK;
}
lv_draw_buf_t * lv_draw_buf_create(uint32_t w, uint32_t h, lv_color_format_t cf, uint32_t stride)
{
lv_draw_buf_t * draw_buf = lv_malloc_zeroed(sizeof(lv_draw_buf_t));

View File

@ -174,13 +174,27 @@ void lv_draw_buf_copy(void * dest_buf, uint32_t dest_w, uint32_t dest_h, const l
* that meets specified requirements.
*
* @param w the buffer width in pixels
* @param h
* @param h the buffer height in pixels
* @param cf the color format for image
* @param stride the stride in bytes for image. Use 0 for automatic calculation based on
* w, cf, and global stride alignment configuration.
*/
lv_draw_buf_t * lv_draw_buf_create(uint32_t w, uint32_t h, lv_color_format_t cf, uint32_t stride);
/**
* Initialize a draw buf with the given buffer and parameters.
* @param draw_buf the draw buf to initialize
* @param w the buffer width in pixels
* @param h the buffer height in pixels
* @param cf the color format
* @param stride the stride in bytes. Use 0 for automatic calculation
* @param data the buffer used for drawing. Unaligned `data` will be aligned internally
* @param data_size the size of the buffer in bytes
* @return return LV_RESULT_OK on success, LV_RESULT_INVALID otherwise
*/
lv_result_t lv_draw_buf_init(lv_draw_buf_t * draw_buf, uint32_t w, uint32_t h, lv_color_format_t cf, uint32_t stride,
void * data, uint32_t data_size);
/**
* Duplicate a draw buf with same image size, stride and color format. Copy the image data too.
* @param draw_buf the draw buf to duplicate

View File

@ -219,10 +219,8 @@ static lv_result_t decoder_open_variable(lv_image_decoder_t * decoder, lv_image_
lv_draw_buf_t * draw_buf = lv_malloc_zeroed(sizeof(lv_draw_buf_t));
LV_ASSERT_MALLOC(draw_buf);
lv_image_header_init(&draw_buf->header, width, height, cf, stride, LV_VG_LITE_IMAGE_NO_CACHE);
lv_draw_buf_init(draw_buf, width, height, cf, stride, (void *)image_data, LV_VG_LITE_IMAGE_NO_CACHE);
dsc->decoded = draw_buf;
draw_buf->data = (void *)image_data;
draw_buf->unaligned_data = (void *)image_data;
return LV_RESULT_OK;
}

View File

@ -70,11 +70,7 @@ void lv_canvas_set_buffer(lv_obj_t * obj, void * buf, int32_t w, int32_t h, lv_c
lv_canvas_t * canvas = (lv_canvas_t *)obj;
uint32_t stride = lv_draw_buf_width_to_stride(w, cf);
lv_memzero(&canvas->static_buf, sizeof(canvas->static_buf));
lv_image_header_init(&canvas->static_buf.header, w, h, cf, stride, 0);
canvas->static_buf.data_size = stride * h;
canvas->static_buf.data = lv_draw_buf_align(buf, cf);
canvas->static_buf.unaligned_data = buf;
lv_draw_buf_init(&canvas->static_buf, w, h, cf, stride, buf, stride * h);
canvas->draw_buf = &canvas->static_buf;
const void * src = lv_image_get_src(obj);