Table of Contents

Struct HexadecatreeQuantizer<TPixel>

Namespace
SixLabors.ImageSharp.Processing.Processors.Quantization
Assembly
SixLabors.ImageSharp.dll

Quantizes an image by building an adaptive 16-way color tree and reducing it to the requested palette size.

public struct HexadecatreeQuantizer<TPixel> : IQuantizer<TPixel>, IDisposable where TPixel : unmanaged, IPixel<TPixel>

Type Parameters

TPixel

The pixel format.

Implements
IQuantizer<TPixel>
Inherited Members
Extension Methods

Remarks

Each level routes colors using one bit of RGB and, when useful, one bit of alpha, giving the tree up to 16 children per node and letting transparency participate directly in palette construction.

Fully opaque mid-tone colors use RGB-only routing so more branch resolution is spent on visible color detail. Transparent, dark, and light colors use alpha-aware routing so opacity changes can form distinct palette buckets.

Constructors

HexadecatreeQuantizer(Configuration, QuantizerOptions)

Initializes a new instance of the HexadecatreeQuantizer<TPixel> struct.

public HexadecatreeQuantizer(Configuration configuration, QuantizerOptions options)

Parameters

configuration Configuration

The configuration that provides memory allocation and pixel conversion services.

options QuantizerOptions

The quantizer options that control palette size, dithering, and transparency behavior.

Properties

Configuration

Gets the configuration.

public readonly Configuration Configuration { get; }

Property Value

Configuration

Options

Gets the quantizer options defining quantization rules.

public readonly QuantizerOptions Options { get; }

Property Value

QuantizerOptions

Palette

Gets the quantized color palette.

public ReadOnlyMemory<TPixel> Palette { get; }

Property Value

ReadOnlyMemory<TPixel>

Exceptions

InvalidOperationException

The palette has not been built via AddPaletteColors(in Buffer2DRegion<TPixel>).

Methods

AddPaletteColors(in Buffer2DRegion<TPixel>)

Adds colors to the quantized palette from the given pixel source.

public readonly void AddPaletteColors(in Buffer2DRegion<TPixel> pixelRegion)

Parameters

pixelRegion Buffer2DRegion<TPixel>

The Buffer2DRegion<T> of source pixels to register.

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

GetQuantizedColor(TPixel, out TPixel)

Returns the index and color from the quantized palette corresponding to the given color.

public readonly byte GetQuantizedColor(TPixel color, out TPixel match)

Parameters

color TPixel

The color to match.

match TPixel

The matched color.

Returns

byte

The byte index.

QuantizeFrame(ImageFrame<TPixel>, Rectangle)

Quantizes an image frame and return the resulting output pixels.

public readonly IndexedImageFrame<TPixel> QuantizeFrame(ImageFrame<TPixel> source, Rectangle bounds)

Parameters

source ImageFrame<TPixel>

The source image frame to quantize.

bounds Rectangle

The bounds within the frame to quantize.

Returns

IndexedImageFrame<TPixel>

A IndexedImageFrame<TPixel> representing a quantized version of the source frame pixels.

Remarks

Only executes the second (quantization) step. The palette has to be built by calling AddPaletteColors(in Buffer2DRegion<TPixel>). To run both steps, use BuildPaletteAndQuantizeFrame<TPixel>(IQuantizer<TPixel>, ImageFrame<TPixel>, Rectangle).