mirror of
https://github.com/greenshot/greenshot
synced 2025-07-15 01:23:47 -07:00
Fixed alpha blending.
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1759 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
1beb0656f4
commit
bfd6cc902e
1 changed files with 8 additions and 16 deletions
|
@ -33,23 +33,16 @@ namespace GreenshotPlugin.Core {
|
||||||
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(BitmapBuffer));
|
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(BitmapBuffer));
|
||||||
private bool clone;
|
private bool clone;
|
||||||
private Bitmap bitmap;
|
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 {
|
public static Color BackgroundBlendColor {
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static BitmapBuffer() {
|
||||||
|
BackgroundBlendColor = Color.White;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the bitmap, you will always need to dispose the returned bitmap!!
|
/// Get the bitmap, you will always need to dispose the returned bitmap!!
|
||||||
/// Only works, and makes sense, if cloned and not locked!
|
/// Only works, and makes sense, if cloned and not locked!
|
||||||
|
@ -340,11 +333,10 @@ namespace GreenshotPlugin.Core {
|
||||||
int blue = pointer[bIndex + offset];
|
int blue = pointer[bIndex + offset];
|
||||||
|
|
||||||
if (a < 255) {
|
if (a < 255) {
|
||||||
int aMult = factors[a];
|
int rem = 255 - a;
|
||||||
int rem = remainings[a];
|
red = (red * a + BackgroundBlendColor.R * rem) / 255;
|
||||||
red = (red * rem + BackgroundBlendColor.R * aMult) >> 16;
|
green = (green * a + BackgroundBlendColor.G * rem) / 255;
|
||||||
green = (green * rem + BackgroundBlendColor.G * aMult) >> 16;
|
blue = (blue * a + BackgroundBlendColor.B * rem) / 255;
|
||||||
blue = (blue * rem + BackgroundBlendColor.B * aMult) >> 16;
|
|
||||||
}
|
}
|
||||||
return Color.FromArgb(255, red, green, blue);
|
return Color.FromArgb(255, red, green, blue);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue