This is an implementation of the Floyd-Steinberg dithering algorithm in OCaml.
$ dune exec ./src/main.ml input-image.jpg output-image.jpg
Original Image (3 bytes per pixel):
Color Compression - No Dithering (3 bits per pixel):
Color Compression - Floyd-Steinberg Dithering (3 bits per pixel):
If you look closely on the image generated by the Floyd-Steinberg algorithm, you can see that the pixels have very "raw" colors (3 bits gives us just 8 colors)