From bfd6cc902ea6c5fc546be8be9359179e5a9f5cb8 Mon Sep 17 00:00:00 2001 From: RKrom Date: Fri, 6 Apr 2012 13:55:07 +0000 Subject: [PATCH] Fixed alpha blending. git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1759 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4 --- GreenshotPlugin/Core/BitmapBuffer.cs | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/GreenshotPlugin/Core/BitmapBuffer.cs b/GreenshotPlugin/Core/BitmapBuffer.cs index 075931156..1580c2aec 100644 --- a/GreenshotPlugin/Core/BitmapBuffer.cs +++ b/GreenshotPlugin/Core/BitmapBuffer.cs @@ -33,23 +33,16 @@ namespace GreenshotPlugin.Core { private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(BitmapBuffer)); private bool clone; private Bitmap bitmap; - private static int[] factors = new int[256]; - private static int[] remainings = new int[256]; - - static BitmapBuffer() { - // Pre calculate for alpha blending - for (int i = 0; i < 256; i++) { - int factor = 0x10000 * i / 255; - factors[i] = factor; - remainings[i] = (0x10000 * 255) - factor; - } - } public static Color BackgroundBlendColor { get; set; } + static BitmapBuffer() { + BackgroundBlendColor = Color.White; + } + /// /// Get the bitmap, you will always need to dispose the returned bitmap!! /// Only works, and makes sense, if cloned and not locked! @@ -340,11 +333,10 @@ namespace GreenshotPlugin.Core { int blue = pointer[bIndex + offset]; if (a < 255) { - int aMult = factors[a]; - int rem = remainings[a]; - red = (red * rem + BackgroundBlendColor.R * aMult) >> 16; - green = (green * rem + BackgroundBlendColor.G * aMult) >> 16; - blue = (blue * rem + BackgroundBlendColor.B * aMult) >> 16; + int rem = 255 - a; + red = (red * a + BackgroundBlendColor.R * rem) / 255; + green = (green * a + BackgroundBlendColor.G * rem) / 255; + blue = (blue * a + BackgroundBlendColor.B * rem) / 255; } return Color.FromArgb(255, red, green, blue); } else {