PredefinedColorsQuantizerSystemDefault4BppPalette Method

Gets a PredefinedColorsQuantizer instance that quantizes colors using the system default 4-bit palette. This palette consists of the 16 standard basic sRGB colors.

Definition

Namespace: KGySoft.Drawing.Imaging
Assembly: KGySoft.Drawing.Core (in KGySoft.Drawing.Core.dll) Version: 8.1.0
C#
public static PredefinedColorsQuantizer SystemDefault4BppPalette(
	Color backColor = default
)

Parameters

backColor  Color  (Optional)
Colors with alpha (transparency) will be blended with this color before quantization. The Color.A property of the background color is ignored. This parameter is optional.
Default value: Empty, which has the same RGB values as Black.

Return Value

PredefinedColorsQuantizer
A PredefinedColorsQuantizer instance that quantizes colors using the system default 4-bit palette.

Remarks

The returned PredefinedColorsQuantizer instance can return up to 16 colors.

This quantizer fits well for the Format4bppIndexed pixel format.

The palette of this quantizer is not expected to contain transparent entries. The palette consists of the 16 standard basic sRGB colors

Example

The following example demonstrates how to use the quantizer returned by this method:
C#
public static IReadWriteBitmapData ToDefault4Bpp(IReadWriteBitmapData source, Color backColor = default, IDitherer ditherer = null)
{
    IQuantizer quantizer = PredefinedColorsQuantizer.SystemDefault4BppPalette(backColor);

    // a.) this solution returns a new bitmap data and does not change the original one:
    return source.Clone(KnownPixelFormat.Format8bppIndexed, quantizer, ditherer);

    // b.) when converting to Format4bppIndexed format without dithering, this produces the same result:
    if (ditherer == null)
        return source.Clone(KnownPixelFormat.Format4bppIndexed, backColor);

    // c.) alternatively, you can perform the quantization directly on the source bitmap data:
    if (ditherer == null)
        source.Quantize(quantizer);
    else
        source.Dither(quantizer, ditherer);
    return source;
}

The example above may produce the following results:

Original image
Quantized image

Color hues with alpha gradient
Color hues with alpha gradient

Color hues with system default 4 BPP palette and black background
Default optional parameter values (black background)

Color hues with system default 4 BPP palette and silver background
Silver background

Color hues with system default 4 BPP palette, using silver background and a stronger Bayer 8x8 ordered dithering
Silver background, Bayer 8x8 dithering with strength = 0.5

Grayscale color shades with different bit depths
Grayscale color shades

Grayscale color shades with system default 4 BPP palette
Default optional parameter values. The asymmetry is due to the uneven distribution of gray shades of this palette.

Grayscale color shades with system default 4 BPP palette using Bayer 8x8 ordered dithering
Bayer 8x8 dithering using auto strength. Darker shades have banding.

Grayscale color shades with system default 4 BPP palette using a stronger Bayer 8x8 ordered dithering
Bayer 8x8 dithering using strength = 0.5. Now there is no banding but white suffers from overdithering.

Grayscale color shades with system default 4 BPP palette using 8x8 ordered dithering with interpolated ato strength
Bayer 8x8 dithering using Interpolated auto strength strategy. Now there is neither banding nor overdithering for black or white colors.

Shield icon with transparent background
Shield icon with transparency

Shield icon with system default 4 BPP palette and black background
Default optional parameter values (black background)

Shield icon with system default 4 BPP palette and silver background
Silver background

Shield icon with system default 4 BPP palette using silver background and Floyd-Steinberg dithering
Silver background, Floyd-Steinberg dithering

See Also