more accurate color bit depth reduction?

metamax's icon

I need to reduce 24-bit color values to various other bit depths. Certain conventional methods don't seem to yield the best possible results. I'm including an example of 24-bit to 6-bit reduction. Obviously there will be an appreciable loss of apparent resolution regardless of the method.. however it doesn't need to be as significant as the enclosed method entails. Any suggestions on improving the conversion? Something that can be applied to other bit depths as well would be ideal.

Max Patch
Copy patch and select New From Clipboard in Max.

metamax's icon

Anyone? This is all related to a sound project I'm doing where I am going in and out of different bit depths of color.

I just cleaned up the example patch so it's easier to follow. Any feedback would be greatly appreciated. Thanks.