Quantizer Class


Abstract Quantizer class - handles the messy, algorithm-independent details of quantization. Subclasses must implement InitialQuantizePixel, GetPallete(), and QuantizePixel. Not thread-safe!

public abstract class Quantizer
System.Object → Quantizer


Quantizer(Boolean) Construct the quantizer


FirstPassPixelCount The approximate number of pixels to use when making a scaled copy of the image for the first pass. Only used when ResizeForFirstPass=True and FirstPassPixelThreshold is exceeded.
FirstPassPixelThreshold The maximum number of pixels the original image may contain before a scaled copy is made for the first pass. Only relevant when ResizeForFirstPass=True
FixedPalette (Readonly) If true, the algorithm can do everything in QuantizePixel, and InitialQuantizePixel will not be called. Implies ResizeForFirstPass=False and FourPass=false=
FourPass If true, image is re-paletted after quantization - forces 2 clones of the original image to be created. FixedPalette and OmitFinalStage should be false if this is used.
FullTrust If true, pointer arithmetic will be used instead of GetPixel. GetPixel is much slower. If false, OmitFinalStage will be assumed true, as only palette generation is possible in low trust. Defaults to true.
OmitFinalStage If true, a 32-bit image with an 8-bit palette will be returned instead of an 8-bit image, which GDI can save using median-cut quantization. Much faster than our final quantization pass, although it can't do transparency. Assumed true if FullTrust is false.
PixelSize The number of bytes in a ARGB structure. Should be 4
ResizeForFirstPass If true, the first pass (InitialQuantizePixel) will be performed on a size-limited version of the original image to control performance. Ignored if FixedPalette=True


AdjustNeighborSource(int, int, int, int, int, int) Can only be called from QuantizePixel... This is how dithering is done... 5-18-09 ndj
AnalyzeImage(BitmapData, int, int) Execute the first pass through the pixels in the image
AnalyzeImageLowTrust(Bitmap, int, int)
GetPalette(ColorPalette) Retrieve the palette for the quantized image
InitialQuantizePixel(Quantizer.Color32) Override this to process the pixel in the first pass of the algorithm
Quantize(Image) Quantize an image and return the resulting output bitmap
QuantizeFullTrust(Bitmap, Bitmap, Bitmap, Bitmap)
QuantizeImage(BitmapData, BitmapData, Bitmap, int, int, Rectangle) Execute a second pass through the bitmap. If dithering is enabled, sourceData will be modified.
QuantizeLowTrust(Bitmap, Bitmap, Bitmap, Bitmap)
QuantizePixel(Quantizer.Color32) Override this to process the pixel in the second pass of the algorithm
Reset() Resets the quantizer so it can process a new image.

Extension Methods

IsNullOrDefault(T) Gets a value indicating if the specified value has the default value of the generic type.
Serialize(object) Serializes an object, or graph of connected objects, to a byte array.
SerializeToJson(object, Formatting?, JsonSerializerSettings) Serializes an object, or graph of connected objects, to a json string.
IsValid(object) Determines whether the specified object is valid by evaluating each ValidationAttribute instance that is attached to the object type.