dgfjslfsgjd
04-08-2004, 03:39 PM
Hi :D, when i use onerror's quantization example for gdi+ (http://www.xtremevbtalk.com/showthread.php?t=128891&highlight=Color+Quantization) when converting a 24 bpp image to 4 bpp, the results only give me 15 colors. so there's one color left over it could have used. is there a way to improve quantization, so that all 16 colors are fully utilized?
passel
04-08-2004, 07:45 PM
Did you count black as one of the colors?
dgfjslfsgjd
04-08-2004, 09:07 PM
yeah i counted black, and any other transparant/background color as a color =)
there are also way more than 16 colors in the source image too
Mathijsken
05-30-2004, 03:03 AM
Maybe you should PM OnError about it, he might explain it as it is his code...
Mathijsken
OnErr0r
05-30-2004, 08:49 AM
Post the original image and I'll take a look.
dgfjslfsgjd
06-02-2004, 12:13 AM
Post the original image and I'll take a look.
Aright
- These two pics convert to 14 colors when the depth setting is set to quantitize to 16 colors
http://devster.retrodev.com/pub/p3010088.jpg
http://devster.retrodev.com/pub/p3010096.jpg
- This one converts to 15 colors
http://devster.retrodev.com/pub/p3010093.jpg
Some images convert to the full 16 colors, and some don't. I tried setting the depth to 17 to 20 to get the full 16 colors out of these images, but it sometimes doesn't work, and would give me more colors than i need.
I used your gdi3 example, and i did the "last missing line" addition, but i don't think that would affect quantization quality at all, maybe =)
thanx lots!
OnErr0r
06-02-2004, 12:10 PM
The problem is with the OCTree data structure, which has up to 8 child nodes per node. When the CombineNodes function is called (to reduce the number of nodes/colors in the palette) it can find from 1 to 8 child nodes to reduce. This leads to a decrease of 0 to 7 colors. So, if you specify Quantize 16, you may have a palette returned with from 9 to 16 colors.
One way around this problem might be to use the quantize code supplied, and add seven to the number of palette colors you need. Then, if the number of colors returned is greater than are needed, you pass the palette to another function which could quantize out (by averaging) the closest remaining colors until the desired quantity is reached.