From 5a274c11ef0b06d2618e2dc3c09451f242df3fb9 Mon Sep 17 00:00:00 2001 From: Mark van Renswoude Date: Sun, 19 Mar 2006 14:50:39 +0000 Subject: [PATCH] Fixed: BlendColors was off by 1 level for each channel (shr 8 = div 256, not div 255 dummy!) --- X2UtGraphics.pas | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/X2UtGraphics.pas b/X2UtGraphics.pas index adf9edd..2c3ee64 100644 --- a/X2UtGraphics.pas +++ b/X2UtGraphics.pas @@ -164,19 +164,28 @@ function BlendColors(const ABackground, AForeground: TColor; var cBack: Cardinal; cFore: Cardinal; - bBack: Byte; + iBack: Integer; + iFore: Integer; begin - cBack := ColorToRGB(ABackground); - cFore := ColorToRGB(AForeground); - bBack := 255 - AAlpha; + if AAlpha = 0 then + Result := ABackground + else if AAlpha = 255 then + Result := AForeground + else + begin + cBack := ColorToRGB(ABackground); + cFore := ColorToRGB(AForeground); + iBack := 256 - AAlpha; + iFore := Succ(AAlpha); - Result := RGB(((GetRValue(cBack) * bBack) + - (GetRValue(cFore) * AAlpha)) shr 8, - ((GetGValue(cBack) * bBack) + - (GetGValue(cFore) * AAlpha)) shr 8, - ((GetBValue(cBack) * bBack) + - (GetBValue(cFore) * AAlpha)) shr 8); + Result := RGB(((GetRValue(cBack) * iBack) + + (GetRValue(cFore) * iFore)) shr 8, + ((GetGValue(cBack) * iBack) + + (GetGValue(cFore) * iFore)) shr 8, + ((GetBValue(cBack) * iBack) + + (GetBValue(cFore) * iFore)) shr 8); + end; end;