pub fn ordered_dither(pixels: &[u8], width: usize, palette: &Palette) -> Vec<u8> ⓘExpand description
Ordered (Bayer 4×4) dither. Pixels are independent — parallelized with rayon.
The Bayer threshold is added in sRGB-fraction space, not linear. Linear-space thresholding produces ~3× the perceptual spread in shadows compared to highlights (the sRGB gamma is convex, so a fixed linear ±0.5 step is huge near 0 and tiny near 1). sRGB-space thresholding gives uniform perceptual dot density across the tonal range, matching how error diffusion already accumulates error. See GitHub issue #27.
The threshold amplitude is scaled by ordered_spread to the palette’s quantization
step so dense grayscale ramps are not swamped by full-range dither noise.