QuantizeOptions Class

Immutable options of a color reduction to a palette: by ImageProcessingExtensions.Quantize, and by the encoders that store a palette (GifEncoder.Quantization, BmpEncoder.Quantization and PngEncoder.Quantization).

public sealed class QuantizeOptions

Remarks

Without QuantizeOptions.Palette, each frame gets its own palette of at most QuantizeOptions.MaxColors entries: the exact colors of the frame when they fit, otherwise a deterministic variance-based median cut of its colors (see PaletteBuilder). With QuantizeOptions.Palette, every frame maps to that palette, which is how the frames of an animation share one palette. A frame whose colors are all palette entries is reproduced exactly, whatever the dithering.

The reduction is deterministic: the same pixels and options give the same output on every platform.

Constructors

NameDescription
QuantizeOptions()

QuantizeOptions()

QuantizeOptions.cs
public QuantizeOptions()

No documentation is available.

Properties

NameDescription
DefaultGets the default options: at most 256 colors per frame, without dithering.
DitherStrengthGets the strength of the dithering, from 0 (no dithering) to 1 (the full error is diffused, or the full pattern added). Defaults to 1. It is applied in 256ths.
DitheringGets the dithering applied when a frame has colors that are not palette entries. Defaults to DitheringMode.None.
MaxColorsGets the largest number of palette entries of a frame, including the transparent entry when the frame has transparent pixels. Defaults to 256. Ignored when QuantizeOptions.Palette is set. An encoder may lower it further: the indexed BMP layouts hold 2, 16 or 256 entries.
PaletteGets a fixed palette every frame maps to, or null (the default) to compute the palette of each frame. Build a palette shared by several frames or images with PaletteBuilder.

Gets the default options: at most 256 colors per frame, without dithering.

public static QuantizeOptions Default { get; }

Property value

QuantizeOptions

DitherStrength

QuantizeOptions.cs

Gets the strength of the dithering, from 0 (no dithering) to 1 (the full error is diffused, or the full pattern added). Defaults to 1. It is applied in 256ths.

public double DitherStrength { get; init; }

Property value

double

Exceptions

ArgumentOutOfRangeException
The value is not between 0 and 1.

Gets the dithering applied when a frame has colors that are not palette entries. Defaults to DitheringMode.None.

public DitheringMode Dithering { get; init; }

Property value

DitheringMode

Exceptions

ArgumentOutOfRangeException
The value is not a defined DitheringMode.

Gets the largest number of palette entries of a frame, including the transparent entry when the frame has transparent pixels. Defaults to 256. Ignored when QuantizeOptions.Palette is set. An encoder may lower it further: the indexed BMP layouts hold 2, 16 or 256 entries.

public int MaxColors { get; init; }

Property value

int

Exceptions

ArgumentOutOfRangeException
The value is not between 2 and 256.

Gets a fixed palette every frame maps to, or null (the default) to compute the palette of each frame. Build a palette shared by several frames or images with PaletteBuilder.

public ImagePalette? Palette { get; init; }

Property value

ImagePalette?