From 6ccebb32340689d1a361a38af6116fe8689ac0bb Mon Sep 17 00:00:00 2001 From: Mira Grudzinska <67589014+mgrudzinska@users.noreply.github.com> Date: Wed, 2 Jun 2021 14:01:12 +0200 Subject: [PATCH] sw_engine common: improving the alpha blending algorithm Calculations accuracy in ALPHA_BLEND function has been improved. Until now blending resulted in a slight hue change (all color channels affected). The chosen method of calculation is a compromise between the accuracy and the performance. --- src/lib/sw_engine/tvgSwCommon.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/sw_engine/tvgSwCommon.h b/src/lib/sw_engine/tvgSwCommon.h index 55b2e73a..6e78543f 100644 --- a/src/lib/sw_engine/tvgSwCommon.h +++ b/src/lib/sw_engine/tvgSwCommon.h @@ -268,8 +268,8 @@ static inline SwCoord TO_SWCOORD(float val) static inline uint32_t ALPHA_BLEND(uint32_t c, uint32_t a) { - return (((((c >> 8) & 0x00ff00ff) * a) & 0xff00ff00) + - ((((c & 0x00ff00ff) * a) >> 8) & 0x00ff00ff)); + return (((((c >> 8) & 0x00ff00ff) * a + 0x00ff00ff) & 0xff00ff00) + + ((((c & 0x00ff00ff) * a + 0x00ff00ff) >> 8) & 0x00ff00ff)); } static inline uint32_t COLOR_INTERPOLATE(uint32_t c1, uint32_t a1, uint32_t c2, uint32_t a2)