Class PaletteOptions
- Namespace
- Egami.Quantization
- Assembly
- Egami.dll
How formats with at most 256 colors (GIF, PNG with a palette, and indexed BMP and TGA) build their palette when an image has more colors than fit. Images with few enough colors always keep them exactly, without dithering.
public sealed record PaletteOptions : IEquatable<PaletteOptions>
- Inheritance
-
PaletteOptions
- Implements
- Inherited Members
Examples
using FileStream output = File.Create("duck.gif");
photo.Save(output, GifFormat.Info, new GifWriterOptions
{
Palette = new PaletteOptions { MaxColors = 128, Dither = DitherMode.Ordered }, // FloydSteinberg (default), Ordered or None
PaletteScope = GifPaletteScope.PerFrame, // Auto (default): one table when all frames fit, else one per frame
});
Properties
AlphaThreshold
Gets the alpha below which a pixel is transparent, for formats whose transparency is on or off (GIF). Defaults to 128.
public byte AlphaThreshold { get; init; }
Property Value
Default
Gets the default options: 256 colors, Floyd–Steinberg dithering at full strength, alpha threshold 128.
public static PaletteOptions Default { get; }
Property Value
Dither
Gets how mapping error is spread. Defaults to FloydSteinberg.
public DitherMode Dither { get; init; }
Property Value
Exceptions
- ArgumentOutOfRangeException
The value is not a defined DitherMode.
DitherStrength
Gets how strongly the dither works, from 0 (none: the nearest color) to 1 (the default, full strength): the share of the error that is diffused, or the height of the ordered pattern.
public float DitherStrength { get; init; }
Property Value
Exceptions
- ArgumentOutOfRangeException
The value is outside 0 to 1.
ExactMatching
Gets whether each color is matched to its exact nearest palette color. By default a 64-level lookup table answers for each small cube of colors at once, which is faster and can pick a color that is not quite the nearest; the default keeps every 1.x output unchanged.
public bool ExactMatching { get; init; }
Property Value
FixedPalette
Gets a fixed palette to map to instead of building one, or null (the default) to build one from the image. Every writer that takes these options honours it, and throws when the palette has more colors than its format allows.
public Palette? FixedPalette { get; init; }
Property Value
Kernel
public ErrorDiffusionKernel? Kernel { get; init; }
Property Value
MaxColors
Gets the most colors the palette may have, 2 to 256. Defaults to 256; a transparent entry counts as one.
public int MaxColors { get; init; }
Property Value
Exceptions
- ArgumentOutOfRangeException
The value is outside 2 to 256.
RefineIterations
Gets how many k-means passes polish the built palette, moving each color to the mean of the pixels nearest it (Lloyd's algorithm on every fourth pixel), from 0 (the default) to 32. 4 to 8 passes gain a few tenths of a decibel at some cost; they never make the palette fit worse.
public int RefineIterations { get; init; }
Property Value
Exceptions
- ArgumentOutOfRangeException
The value is outside 0 to 32.
Serpentine
Gets whether error diffusion alternates direction from row to row (serpentine scanning), which breaks up the diagonal streaks plain left-to-right diffusion can leave. Defaults to false.
public bool Serpentine { get; init; }