From 923defd6b618babb1b99b2ff7a551be72f7100df Mon Sep 17 00:00:00 2001 From: X-Ryl669 Date: Mon, 24 Jan 2022 15:47:47 +0100 Subject: [PATCH] fix(gradient): general cleanup and fix for alignment issues (#3036) * Try to fix ASAN behavior * improve alignments * fix buffer overflow and various other fixes * minor fixes * formatting Co-authored-by: Gabor Kiss-Vamosi --- Kconfig | 30 ++++ docs/overview/style-props.md | 4 +- examples/styles/lv_example_style_2.c | 4 +- lv_conf_template.h | 42 +++--- scripts/style_api_gen.py | 6 +- src/core/lv_obj_draw.c | 2 +- src/core/lv_obj_style_gen.c | 4 +- src/core/lv_obj_style_gen.h | 8 +- src/draw/lv_draw_rect.h | 2 +- src/draw/sw/lv_draw_sw_dither.c | 10 +- src/draw/sw/lv_draw_sw_dither.h | 3 +- src/draw/sw/lv_draw_sw_gradient.c | 201 ++++++++++++++++----------- src/draw/sw/lv_draw_sw_gradient.h | 31 +++-- src/draw/sw/lv_draw_sw_rect.c | 36 ++++- src/lv_conf_internal.h | 92 ++++++------ src/misc/lv_style.h | 4 +- src/misc/lv_style_gen.c | 4 +- src/misc/lv_style_gen.h | 6 +- tests/CMakeLists.txt | 10 +- tests/src/test_cases/test_style.c | 8 ++ 20 files changed, 314 insertions(+), 193 deletions(-) diff --git a/Kconfig b/Kconfig index eac5eb9d48..ca0d8da2c6 100644 --- a/Kconfig +++ b/Kconfig @@ -167,6 +167,36 @@ menu "LVGL configuration" save the continuous open/decode of images. However the opened images might consume additional RAM. + config LV_GRADIENT_MAX_STOPS + int "Number of stops allowed per gradient." + default 2 + help + Increase this to allow more stops. + This adds (sizeof(lv_color_t) + 1) bytes per additional stop + + config LV_GRAD_CACHE_DEF_SIZE + int "Default gradient buffer size." + default 0 + help + When LVGL calculates the gradient "maps" it can save them into a cache to avoid calculating them again. + LV_GRAD_CACHE_DEF_SIZE sets the size of this cache in bytes. + If the cache is too small the map will be allocated only while it's required for the drawing. + 0 mean no caching. + + config LV_DITHER_GRADIENT + bool "Allow dithering the gradients" + help + Allow dithering the gradients (to achieve visual smooth color gradients on limited color depth display) + LV_DITHER_GRADIENT implies allocating one or two more lines of the object's rendering surface + The increase in memory consumption is (32 bits * object width) plus 24 bits * object width if using error diffusion + + config LV_DITHER_ERROR_DIFFUSION + bool "Add support for error diffusion dithering" + depends on LV_DITHER_GRADIENT + help + Error diffusion dithering gets a much better visual result, but implies more CPU consumption and memory when drawing. + The increase in memory consumption is (24 bits * object's width) + config LV_DISP_ROT_MAX_BUF int "Maximum buffer size to allocate for rotation" default 10240 diff --git a/docs/overview/style-props.md b/docs/overview/style-props.md index 12a4869821..3eeaa8dd01 100644 --- a/docs/overview/style-props.md +++ b/docs/overview/style-props.md @@ -252,8 +252,8 @@ Set the point from which the background's gradient color should start. 0 means t
  • Ext. draw No
  • -### bg_gradient -Set the gradient definition for the body. The pointed instance must exist while the object is alive. NULL to disable +### bg_grad +Set the gradient definition. The pointed instance must exist while the object is alive. NULL to disable. It wraps `BG_GRAD_COLOR`, `BG_GRAD_DIR`, `BG_MAIN_STOP` and `BG_GRAD_STOP` into one descriptor and allows craeting gradients with more colors too.