From e01577845ab4446e5be1c7a6cc0bc82e09857326 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Tue, 4 Jun 2019 15:20:22 +0200 Subject: [PATCH] draw tri: fix pixel overwrite with oapcity (from #1091) --- src/lv_draw/lv_draw_triangle.c | 45 ++++++++++++++-------------------- 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/src/lv_draw/lv_draw_triangle.c b/src/lv_draw/lv_draw_triangle.c index 96bdef37f..02147095b 100644 --- a/src/lv_draw/lv_draw_triangle.c +++ b/src/lv_draw/lv_draw_triangle.c @@ -27,7 +27,6 @@ static void point_swap(lv_point_t * p1, lv_point_t * p2); /********************** * STATIC VARIABLES **********************/ -static uint8_t corr_value; /********************** * MACROS @@ -47,6 +46,7 @@ static uint8_t corr_value; void lv_draw_triangle(const lv_point_t * points, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale) { + /*Return is the triangle is degenerated*/ if(points[0].x == points[1].x && points[0].y == points[1].y) return; if(points[1].x == points[2].x && points[1].y == points[2].y) return; @@ -65,27 +65,19 @@ void lv_draw_triangle(const lv_point_t * points, const lv_area_t * mask, const l lv_coord_t y_min = LV_MATH_MIN(LV_MATH_MIN(points[0].y, points[1].y), points[2].y); lv_coord_t y_max = LV_MATH_MAX(LV_MATH_MAX(points[0].y, points[1].y), points[2].y); - if(opa < LV_OPA_MAX) { - /*Simply draw the triangles with opacity */ - corr_value = 1; + /* Draw the tall rectangles from vertical lines + * and from the flat triangles from horizontal lines + * to minimize the number of lines. + * Some pixels are overdrawn on the common edges of the triangles + * so use it only if the triangle has no opacity*/ + + /* Draw from horizontal lines*/ + if(x_max - x_min < y_max - y_min) { tri_draw_tall(points, mask, style, opa); - } else { - /* Draw the tall rectangles from vertical lines - * and from the flat triangles from horizontal lines - * to minimize the number of lines. - * Some pixels are overdrawn on the common edges of the triangles - * so use it only if the triangle has no opacity*/ - - corr_value = 0; - - /* Draw from horizontal lines*/ - if(x_max - x_min < y_max - y_min) { - tri_draw_tall(points, mask, style, opa); - } - /*Else flat so draw from vertical lines*/ - else { - tri_draw_flat(points, mask, style, opa); - } + } + /*Else flat so draw from vertical lines*/ + else { + tri_draw_flat(points, mask, style, opa); } } @@ -114,7 +106,6 @@ void lv_draw_polygon(const lv_point_t * points, uint32_t point_cnt, const lv_are tri[2].y = points[i+1].y; lv_draw_triangle(tri, mask, style, opa_scale); } - } /********************** @@ -193,10 +184,10 @@ void tri_draw_flat(const lv_point_t * points, const lv_area_t * mask, const lv_s /* Get the area of a line. * Adjust it a little bit to perfectly match (no redrawn pixels) with the adjacent triangles*/ - draw_area.x1 = LV_MATH_MIN(act_area.x1, act_area.x2); - draw_area.x2 = LV_MATH_MAX(act_area.x1, act_area.x2) - corr_value; - draw_area.y1 = LV_MATH_MIN(act_area.y1, act_area.y2); - draw_area.y2 = LV_MATH_MAX(act_area.y1, act_area.y2); + draw_area.x1 = LV_MATH_MIN(act_area.x1, act_area.x2) + 1; + draw_area.x2 = LV_MATH_MAX(act_area.x1, act_area.x2); + draw_area.y1 = LV_MATH_MIN(act_area.y1, act_area.y2) - 1; + draw_area.y2 = LV_MATH_MAX(act_area.y1, act_area.y2) - 1; lv_draw_fill(&draw_area, mask, style->body.main_color, opa); @@ -298,7 +289,7 @@ void tri_draw_tall(const lv_point_t * points, const lv_area_t * mask, const lv_s draw_area.x1 = LV_MATH_MIN(act_area.x1, act_area.x2); draw_area.x2 = LV_MATH_MAX(act_area.x1, act_area.x2); draw_area.y1 = LV_MATH_MIN(act_area.y1, act_area.y2); - draw_area.y2 = LV_MATH_MAX(act_area.y1, act_area.y2) - corr_value; + draw_area.y2 = LV_MATH_MAX(act_area.y1, act_area.y2) - 1; lv_draw_fill(&draw_area, mask, style->body.main_color, opa);