|
|
|
@ -18,7 +18,16 @@ namespace SixLabors.ImageSharp.Processing.Quantization |
|
|
|
/// Initializes a new instance of the <see cref="OctreeQuantizer"/> class.
|
|
|
|
/// </summary>
|
|
|
|
public OctreeQuantizer() |
|
|
|
: this(255) |
|
|
|
: this(true) |
|
|
|
{ |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="OctreeQuantizer"/> class.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="maxColors">The maximum number of colors to hold in the color palette</param>
|
|
|
|
public OctreeQuantizer(int maxColors) |
|
|
|
: this(GetDiffuser(true), maxColors) |
|
|
|
{ |
|
|
|
} |
|
|
|
|
|
|
|
@ -27,40 +36,34 @@ namespace SixLabors.ImageSharp.Processing.Quantization |
|
|
|
/// </summary>
|
|
|
|
/// <param name="dither">Whether to apply dithering to the output image</param>
|
|
|
|
public OctreeQuantizer(bool dither) |
|
|
|
: this(dither, DiffuseMode.FloydSteinberg, 255) |
|
|
|
: this(GetDiffuser(dither), 255) |
|
|
|
{ |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="OctreeQuantizer"/> class.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="maxColors">The maximum number of colors to hold in the color palette</param>
|
|
|
|
public OctreeQuantizer(int maxColors) |
|
|
|
: this(true, DiffuseMode.FloydSteinberg, maxColors) |
|
|
|
/// <param name="diffuser">The error diffusion algorithm, if any, to apply to the output image</param>
|
|
|
|
public OctreeQuantizer(IErrorDiffuser diffuser) |
|
|
|
: this(diffuser, 255) |
|
|
|
{ |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="OctreeQuantizer"/> class.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="dither">Whether to apply dithering to the output image</param>
|
|
|
|
/// <param name="ditherType">The dithering algorithm to apply to the output image</param>
|
|
|
|
/// <param name="diffuser">The error diffusion algorithm, if any, to apply to the output image</param>
|
|
|
|
/// <param name="maxColors">The maximum number of colors to hold in the color palette</param>
|
|
|
|
public OctreeQuantizer(bool dither, IErrorDiffuser ditherType, int maxColors) |
|
|
|
public OctreeQuantizer(IErrorDiffuser diffuser, int maxColors) |
|
|
|
{ |
|
|
|
Guard.NotNull(ditherType, nameof(ditherType)); |
|
|
|
Guard.MustBeBetweenOrEqualTo(maxColors, 1, 255, nameof(maxColors)); |
|
|
|
|
|
|
|
this.Dither = dither; |
|
|
|
this.DitherType = ditherType; |
|
|
|
this.Diffuser = diffuser; |
|
|
|
this.MaxColors = maxColors; |
|
|
|
} |
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
public bool Dither { get; } |
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
public IErrorDiffuser DitherType { get; } |
|
|
|
public IErrorDiffuser Diffuser { get; } |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the maximum number of colors to hold in the color palette.
|
|
|
|
@ -71,5 +74,7 @@ namespace SixLabors.ImageSharp.Processing.Quantization |
|
|
|
public IFrameQuantizer<TPixel> CreateFrameQuantizer<TPixel>() |
|
|
|
where TPixel : struct, IPixel<TPixel> |
|
|
|
=> new OctreeFrameQuantizer<TPixel>(this); |
|
|
|
|
|
|
|
private static IErrorDiffuser GetDiffuser(bool dither) => dither ? DiffuseMode.FloydSteinberg : null; |
|
|
|
} |
|
|
|
} |