Browse Source

quatizer base class

pull/299/head
Scott Williams 9 years ago
parent
commit
c0423fa8bf
  1. 3
      src/ImageSharp/Quantizers/OctreeQuantizer{TPixel}.cs
  2. 3
      src/ImageSharp/Quantizers/PaletteQuantizer{TPixel}.cs
  3. 8
      src/ImageSharp/Quantizers/QuantizerBase{TPixel}.cs
  4. 3
      src/ImageSharp/Quantizers/WuQuantizer{TPixel}.cs
  5. 6
      tests/ImageSharp.Benchmarks/Image/EncodePng.cs

3
src/ImageSharp/Quantizers/OctreeQuantizer{TPixel}.cs

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Quantizers.Base;
namespace SixLabors.ImageSharp.Quantizers namespace SixLabors.ImageSharp.Quantizers
{ {
@ -13,7 +14,7 @@ namespace SixLabors.ImageSharp.Quantizers
/// <see href="http://msdn.microsoft.com/en-us/library/aa479306.aspx"/> /// <see href="http://msdn.microsoft.com/en-us/library/aa479306.aspx"/>
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
public sealed class OctreeQuantizer<TPixel> : Quantizer<TPixel> public sealed class OctreeQuantizer<TPixel> : QuantizerBase<TPixel>
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
/// <summary> /// <summary>

3
src/ImageSharp/Quantizers/PaletteQuantizer{TPixel}.cs

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Quantizers.Base;
namespace SixLabors.ImageSharp.Quantizers namespace SixLabors.ImageSharp.Quantizers
{ {
@ -13,7 +14,7 @@ namespace SixLabors.ImageSharp.Quantizers
/// <see href="http://msdn.microsoft.com/en-us/library/aa479306.aspx"/> /// <see href="http://msdn.microsoft.com/en-us/library/aa479306.aspx"/>
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
public sealed class PaletteQuantizer<TPixel> : Quantizer<TPixel> public sealed class PaletteQuantizer<TPixel> : QuantizerBase<TPixel>
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
/// <summary> /// <summary>

8
src/ImageSharp/Quantizers/Quantizer{TPixel}.cs → src/ImageSharp/Quantizers/QuantizerBase{TPixel}.cs

@ -8,13 +8,13 @@ using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Dithering; using SixLabors.ImageSharp.Dithering;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Quantizers namespace SixLabors.ImageSharp.Quantizers.Base
{ {
/// <summary> /// <summary>
/// Encapsulates methods to calculate the color palette of an image. /// Encapsulates methods to calculate the color palette of an image.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
public abstract class Quantizer<TPixel> : IQuantizer<TPixel> public abstract class QuantizerBase<TPixel> : IQuantizer<TPixel>
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
/// <summary> /// <summary>
@ -23,7 +23,7 @@ namespace SixLabors.ImageSharp.Quantizers
private readonly bool singlePass; private readonly bool singlePass;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Quantizer{TPixel}"/> class. /// Initializes a new instance of the <see cref="QuantizerBase{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="singlePass"> /// <param name="singlePass">
/// If true, the quantization only needs to loop through the source pixels once /// If true, the quantization only needs to loop through the source pixels once
@ -33,7 +33,7 @@ namespace SixLabors.ImageSharp.Quantizers
/// only call the 'QuantizeImage' function. If two passes are required, the code will call 'InitialQuantizeImage' /// only call the 'QuantizeImage' function. If two passes are required, the code will call 'InitialQuantizeImage'
/// and then 'QuantizeImage'. /// and then 'QuantizeImage'.
/// </remarks> /// </remarks>
protected Quantizer(bool singlePass) protected QuantizerBase(bool singlePass)
{ {
this.singlePass = singlePass; this.singlePass = singlePass;
} }

3
src/ImageSharp/Quantizers/WuQuantizer{TPixel}.cs

@ -7,6 +7,7 @@ using System.Collections.Generic;
using System.Numerics; using System.Numerics;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Quantizers.Base;
namespace SixLabors.ImageSharp.Quantizers namespace SixLabors.ImageSharp.Quantizers
{ {
@ -30,7 +31,7 @@ namespace SixLabors.ImageSharp.Quantizers
/// </para> /// </para>
/// </remarks> /// </remarks>
/// <typeparam name="TPixel">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
public class WuQuantizer<TPixel> : Quantizer<TPixel> public class WuQuantizer<TPixel> : QuantizerBase<TPixel>
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
/// <summary> /// <summary>

6
tests/ImageSharp.Benchmarks/Image/EncodePng.cs

@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Image
using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Quantizers; using SixLabors.ImageSharp.Quantizers;
using SixLabors.ImageSharp.Quantizers.Base;
using CoreImage = ImageSharp.Image; using CoreImage = ImageSharp.Image;
public class EncodePng : BenchmarkBase public class EncodePng : BenchmarkBase
@ -66,8 +66,8 @@ namespace SixLabors.ImageSharp.Benchmarks.Image
{ {
using (MemoryStream memoryStream = new MemoryStream()) using (MemoryStream memoryStream = new MemoryStream())
{ {
Quantizer<Rgba32> quantizer = this.UseOctreeQuantizer QuantizerBase<Rgba32> quantizer = this.UseOctreeQuantizer
? (Quantizer<Rgba32>) ? (QuantizerBase<Rgba32>)
new OctreeQuantizer<Rgba32>() new OctreeQuantizer<Rgba32>()
: new PaletteQuantizer<Rgba32>(); : new PaletteQuantizer<Rgba32>();

Loading…
Cancel
Save