Tool · 2026-11-02
Dithering, and where the light goes.
A screen with two colours can still show grey if it mixes them finely enough. Dithering decides which pixel gets which colour. Most implementations do that arithmetic on sRGB values, which are not amounts of light, and the picture comes out brighter than it should. Pick an algorithm, then flip the space it works in.
- light in, whole image
- —
- light out
- —
- squint error (rms)
- —
| Test square | Light in | Light out | Ratio |
|---|
Test image, bottom right: #808080, #bcbcbc, and a one-pixel black and white checkerboard. Uploaded images never leave your browser.
Note
Look at the three squares in the corner of the test image. The checkerboard is half black pixels and half white ones, so from a distance it sends exactly half the light of white. Of the two solid squares, the one that matches it when you squint is #bcbcbc, not #808080. sRGB stores brightness on a curve close to a 2.2 power so that eight bits are spent where eyes can tell the difference. The value 128 out of 255 stands for about 21.6 percent of full light. The value 188 stands for 50 percent.
A ditherer that treats 128 as "half" will turn #808080 into half white pixels. That emits 0.50 where the original emitted 0.216, which the table above reports as a ratio of about 2.3. The whole image drifts brighter in the midtones and the shadows. Switch the working space to linear light and the code converts every value with the sRGB transfer function before it compares or carries any error, then the ratios fall to within a percent or two of 1.
Threshold and the two Bayer patterns look at one pixel at a time. Bayer adds a fixed offset taken from a recursively built matrix before rounding, so a flat grey becomes a regular crosshatch. It parallelises perfectly, which is why GPUs and old consoles used it. Random noise does the same with an unstructured offset and looks worse for it.
The error diffusion methods round a pixel, measure how far off the result is, and push that difference onto neighbours that have not been visited yet. Floyd and Steinberg's 1976 kernel spreads it over four pixels with weights 7, 3, 5 and 1 out of 16. Jarvis, Judice and Ninke spread it over twelve, which smooths the texture and costs three times the work. Sierra Lite uses three. Bill Atkinson's version for the original Macintosh hands on only six eighths of the error and drops the rest. Highlights and shadows clip to pure white and black, which gave early Mac screenshots their crisp look. The "light out" readout shows the price: Atkinson is the only diffusion kernel here that does not conserve light even in linear mode.
Scanning every row left to right lets error pile up in one direction, which shows as diagonal worms in flat areas. Serpentine order reverses every other row and mirrors the kernel, and the worms mostly go away.
Squint blurs both images with three passes of a 5-pixel box filter, close to a Gaussian with a radius of about 2.4 pixels. The blur runs in linear light, since that is what an eye or a camera integrates. The rms figure compares the two blurred luminances, ignoring a six-pixel border. It is a rough stand-in for perceived error, and it favours the methods whose noise sits at high frequencies.
Colour palettes pick the nearest entry by straight Euclidean distance in whichever space is active. That is not perceptually uniform, and with a palette as lopsided as CGA's it shows: some skin tones resolve to magenta. A careful implementation would measure distance in a space like OKLab while still diffusing the error in linear RGB. This page does not.
Sources
- Floyd, R. W., Steinberg, L. (1976). An adaptive algorithm for spatial greyscale. Proceedings of the Society for Information Display, 17(2), pages 75-77.
- Jarvis, J. F., Judice, C. N., Ninke, W. H. (1976). A survey of techniques for the display of continuous tone pictures on bilevel displays. Computer Graphics and Image Processing, 5(1), pages 13-40.
- Bayer, B. E. (1973). An optimum method for two-level rendition of continuous-tone pictures. IEEE International Conference on Communications, pages 26.11-26.15.
- IEC 61966-2-1:1999. Multimedia systems and equipment, colour measurement and management, part 2-1: default RGB colour space, sRGB.
- Ulichney, R. (1987). Digital Halftoning. MIT Press.