mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[kandinsky/color] Blend identical colors
KDColor::blend used to produce different colors when blending two identical colors (ex : use draw_string in Python to print white text on a white background). blend now escapes early when its two color arguments are identical. Change-Id: I01dc5a0d5e4e6a20e09fee0f346dafc313dae97b
This commit is contained in:
committed by
EmilieNumworks
parent
d154611023
commit
38e15da5d0
@@ -7,7 +7,11 @@ KDColor KDColor::blend(KDColor first, KDColor second, uint8_t alpha) {
|
||||
* dealt with. So let's make a special case for them. */
|
||||
if (alpha == 0) {
|
||||
return second;
|
||||
} else if (alpha == 0xFF) {
|
||||
}
|
||||
if (alpha == 0xFF) {
|
||||
return first;
|
||||
}
|
||||
if (first == second) {
|
||||
return first;
|
||||
}
|
||||
|
||||
@@ -21,8 +25,8 @@ KDColor KDColor::blend(KDColor first, KDColor second, uint8_t alpha) {
|
||||
uint16_t blue = first.blue()*alpha + second.blue()*oneMinusAlpha;
|
||||
return RGB888(red>>8, green>>8, blue>>8);
|
||||
|
||||
|
||||
// Blend White + black, ask for white
|
||||
// white.red() = 0x1F << 3 = 0xF8
|
||||
// white.red() * 0xFF = 0xF708, we wanted 0xF800
|
||||
/* 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. */
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user