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
quantizerIQuantizer<TPixel>The pixel specific quantizer.
sourceImageFrame<TPixel>The source image frame to quantize.
boundsRectangleThe bounds within the frame to quantize.
Returns
- IndexedImageFrame<TPixel>
A IndexedImageFrame<TPixel> representing a quantized version of the source frame pixels.
Type Parameters
TPixelThe 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
quantizerIQuantizer<TPixel>The pixel specific quantizer.
pixelSamplingStrategyIPixelSamplingStrategyThe pixel sampling strategy.
sourceImageFrame<TPixel>The source image frame to sample from.
Type Parameters
TPixelThe 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
quantizerIQuantizer<TPixel>The pixel specific quantizer.
pixelSamplingStrategyIPixelSamplingStrategyThe pixel sampling strategy.
sourceImage<TPixel>The source image to sample from.
Type Parameters
TPixelThe 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
paletteReadOnlyMemory<TPixel>The frame quantizer palette.
Type Parameters
TPixelThe 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
optionsQuantizerOptionsThe QuantizerOptions instance to clone.
mutateAction<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
quantizerTFrameQuantizerThe pixel specific quantizer.
sourceImageFrame<TPixel>The source image frame to quantize.
boundsRectangleThe bounds within the frame to quantize.
Returns
- IndexedImageFrame<TPixel>
A IndexedImageFrame<TPixel> representing a quantized version of the source frame pixels.
Type Parameters
TFrameQuantizerThe type of frame quantizer.
TPixelThe 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
sourceSpan<Vector4>A span of color vectors that will be checked for transparency and potentially modified.
thresholdfloatThe 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
thresholdfloatThe alpha threshold used to determine if a pixel is transparent.
Returns
- bool
Returns true if transparent pixels can be replaced; otherwise, false.
Type Parameters
TPixelThe type of the pixel.