diff --git a/GreenshotPlugin/Core/Effects.cs b/GreenshotPlugin/Core/Effects.cs index 9f0224b03..fea2be5a3 100644 --- a/GreenshotPlugin/Core/Effects.cs +++ b/GreenshotPlugin/Core/Effects.cs @@ -138,6 +138,34 @@ namespace Greenshot.Core { } } + /// + /// ReduceColorsEffect + /// + 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; + } + } + /// /// InvertEffect /// diff --git a/GreenshotPlugin/Core/ImageHelper.cs b/GreenshotPlugin/Core/ImageHelper.cs index e26ab49af..f6d234546 100644 --- a/GreenshotPlugin/Core/ImageHelper.cs +++ b/GreenshotPlugin/Core/ImageHelper.cs @@ -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; } ///