From a6d8773d0b51e2e0c04cd2ffa2def14563feeca9 Mon Sep 17 00:00:00 2001 From: azagaya Date: Wed, 1 Apr 2020 14:05:33 -0300 Subject: [PATCH] Fixing wrong blending rect methods Using Color.blend function instead of custom code Fixed clang_format Removed unnecessary help (cherry picked from commit b211a86ebe241599f95186f9db28be2061a19962) --- core/image.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/core/image.cpp b/core/image.cpp index ac2edf9c42f..234b359e764 100644 --- a/core/image.cpp +++ b/core/image.cpp @@ -2223,12 +2223,11 @@ void Image::blend_rect(const Ref &p_src, const Rect2 &p_src_rect, const P int dst_y = dest_rect.position.y + i; Color sc = img->get_pixel(src_x, src_y); - Color dc = get_pixel(dst_x, dst_y); - dc.r = (double)(sc.a * sc.r + dc.a * (1.0 - sc.a) * dc.r); - dc.g = (double)(sc.a * sc.g + dc.a * (1.0 - sc.a) * dc.g); - dc.b = (double)(sc.a * sc.b + dc.a * (1.0 - sc.a) * dc.b); - dc.a = (double)(sc.a + dc.a * (1.0 - sc.a)); - set_pixel(dst_x, dst_y, dc); + if (sc.a != 0) { + Color dc = get_pixel(dst_x, dst_y); + dc = dc.blend(sc); + set_pixel(dst_x, dst_y, dc); + } } } @@ -2285,12 +2284,11 @@ void Image::blend_rect_mask(const Ref &p_src, const Ref &p_mask, c int dst_y = dest_rect.position.y + i; Color sc = img->get_pixel(src_x, src_y); - Color dc = get_pixel(dst_x, dst_y); - dc.r = (double)(sc.a * sc.r + dc.a * (1.0 - sc.a) * dc.r); - dc.g = (double)(sc.a * sc.g + dc.a * (1.0 - sc.a) * dc.g); - dc.b = (double)(sc.a * sc.b + dc.a * (1.0 - sc.a) * dc.b); - dc.a = (double)(sc.a + dc.a * (1.0 - sc.a)); - set_pixel(dst_x, dst_y, dc); + if (sc.a != 0) { + Color dc = get_pixel(dst_x, dst_y); + dc = dc.blend(sc); + set_pixel(dst_x, dst_y, dc); + } } } }