A small program written in C demonstrating implementations of common image dithering algorithms such as Floyd-Steinberg, error-diffuse dithering and ordered dithering. The program takes an image file and optionally a text file containing a list of hex codes to use as a colour palette.
The code is in dither.c. Methods prefixed with render (render_monochrome_1D_errordiffuse, render_monochrome_floydstein, render_monochrome_ordered4x4 etc.) contain the implementations of the different algorithms for reference. The final quantised colour for each pixel is determined by the shortest euclidean distance between colours: sqrt(Δr + Δg + Δb)
Dither.exe runs in the Windows command prompt (or under any terminal emulator on Windows):
dither.exe imagefile.png palette.txt
./dither imagefile.png palette.txt (unix/bash terminal emulators)
imagefile.png - A png image (also supports jpeg)
palette.txt - A text file with hex colour codes arranged on separate lines (see included files for examples)
Move back and forth between the different dithering algorithms using the < arrow keys >.
A windows build of the program is included with the required DLLs. The program requires SDL2 and SDL2_Image which must be downloaded if you wish to compile the code for a different OS.