Libdither is a library for black-and-white image dithering, written in C (ANSI C99 standard). Libdither has no external dependencies and should compile easily on most current systems.
Dithering algorithms:
- Grid dithering
- Ordered dithering, incl. Blue Noise dithering
- Error diffusion dithering
- Variable error diffusion (Ostromoukhov, Zhou Fang)
- Pattern dithering
- Direct Binary Search (DBS) dithering
- Dot diffusion
- Kacker and Allebach dithering
- Riemersma dithering
- Thresholding
Other features:
- Libdither works in linear color space and takes image gamma into account
- Dither matrices and inputs can be easily extended without having to change the dither code itself
- no external dependencies on other libraries
- tested on Windows (MingW w64 11.2.0, MSVC 2019), Linux (gcc 11.2.0) and macOS (clang 13.1.6)
- works with C and C++ projects
- fairly portable code (most prototyping was done in Python)
- universal binary support (intel and Apple silicon) for macOS
You need an ANSI C compiler and the make utility. Run make
to display all build options.
By default, libdither is built for the current architecture.
Once compiled, you can find the finished library in the dist
directory.
macOS notes:
- Installing the XCode command line tools is all you need for building libdither
- You can choose if you want to build a x64, arm64 or universal library. The demo, however, only builds against the current machine's architecture.
Linux notes:
gcc
andmake
is all you need to build libdither. E.g. on Ubuntu you should install build-essential viaapt
to get these tools.
Windows notes:
- You can build both MingW and MSVC targets from the Makefile (sorry, no .sln)
- For MingW, open the Makefile and ensure the path (on top of the file) points to your MingW installation directory
- Install make via Chocolatey package manager from chocolatey.org (https://chocolatey.org/, https://chocolatey.org/packages/make)
The src/demo
example shows how to load an image (we use .bmp as it's an easy format to work with),
convert it to linear color space, dither it, and write it back to an output .bmp file. The demo was used
to create all the dithering examples you can see below.
You can also look at libdither.h
, which includes commentary on how to use libdither.
In your own code, you only need to #include "libdither.h"
, which includes all public functions
and data structures, and link the libdither library, either statically or dynamically.