This is an include to quantize true-color images to 256 colors (8 bit).
The code use the NeuQuant C algorithm by Anthony Dekker
and is based on Kohonen neural networks for optimal colour quantization, I also added Floyd-Steinberg and Sierra filters (for optional dithering) to the original implementation. Quality was the first priority, speed came second.
The NeuQuant include translated to PB should be cross-platform
, usage from any OS is explained in the include, you only have to provide the image data in the right format.
The rest of the code (the one calling it) is Windows x86/x64 only.
The code is modular enough to permit you to add more dithering algorithms AND more quantization algorithms easily if you like, just following the same method I used. The dithering algorithms are separated in dedicated macros.
The zip contains a simple program and the source images showed in the picture below, good for testing.
Thanks to Netmaestro for the code to save the 8 bit bmp to file.
What do you think ? EDIT: IMPORTANT
Now PB uses this same algorithm to quantize images from 24 to 8 bits, with an optional Floid-Steinberg dithering.
So you can probably use its native implementation
directly and forget about this !
The differences, for what I can see, are:
1) with this source you can specify different levels of quality
2) you have two type of dithering and you can easily add more for yourself using macros following the examples in Macros.pbi
3) this is pb code, you can modify it
4) the native implementation is cross platform
You can download the source (1.05) from --> here
EDIT: updated for PB 5.21