So, here's my new hardcore-problem:
I need to write a proggy that generates an 8-Bit Paletted Image from a 24Bit RGB Image.
Until now I used to scan the whole RGB Pixel Buffer and generare a Color List. Then I sorted the colors by the number they were used in the image.
However, this brings certain problems:
1. It takes a LOT of time of generate the Color List. (e.g. in a 600x400 Image there are 240.000 possible colors)
2. It takes even more time to sort the Color List via BubbleSort...
3. Let's say you've got an image of a sky with a rainbow on it. The sky will take 75% of the picture and only 25% are used by the rainbow. So it is clear that the palette generate will generate a palette with 240 blue colors (for the sky) and about 16 for the rainbow itself...
So this is no solution. I read something about a method called "Quantization" and I already downloaded a (scientific) document about it, however, I don't really understand it...

So is there anyone in here who knows how this algorithm works?
(If not, I will have to ask my maths teacher on monday...)
Thanx
- Alhexx
- edit -
Oh, and things like dithering are not important: I have already included some dithering algorithms like Floyd-Steinberg and so on ... I just need to calculate an optimal palette...