Browse Source

Make quantizers per instance

Former-commit-id: a7f37947dd2e4ca8dd3f8a15cf0eab84c3974376
Former-commit-id: b0a11a6e64ee0f028124483ad83eccd2ca0e849a
af/merge-core
James South 11 years ago
parent
commit
05d8f1a01e
  1. 30
      src/ImageProcessor/Imaging/Formats/GifFormat.cs
  2. 30
      src/ImageProcessor/Imaging/Formats/PngFormat.cs

30
src/ImageProcessor/Imaging/Formats/GifFormat.cs

@ -21,8 +21,13 @@ namespace ImageProcessor.Imaging.Formats
/// <summary>
/// Provides the necessary information to support gif images.
/// </summary>
public class GifFormat : FormatBase
public class GifFormat : FormatBase, IQuantizableImageFormat
{
/// <summary>
/// The quantizer for reducing the image palette.
/// </summary>
private IQuantizer quantizer = new OctreeQuantizer(255, 8);
/// <summary>
/// Gets the file headers.
/// </summary>
@ -67,6 +72,22 @@ namespace ImageProcessor.Imaging.Formats
}
}
/// <summary>
/// Gets or sets the quantizer for reducing the image palette.
/// </summary>
public IQuantizer Quantizer
{
get
{
return this.quantizer;
}
set
{
this.quantizer = value;
}
}
/// <summary>
/// Applies the given processor the current image.
/// </summary>
@ -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);

30
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;
/// <summary>
/// Provides the necessary information to support png images.
/// </summary>
public class PngFormat : FormatBase
public class PngFormat : FormatBase, IQuantizableImageFormat
{
/// <summary>
/// The quantizer for reducing the image palette.
/// </summary>
private IQuantizer quantizer = new WuQuantizer();
/// <summary>
/// Gets the file headers.
/// </summary>
@ -34,8 +40,6 @@ namespace ImageProcessor.Imaging.Formats
/// <summary>
/// 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.
/// </summary>
public override string[] FileExtensions
{
@ -67,6 +71,22 @@ namespace ImageProcessor.Imaging.Formats
}
}
/// <summary>
/// Gets or sets the quantizer for reducing the image palette.
/// </summary>
public IQuantizer Quantizer
{
get
{
return this.quantizer;
}
set
{
this.quantizer = value;
}
}
/// <summary>
/// Saves the current image to the specified output stream.
/// </summary>
@ -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);

Loading…
Cancel
Save