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.
This commit is contained in:
Mira Grudzinska 2021-06-02 14:01:12 +02:00 committed by GitHub
parent c7a156d5a6
commit 6ccebb3234
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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)