See the Remarks section for details.
KGySoft.Drawing.ImagingPalette
Namespace: KGySoft.Drawing.Imaging
Assembly: KGySoft.Drawing.Core (in KGySoft.Drawing.Core.dll) Version: 7.0.0-preview.2
The Palette type exposes the following members.
Name | Description | |
---|---|---|
![]() | Palette(Palette, Color32, Byte) |
Initializes a new instance of the Palette class from another palette using
new backColor and alphaThreshold values.
|
![]() | Palette(Color, Color, Byte, FuncColor32, Int32) |
Initializes a new instance of the Palette class.
See the Remarks section of the Palette class for details. |
![]() | Palette(Color32, Color32, Byte, FuncColor32, Int32) |
Initializes a new instance of the Palette class.
See the Remarks section of the Palette class for details. |
Name | Description | |
---|---|---|
![]() | AlphaThreshold |
If this Palette has a transparent entry, then gets a threshold value for the Color32.A field,
under which lookup operations will return the first transparent color (GetNearestColor)
or the index of the first transparent color (GetNearestColorIndex) in the palette.
|
![]() | BackColor |
Gets the background color. If a lookup operation (GetNearestColor, GetNearestColorIndex)
is performed with a color whose Color32.A field is equal to or greater than AlphaThreshold, and there is no exact match among the entries of this Palette,
then the color will be blended with this color before performing the lookup.
|
![]() | Count |
Gets the number of color entries in the current Palette.
|
![]() | HasAlpha |
Gets whether the palette contains at least one entry that is not fully opaque.
|
![]() | IsGrayscale |
Gets whether the palette consists only of grayscale entries.
|
![]() | Item |
Gets the color entry of this Palette at the specified index.
|
Name | Description | |
---|---|---|
![]() ![]() | BlackAndWhite |
Gets a Palette instance that uses the black and white colors.
See the Remarks section of the PredefinedColorsQuantizer.BlackAndWhite method for details and some examples. |
![]() | GetColor |
Gets the color entry of this Palette at the specified index.
|
![]() | GetEntries |
Gets a read-only wrapper of the entries of this Palette instance.
|
![]() | GetNearestColor | |
![]() | GetNearestColorIndex |
Gets the index of a Palette entry that is the nearest color to the specified Color32 instance.
See the Remarks section for details. |
![]() ![]() | Grayscale16 |
Gets a Palette instance that uses a 4-bit grayscale palette of 16 shades.
See the Remarks section of the PredefinedColorsQuantizer.Grayscale16 method for details and some examples. |
![]() ![]() | Grayscale256 |
Gets a Palette instance that uses a 8-bit grayscale palette of 256 shades.
See the Remarks section of the PredefinedColorsQuantizer.Grayscale method for details and some examples. |
![]() ![]() | Grayscale4 |
Gets a Palette instance that uses a grayscale palette of 4 shades.
See the Remarks section of the PredefinedColorsQuantizer.Grayscale4 method for details and some examples. |
![]() ![]() | Rgb332 |
Gets a Palette instance that uses a 8-bit palette where red, green and blue components are encoded in 3, 3 and 2 bits, respectively.
See the Remarks section of the PredefinedColorsQuantizer.Rgb332 method for details and some examples. |
![]() ![]() | SystemDefault1BppPalette |
Gets a Palette instance that uses the system default 1-bit palette.
This palette consists of the black and white colors.
See the Remarks section of the PredefinedColorsQuantizer.SystemDefault1BppPalette method for details. |
![]() ![]() | SystemDefault4BppPalette |
Gets a Palette instance that uses the system default 4-bit palette.
This palette consists of the 16 standard basic sRGB colors.
See the Remarks section of the PredefinedColorsQuantizer.SystemDefault4BppPalette method for details and some examples. |
![]() ![]() | SystemDefault8BppPalette |
Gets a Palette instance that uses the system default 8-bit palette.
This palette contains the 16 standard basic sRGB colors,
the "web-safe" palette of 216 colors as well as 24 transparent entries.
See the Remarks section of the PredefinedColorsQuantizer.SystemDefault8BppPalette method for details and some examples. |
The Palette class can be used to perform quick lookup operations (see GetNearestColor and GetNearestColorIndex methods) to find the closest matching palette entry to any color.
By default the lookup is performed by a slightly modified euclidean-like search but if the Palette contains grayscale entries only, then it is optimized for finding the best matching gray shade based on human perception. To override this logic a custom lookup routine can be passed to the constructors.
If the Palette instance is created without a custom lookup logic, then the search results for non-palette-entry colors are cached. The cache is optimized for parallel processing. The theoretical maximum of cache size (apart from the actual palette entries) is 2 x 218 but as soon as that limit is reached the amount of stored elements are halved so the cache is somewhat optimized to store the most recently processed colors.
In order to prevent caching you can pass a custom lookup logic to the constructors. It is expected to be fast (applying some direct mapping to a palette index, for example), or that it uses some custom caching (which should perform well also when queried concurrently).
The palette can have any number of colors but as the typical usage is quantizing colors for indexed bitmaps the typical maximum palette size is 256. Generally, the more colors the palette has the slower are the lookups for non-palette colors that are not cached yet.