diff --git a/src/ImageProcessor/Imaging/Formats/GifFormat.cs b/src/ImageProcessor/Imaging/Formats/GifFormat.cs
index c36457ae5..e27766dc7 100644
--- a/src/ImageProcessor/Imaging/Formats/GifFormat.cs
+++ b/src/ImageProcessor/Imaging/Formats/GifFormat.cs
@@ -21,8 +21,13 @@ namespace ImageProcessor.Imaging.Formats
///
/// Provides the necessary information to support gif images.
///
- public class GifFormat : FormatBase
+ public class GifFormat : FormatBase, IQuantizableImageFormat
{
+ ///
+ /// The quantizer for reducing the image palette.
+ ///
+ private IQuantizer quantizer = new OctreeQuantizer(255, 8);
+
///
/// Gets the file headers.
///
@@ -67,6 +72,22 @@ namespace ImageProcessor.Imaging.Formats
}
}
+ ///
+ /// Gets or sets the quantizer for reducing the image palette.
+ ///
+ public IQuantizer Quantizer
+ {
+ get
+ {
+ return this.quantizer;
+ }
+
+ set
+ {
+ this.quantizer = value;
+ }
+ }
+
///
/// Applies the given processor the current image.
///
@@ -78,12 +99,11 @@ namespace ImageProcessor.Imaging.Formats
if (decoder.IsAnimated)
{
- OctreeQuantizer quantizer = new OctreeQuantizer(255, 8);
GifEncoder encoder = new GifEncoder(null, null, decoder.LoopCount);
foreach (GifFrame frame in decoder.GifFrames)
{
factory.Image = frame.Image;
- frame.Image = quantizer.Quantize(processor.Invoke(factory));
+ frame.Image = this.Quantizer.Quantize(processor.Invoke(factory));
encoder.AddFrame(frame);
}
@@ -109,7 +129,7 @@ namespace ImageProcessor.Imaging.Formats
{
if (!FormatUtilities.IsAnimated(image))
{
- image = new OctreeQuantizer(255, 8).Quantize(image);
+ image = this.Quantizer.Quantize(image);
}
return base.Save(stream, image);
@@ -128,7 +148,7 @@ namespace ImageProcessor.Imaging.Formats
{
if (!FormatUtilities.IsAnimated(image))
{
- image = new OctreeQuantizer(255, 8).Quantize(image);
+ image = this.Quantizer.Quantize(image);
}
return base.Save(path, image);
diff --git a/src/ImageProcessor/Imaging/Formats/PngFormat.cs b/src/ImageProcessor/Imaging/Formats/PngFormat.cs
index 998e46b99..bdf4295b9 100644
--- a/src/ImageProcessor/Imaging/Formats/PngFormat.cs
+++ b/src/ImageProcessor/Imaging/Formats/PngFormat.cs
@@ -14,13 +14,19 @@ namespace ImageProcessor.Imaging.Formats
using System.Drawing.Imaging;
using System.IO;
+ using ImageProcessor.Imaging.Quantizers;
using ImageProcessor.Imaging.Quantizers.WuQuantizer;
///
/// Provides the necessary information to support png images.
///
- public class PngFormat : FormatBase
+ public class PngFormat : FormatBase, IQuantizableImageFormat
{
+ ///
+ /// The quantizer for reducing the image palette.
+ ///
+ private IQuantizer quantizer = new WuQuantizer();
+
///
/// Gets the file headers.
///
@@ -34,8 +40,6 @@ namespace ImageProcessor.Imaging.Formats
///
/// Gets the list of file extensions.
- /// Obviously png8 isn't a valid file extension but it's a neat way to
- /// add the value to the format method detection.
///
public override string[] FileExtensions
{
@@ -67,6 +71,22 @@ namespace ImageProcessor.Imaging.Formats
}
}
+ ///
+ /// Gets or sets the quantizer for reducing the image palette.
+ ///
+ public IQuantizer Quantizer
+ {
+ get
+ {
+ return this.quantizer;
+ }
+
+ set
+ {
+ this.quantizer = value;
+ }
+ }
+
///
/// Saves the current image to the specified output stream.
///
@@ -79,7 +99,7 @@ namespace ImageProcessor.Imaging.Formats
{
if (this.IsIndexed)
{
- image = new WuQuantizer().Quantize(image);
+ image = this.Quantizer.Quantize(image);
}
return base.Save(stream, image);
@@ -98,7 +118,7 @@ namespace ImageProcessor.Imaging.Formats
{
if (this.IsIndexed)
{
- image = new WuQuantizer().Quantize(image);
+ image = this.Quantizer.Quantize(image);
}
return base.Save(path, image);