CrImage::Util::Dithering
Dithering algorithms for reducing color depth while maintaining visual quality. Implements error diffusion and ordered dithering techniques.
Class methods
Applies dithering to convert an image to a limited palette.
Dithering creates the illusion of more colors by distributing quantization error to neighboring pixels.
Parameters:
src: The source imagepalette: Target color palettealgorithm: Dithering algorithm to use (default: FloydSteinberg)
Returns: A new Paletted image with dithering applied
Example:
img = CrImage::PNG.read("photo.png")
palette = CrImage::Color::Palette.new([
CrImage::Color::BLACK,
CrImage::Color::WHITE,
] of CrImage::Color::Color)
dithered = CrImage::Util::Dithering.apply(img, palette)
Applies Atkinson dithering (convenience method).
Atkinson dithering distributes error to 6 pixels but only uses 75% of the error, creating a lighter, more artistic effect.
Example:
dithered = CrImage::Util::Dithering.atkinson(img, palette)
Applies Floyd-Steinberg dithering (convenience method).
Floyd-Steinberg is the most common error diffusion algorithm, distributing error to 4 neighboring pixels.
Example:
dithered = CrImage::Util::Dithering.floyd_steinberg(img, palette)
Applies ordered (Bayer matrix) dithering (convenience method).
Ordered dithering uses a threshold matrix, faster than error diffusion but produces a more regular pattern.
Example:
dithered = CrImage::Util::Dithering.ordered(img, palette)