Table of Contents

Class QuantizerUtilities

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

Contains utility methods for IQuantizer<TPixel> instances.

public static class QuantizerUtilities
Inheritance
QuantizerUtilities
Inherited Members

Methods

BuildPaletteAndQuantizeFrame<TPixel>(IQuantizer<TPixel>, ImageFrame<TPixel>, Rectangle)

Execute both steps of the quantization.

public static IndexedImageFrame<TPixel> BuildPaletteAndQuantizeFrame<TPixel>(this IQuantizer<TPixel> quantizer, ImageFrame<TPixel> source, Rectangle bounds) where TPixel : unmanaged, IPixel<TPixel>

Parameters

quantizer IQuantizer<TPixel>

The pixel specific quantizer.

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.

Type Parameters

TPixel

The pixel type.

BuildPalette<TPixel>(IQuantizer<TPixel>, IPixelSamplingStrategy, ImageFrame<TPixel>)

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

public static void BuildPalette<TPixel>(this IQuantizer<TPixel> quantizer, IPixelSamplingStrategy pixelSamplingStrategy, ImageFrame<TPixel> source) where TPixel : unmanaged, IPixel<TPixel>

Parameters

quantizer IQuantizer<TPixel>

The pixel specific quantizer.

pixelSamplingStrategy IPixelSamplingStrategy

The pixel sampling strategy.

source ImageFrame<TPixel>

The source image frame to sample from.

Type Parameters

TPixel

The pixel format.

BuildPalette<TPixel>(IQuantizer<TPixel>, IPixelSamplingStrategy, Image<TPixel>)

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

public static void BuildPalette<TPixel>(this IQuantizer<TPixel> quantizer, IPixelSamplingStrategy pixelSamplingStrategy, Image<TPixel> source) where TPixel : unmanaged, IPixel<TPixel>

Parameters

quantizer IQuantizer<TPixel>

The pixel specific quantizer.

pixelSamplingStrategy IPixelSamplingStrategy

The pixel sampling strategy.

source Image<TPixel>

The source image to sample from.

Type Parameters

TPixel

The pixel format.

CheckPaletteState<TPixel>(in ReadOnlyMemory<TPixel>)

Helper method for throwing an exception when a frame quantizer palette has been requested but not built yet.

public static void CheckPaletteState<TPixel>(in ReadOnlyMemory<TPixel> palette) where TPixel : unmanaged, IPixel<TPixel>

Parameters

palette ReadOnlyMemory<TPixel>

The frame quantizer palette.

Type Parameters

TPixel

The pixel format.

Exceptions

InvalidOperationException

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

DeepClone(QuantizerOptions, Action<QuantizerOptions>?)

Performs a deep clone the QuantizerOptions instance and optionally mutates the clone.

public static QuantizerOptions DeepClone(this QuantizerOptions options, Action<QuantizerOptions>? mutate)

Parameters

options QuantizerOptions

The QuantizerOptions instance to clone.

mutate Action<QuantizerOptions>

An optional delegate to mutate the cloned instance.

Returns

QuantizerOptions

The cloned QuantizerOptions instance.

QuantizeFrame<TFrameQuantizer, TPixel>(ref TFrameQuantizer, ImageFrame<TPixel>, Rectangle)

Quantizes an image frame and return the resulting output pixels.

public static IndexedImageFrame<TPixel> QuantizeFrame<TFrameQuantizer, TPixel>(ref TFrameQuantizer quantizer, ImageFrame<TPixel> source, Rectangle bounds) where TFrameQuantizer : struct, IQuantizer<TPixel> where TPixel : unmanaged, IPixel<TPixel>

Parameters

quantizer TFrameQuantizer

The pixel specific quantizer.

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.

Type Parameters

TFrameQuantizer

The type of frame quantizer.

TPixel

The pixel format.

ReplacePixelsByAlphaThreshold(Span<Vector4>, float)

Replaces pixels in a span with fully transparent pixels based on an alpha threshold.

public static void ReplacePixelsByAlphaThreshold(Span<Vector4> source, float threshold)

Parameters

source Span<Vector4>

A span of color vectors that will be checked for transparency and potentially modified.

threshold float

The alpha threshold used to determine if a pixel is transparent.

ShouldReplacePixelsByAlphaThreshold<TPixel>(float)

Determines if transparent pixels can be replaced based on the specified color mode and pixel type.

public static bool ShouldReplacePixelsByAlphaThreshold<TPixel>(float threshold) where TPixel : unmanaged, IPixel<TPixel>

Parameters

threshold float

The alpha threshold used to determine if a pixel is transparent.

Returns

bool

Returns true if transparent pixels can be replaced; otherwise, false.

Type Parameters

TPixel

The type of the pixel.