OrderedDitherer Class

KGy SOFT Drawing Libraries Help
Provides an IDitherer implementation for dithering patterns that are based on an ordered matrix. Use the static properties of this class to use predefined patterns or the constructor to create a custom ordered ditherer.
See the Remarks section for details and some image examples.
Inheritance Hierarchy

SystemObject
  KGySoft.Drawing.ImagingOrderedDitherer

Namespace:  KGySoft.Drawing.Imaging
Assembly:  KGySoft.Drawing (in KGySoft.Drawing.dll) Version: 5.0.0
Syntax

public sealed class OrderedDitherer : IDitherer

The OrderedDitherer type exposes the following members.

Constructors

  NameDescription
Public methodCode exampleOrderedDitherer
Initializes a new instance of the OrderedDitherer class using the specified matrix and strength.
See the Examples section for some examples.
Top
Properties

  NameDescription
Public propertyStatic memberCode exampleBayer2x2
Gets an OrderedDitherer using the standard Bayer 2x2 matrix.
See the Examples section for some examples.
Public propertyStatic memberCode exampleBayer3x3
Gets an OrderedDitherer using the standard Bayer 3x3 matrix.
See the Examples section for some examples.
Public propertyStatic memberCode exampleBayer4x4
Gets an OrderedDitherer using the standard Bayer 4x4 matrix.
See the Examples section for some examples.
Public propertyStatic memberCode exampleBayer8x8
Gets an OrderedDitherer using the standard Bayer 8x8 matrix.
See the Examples section for some examples.
Public propertyStatic memberCode exampleBlueNoise
Gets an OrderedDitherer using a fixed 64x64 blue noise pattern of 256 different values.
See the Examples section for some examples.
Public propertyStatic memberCode exampleDottedHalftone
Gets an OrderedDitherer using a 8x8 matrix of a dotted halftone pattern.
See the Examples section for some examples.
Top
Methods

  NameDescription
Public methodCode exampleConfigureStrength
Gets a new OrderedDitherer instance that has the specified dithering strength.
See the Remarks section for details.
Top
Remarks

The constructor can be used to create an ordered ditherer using a custom matrix.

Use the static properties to obtain an instance with a predefined pattern. For the best results use the Bayer8x8 or BlueNoise properties. Or you can use the DottedHalftone property for artistic results.

The OrderedDitherer class offers a very fast dithering technique based on an ordered pattern specified in a matrix of bytes. The more different values the matrix has the more number of different patterns can be mapped to the shades of the original pixels. While quantizing lighter and lighter colors, the different patterns appear in the order of the values in the specified matrix.

The following table demonstrates the effect of the dithering:

Original imageQuantized image

Color hues with alpha gradient
Color hues with alpha gradient

Color hues with system default 8 BPP palette and silver background
Quantizing with system default 8 BPP palette, no dithering

Color hues with system default 8 BPP palette, silver background and Bayer 8x8 ordered dithering
Quantizing with system default 8 BPP palette and Bayer 8x8 dithering

Color hues with system default 8 BPP palette, using silver background and blue noise dithering
Quantizing with system default 8 BPP palette and blue noise dithering

Color hues with system default 8 BPP palette, using silver background and rectangular 7x7 dotted halftone pattern dithering
Quantizing with system default 8 BPP palette and dotted halftone pattern dithering

Grayscale color shades with different bit depths
Grayscale color shades

Grayscale color shades with black and white palette
Quantizing with black and white palette, no dithering

Grayscale color shades with black and white palette, using Bayer 8x8 ordered dithering
Quantizing with black and white palette and Bayer 8x8 dithering

Grayscale color shades with black and white palette using blue noise dithering
Quantizing with black and white palette and blue noise dithering

Grayscale color shades with black and white palette using rectangular 7x7 dotted halftone pattern dithering
Quantizing with black and white palette and dotted halftone pattern dithering

Unlike in case of the ErrorDiffusionDitherer, ordered dithering does not adjust strength to the quantization error of a pixel but simply uses the specified matrix values based on pixel coordinates to determine the quantized result. Therefore, a strength can be specified (see the constructor and the ConfigureStrength method), whose ideal value depends on the colors that a quantizer can return. If the strength is too low, then banding may appear in the result in place of gradients in the original image; whereas if the strength is too high, then dithering patterns may appear even in colors without quantization error (overdithering).

Every static property in the OrderedDitherer returns an instance with auto strength, meaning that strength will be calibrated for each dithering session so that neither the black, nor the white colors will suffer from overdithering in the result. The auto value is usually correct if the quantizer returns evenly distributed colors. To obtain an OrderedDitherer instance with custom strength use the ConfigureStrength method.

The following table demonstrates the effect of different strengths:

Original imageQuantized image

Grayscale color shades with different bit depths
Grayscale color shades

Grayscale color shades with system default 4 BPP palette
Quantizing with system default 4 BPP palette, no dithering. 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
Quantizing with system default 4 BPP palette and 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
Quantizing with system default 4 BPP palette and Bayer 8x8 dithering using strength = 0.5. Now there is no banding but white suffers from overdithering.

Tip Tip
See the Examples section of the static properties for more examples.
See Also

Reference