[kandinsky/color] Fix blend method

When computing the barycenter between two colors, the some of the two
factors a and (1-a) was equal to 255/256 instead of 1.

Change-Id: Ia9a779d43470ef42d9430ad730e842da0f007140
This commit is contained in:
Gabriel Ozouf
2020-08-19 15:51:44 +02:00
committed by EmilieNumworks
parent 38e15da5d0
commit 078bba2fb9

View File

@@ -19,14 +19,9 @@ KDColor KDColor::blend(KDColor first, KDColor second, uint8_t alpha) {
// First is RRRRR GGGGGG BBBBB
// Second is same
uint8_t oneMinusAlpha = 0xFF-alpha;
uint16_t oneMinusAlpha = 0x100-alpha;
uint16_t red = first.red()*alpha + second.red()*oneMinusAlpha;
uint16_t green = first.green()*alpha + second.green()*oneMinusAlpha;
uint16_t blue = first.blue()*alpha + second.blue()*oneMinusAlpha;
return RGB888(red>>8, green>>8, blue>>8);
/* The formula used to blend colors produces some unwanted results :
* blend white + black, alpha = OxFF (should be white)
* white.red() * OxFF = OxF708, while we would like 0xF800
* Escaping early solves this issue. */
}