Neuquant Quantize 1.05 (True Color to 8 bit) - Windows
Posted: Wed Oct 21, 2009 11:49 pm
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 using the port) 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 ?
Download [... from someone who got a copy at the time].
Updated for PB 5.21
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
Bye!
EDIT 2: ASM SSE2 VERSION !
Wilbert has done a version in ASM using SSE2 instructions (so the CPU need to support that) and it's at least 3 time faster than this !
See it here -> http://www.purebasic.fr/english/viewtop ... 33#p434633
So now you have a lot of different options: the PB implementation, this one with the PB source, and one written is ASM !
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 using the port) 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 ?
Download [... from someone who got a copy at the time].
Updated for PB 5.21
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
Bye!
EDIT 2: ASM SSE2 VERSION !
Wilbert has done a version in ASM using SSE2 instructions (so the CPU need to support that) and it's at least 3 time faster than this !
See it here -> http://www.purebasic.fr/english/viewtop ... 33#p434633
So now you have a lot of different options: the PB implementation, this one with the PB source, and one written is ASM !