mirror of
https://github.com/greenshot/greenshot
synced 2025-07-16 10:03:44 -07:00
Added ReduceColorEffect (using the WuQuantizer in the effect). Changed the way the ApplyEffect works, an effect might decide to do nothing and return null.
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2471 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
8f36064131
commit
f0b1f1f84d
2 changed files with 39 additions and 9 deletions
|
@ -138,6 +138,34 @@ namespace Greenshot.Core {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ReduceColorsEffect
|
||||
/// </summary>
|
||||
public class ReduceColorsEffect : IEffect {
|
||||
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ReduceColorsEffect));
|
||||
public ReduceColorsEffect() : base() {
|
||||
Colors = 256;
|
||||
}
|
||||
public int Colors {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public Image Apply(Image sourceImage, out Point offsetChange) {
|
||||
offsetChange = Point.Empty;
|
||||
using (WuQuantizer quantizer = new WuQuantizer((Bitmap)sourceImage)) {
|
||||
int colorCount = quantizer.GetColorCount();
|
||||
if (colorCount > Colors) {
|
||||
try {
|
||||
return quantizer.GetQuantizedImage(Colors);
|
||||
} catch (Exception e) {
|
||||
LOG.Warn("Error occurred while Quantizing the image, ignoring and using original. Error: ", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// InvertEffect
|
||||
/// </summary>
|
||||
|
|
|
@ -357,18 +357,20 @@ namespace GreenshotPlugin.Core {
|
|||
// Default out value for the offset, will be modified there where needed
|
||||
offset = new Point(0, 0);
|
||||
Point tmpPoint;
|
||||
Image tmpImage = null;
|
||||
foreach (IEffect effect in effects) {
|
||||
tmpImage = effect.Apply(currentImage, out tmpPoint);
|
||||
Image tmpImage = effect.Apply(currentImage, out tmpPoint);
|
||||
if (tmpImage != null) {
|
||||
offset.Offset(tmpPoint);
|
||||
if (disposeImage) {
|
||||
currentImage.Dispose();
|
||||
}
|
||||
currentImage = tmpImage;
|
||||
tmpImage = null;
|
||||
// Make sure the "new" image is disposed
|
||||
disposeImage = true;
|
||||
}
|
||||
return tmpImage;
|
||||
}
|
||||
return currentImage;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue