mirror of
https://github.com/greenshot/greenshot
synced 2025-07-16 10:03:44 -07:00
Fixed missing alpha blending and optimized performance.
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1718 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
4a5e04ae23
commit
64bc855652
2 changed files with 34 additions and 40 deletions
|
@ -71,8 +71,6 @@ namespace GreenshotPlugin.Core {
|
|||
|
||||
public class WuQuantizer {
|
||||
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(WuQuantizer));
|
||||
private static readonly Color BackgroundColor;
|
||||
private static readonly Double[] Factors;
|
||||
|
||||
private const Int32 MAXCOLOR = 512;
|
||||
private const Int32 RED = 2;
|
||||
|
@ -102,14 +100,6 @@ namespace GreenshotPlugin.Core {
|
|||
private Bitmap sourceBitmap;
|
||||
private Bitmap resultBitmap;
|
||||
|
||||
static WuQuantizer() {
|
||||
BackgroundColor = Color.White;
|
||||
Factors = new Double[256];
|
||||
for (Int32 value = 0; value < 256; value++) {
|
||||
Factors[value] = value / 255.0;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// See <see cref="IColorQuantizer.Prepare"/> for more details.
|
||||
/// </summary>
|
||||
|
@ -157,8 +147,7 @@ namespace GreenshotPlugin.Core {
|
|||
bbbDest.Lock();
|
||||
for (int y = 0; y < bbbSrc.Height; y++) {
|
||||
for (int x = 0; x < bbbSrc.Width; x++) {
|
||||
Color color = bbbSrc.GetColorAt(x, y);
|
||||
color = ConvertAlpha(color);
|
||||
Color color = bbbSrc.GetColorAtWithoutAlpha(x, y);
|
||||
// To count the colors
|
||||
int index = color.ToArgb() & 0x00ffffff;
|
||||
// Check if we already have this color
|
||||
|
@ -270,8 +259,7 @@ namespace GreenshotPlugin.Core {
|
|||
byte bestMatch;
|
||||
for (int y = 0; y < bbbSrc.Height; y++) {
|
||||
for (int x = 0; x < bbbSrc.Width; x++) {
|
||||
Color color = bbbSrc.GetColorAt(x, y);
|
||||
|
||||
Color color = bbbSrc.GetColorAtWithoutAlpha(x, y);
|
||||
// Check if we already matched the color
|
||||
if (!lookup.ContainsKey(color)) {
|
||||
// If not we need to find the best match
|
||||
|
@ -329,28 +317,6 @@ namespace GreenshotPlugin.Core {
|
|||
return resultBitmap;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts the alpha blended color to a non-alpha blended color.
|
||||
/// </summary>
|
||||
/// <param name="color">The alpha blended color (ARGB).</param>
|
||||
/// <returns>The non-alpha blended color (RGB).</returns>
|
||||
private static Color ConvertAlpha(Color color) {
|
||||
Color result = color;
|
||||
|
||||
if (color.A < 255) {
|
||||
// performs a alpha blending (second color is BackgroundColor, by default a Control color)
|
||||
Double colorFactor = Factors[color.A];
|
||||
Double backgroundFactor = Factors[255 - color.A];
|
||||
Int32 red = (Int32)(color.R * colorFactor + BackgroundColor.R * backgroundFactor);
|
||||
Int32 green = (Int32)(color.G * colorFactor + BackgroundColor.G * backgroundFactor);
|
||||
Int32 blue = (Int32)(color.B * colorFactor + BackgroundColor.B * backgroundFactor);
|
||||
Int32 argb = 255 << 24 | red << 16 | green << 8 | blue;
|
||||
result = Color.FromArgb(argb);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts the histogram to a series of moments.
|
||||
/// </summary>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue