mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-14 06:42:58 +08:00
feat(draw_buf): add LV_STRIDE_AUTO to let lvgl calculate stride (#5281)
Signed-off-by: Xu Xingliang <xuxingliang@xiaomi.com>
This commit is contained in:
parent
fe61f1fc94
commit
b713ec33d9
@ -231,6 +231,8 @@ int32_t lv_display_get_dpi(const lv_display_t * disp);
|
||||
* @param disp pointer to a display
|
||||
* @param buf1 first buffer
|
||||
* @param buf2 second buffer (can be `NULL`)
|
||||
* @param buf_size buffer size in byte
|
||||
* @param render_mode LV_DISPLAY_RENDER_MODE_PARTIAL/DIRECT/FULL
|
||||
*/
|
||||
void lv_display_set_buffers(lv_display_t * disp, void * buf1, void * buf2, uint32_t buf_size,
|
||||
lv_display_render_mode_t render_mode);
|
||||
|
@ -21,6 +21,10 @@ extern "C" {
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/*Use this value to let LVGL calculate stride automatically*/
|
||||
#define LV_STRIDE_AUTO 0
|
||||
LV_EXPORT_CONST_INT(LV_STRIDE_AUTO);
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
@ -403,13 +403,13 @@ static void draw_letter(lv_draw_unit_t * draw_unit, lv_draw_glyph_dsc_t * dsc,
|
||||
lv_draw_buf_t * draw_buf = NULL;
|
||||
if(g.bpp < LV_IMGFONT_BPP) {
|
||||
/*Only check draw buf for bitmap glyph*/
|
||||
draw_buf = lv_draw_buf_reshape(dsc->_draw_buf, 0, g.box_w, g.box_h, 0);
|
||||
draw_buf = lv_draw_buf_reshape(dsc->_draw_buf, 0, g.box_w, g.box_h, LV_STRIDE_AUTO);
|
||||
if(draw_buf == NULL) {
|
||||
if(dsc->_draw_buf) lv_draw_buf_destroy(dsc->_draw_buf);
|
||||
|
||||
uint32_t h = g.box_h;
|
||||
if(h * g.box_w < 64) h *= 2; /*Alloc a slightly larger buffer*/
|
||||
draw_buf = lv_draw_buf_create(g.box_w, h, LV_COLOR_FORMAT_A8, 0);
|
||||
draw_buf = lv_draw_buf_create(g.box_w, h, LV_COLOR_FORMAT_A8, LV_STRIDE_AUTO);
|
||||
LV_ASSERT_MALLOC(draw_buf);
|
||||
draw_buf->header.h = g.box_h;
|
||||
dsc->_draw_buf = draw_buf;
|
||||
|
@ -209,7 +209,7 @@ static bool lv_barcode_change_buf_size(lv_obj_t * obj, int32_t w, int32_t h)
|
||||
LV_ASSERT(w > 0);
|
||||
|
||||
lv_draw_buf_t * old_buf = lv_canvas_get_draw_buf(obj);
|
||||
lv_draw_buf_t * new_buf = lv_draw_buf_create(w, h, LV_COLOR_FORMAT_I1, 0);
|
||||
lv_draw_buf_t * new_buf = lv_draw_buf_create(w, h, LV_COLOR_FORMAT_I1, LV_STRIDE_AUTO);
|
||||
if(new_buf == NULL) {
|
||||
LV_LOG_ERROR("malloc failed for canvas buffer");
|
||||
return false;
|
||||
|
@ -400,7 +400,7 @@ lv_result_t lv_bin_decoder_get_area(lv_image_decoder_t * decoder, lv_image_decod
|
||||
/*Use existing one directly*/
|
||||
}
|
||||
else {
|
||||
decoded = lv_draw_buf_create(w_px, 1, cf_decoded, 0);
|
||||
decoded = lv_draw_buf_create(w_px, 1, cf_decoded, LV_STRIDE_AUTO);
|
||||
if(decoded == NULL)
|
||||
return LV_RESULT_INVALID;
|
||||
}
|
||||
|
@ -199,7 +199,7 @@ static lv_result_t decoder_get_area(lv_image_decoder_t * decoder, lv_image_decod
|
||||
if(decoded_area->y1 == LV_COORD_MIN) {
|
||||
*decoded_area = *full_area;
|
||||
decoded_area->y2 = decoded_area->y1;
|
||||
if(decoded == NULL) decoded = lv_draw_buf_create(lv_area_get_width(full_area), 1, dsc->header.cf, 0);
|
||||
if(decoded == NULL) decoded = lv_draw_buf_create(lv_area_get_width(full_area), 1, dsc->header.cf, LV_STRIDE_AUTO);
|
||||
dsc->decoded = decoded;
|
||||
}
|
||||
else {
|
||||
|
@ -350,7 +350,7 @@ static lv_draw_buf_t * decode_jpeg_file(const char * filename)
|
||||
buffer = (*cinfo.mem->alloc_sarray)
|
||||
((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);
|
||||
|
||||
decoded = lv_draw_buf_create(cinfo.output_width, cinfo.output_height, LV_COLOR_FORMAT_RGB888, 0);
|
||||
decoded = lv_draw_buf_create(cinfo.output_width, cinfo.output_height, LV_COLOR_FORMAT_RGB888, LV_STRIDE_AUTO);
|
||||
if(decoded != NULL) {
|
||||
uint8_t * cur_pos = decoded->data;
|
||||
size_t stride = cinfo.output_width * JPEG_PIXEL_SIZE;
|
||||
|
@ -59,7 +59,7 @@ void lv_qrcode_set_size(lv_obj_t * obj, int32_t size)
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
|
||||
lv_draw_buf_t * old_buf = lv_canvas_get_draw_buf(obj);
|
||||
lv_draw_buf_t * new_buf = lv_draw_buf_create(size, size, LV_COLOR_FORMAT_I1, 0);
|
||||
lv_draw_buf_t * new_buf = lv_draw_buf_create(size, size, LV_COLOR_FORMAT_I1, LV_STRIDE_AUTO);
|
||||
if(new_buf == NULL) {
|
||||
LV_LOG_ERROR("malloc failed for canvas buffer");
|
||||
return;
|
||||
|
@ -349,7 +349,7 @@ static bool tiny_ttf_cache_create_cb(tiny_ttf_cache_data_t * node, void * user_d
|
||||
int w, h;
|
||||
w = x2 - x1 + 1;
|
||||
h = y2 - y1 + 1;
|
||||
lv_draw_buf_t * draw_buf = lv_draw_buf_create(w, h, LV_COLOR_FORMAT_A8, 0);
|
||||
lv_draw_buf_t * draw_buf = lv_draw_buf_create(w, h, LV_COLOR_FORMAT_A8, LV_STRIDE_AUTO);
|
||||
if(NULL == draw_buf) {
|
||||
LV_LOG_ERROR("tiny_ttf: out of memory\n");
|
||||
return false;
|
||||
|
@ -148,7 +148,7 @@ lv_image_dsc_t * lv_snapshot_take(lv_obj_t * obj, lv_color_format_t cf)
|
||||
h += ext_size * 2;
|
||||
if(w == 0 || h == 0) return NULL;
|
||||
|
||||
lv_draw_buf_t * draw_buf = lv_draw_buf_create(w, h, cf, 0);
|
||||
lv_draw_buf_t * draw_buf = lv_draw_buf_create(w, h, cf, LV_STRIDE_AUTO);
|
||||
if(draw_buf == NULL) return NULL;
|
||||
|
||||
if(lv_snapshot_take_to_buf(obj, cf, (lv_image_dsc_t *)draw_buf, draw_buf->data, draw_buf->data_size) != LV_RESULT_OK) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user