From 38e15da5d0d00c0d72c9ddffe92d0919448170e6 Mon Sep 17 00:00:00 2001 From: Gabriel Ozouf Date: Thu, 13 Aug 2020 18:09:16 +0200 Subject: [PATCH] [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 --- kandinsky/src/color.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/kandinsky/src/color.cpp b/kandinsky/src/color.cpp index b61c45061..57256d820 100644 --- a/kandinsky/src/color.cpp +++ b/kandinsky/src/color.cpp @@ -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. */ }