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:
RKrom 2013-02-08 16:01:19 +00:00
parent 8f36064131
commit f0b1f1f84d
2 changed files with 39 additions and 9 deletions

View file

@ -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>

View file

@ -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);
offset.Offset(tmpPoint);
if (disposeImage) {
currentImage.Dispose();
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;
}
currentImage = tmpImage;
// Make sure the "new" image is disposed
disposeImage = true;
}
return tmpImage;
return currentImage;
}
/// <summary>