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

fix(color): compensate rounding error during blending

fixes #3362
This commit is contained in:
Gabor Kiss-Vamosi 2022-05-18 23:06:21 +02:00
parent 71d535defd
commit 42d9c07eeb
2 changed files with 9 additions and 1 deletions

View File

@ -249,6 +249,14 @@ LV_ATTRIBUTE_FAST_MEM static void fill_normal(lv_color_t * dest_buf, const lv_ar
lv_color_t last_dest_color = lv_color_black();
lv_color_t last_res_color = lv_color_mix(color, last_dest_color, opa);
#if LV_COLOR_MIX_ROUND_OFS == 0 && LV_COLOR_DEPTH == 16
/*lv_color_mix work with an optimized algorithm with 16 bit color depth.
*However, it introduces some rounded error on opa.
*Introduce the same error here too to make lv_color_premult produces the same result */
opa = (uint32_t)((uint32_t)opa + 4) >> 3;
opa = opa << 3;
#endif
uint16_t color_premult[3];
lv_color_premult(color, opa, color_premult);
lv_opa_t opa_inv = 255 - opa;

View File

@ -442,7 +442,7 @@ LV_ATTRIBUTE_FAST_MEM static inline lv_color_t lv_color_mix(lv_color_t c1, lv_co
#if LV_COLOR_DEPTH == 16 && LV_COLOR_16_SWAP == 0 && LV_COLOR_MIX_ROUND_OFS == 0
/*Source: https://stackoverflow.com/a/50012418/1999969*/
mix = (mix + 4) >> 3;
mix = (uint32_t)((uint32_t)mix + 4) >> 3;
uint32_t bg = (uint32_t)((uint32_t)c2.full | ((uint32_t)c2.full << 16)) &
0x7E0F81F; /*0b00000111111000001111100000011111*/
uint32_t fg = (uint32_t)((uint32_t)c1.full | ((uint32_t)c1.full << 16)) & 0x7E0F81F;