I'm trying to do scaled quantizing on a 8 bit image.
I get input int:bits, which is 1-8 and the intensity of every pixel, 0-255.
I need to scale and quantize it.
Example:
bits = 1 // = 2 colors
pixlesin[0] = 129
// will make the out to 255
pixlesout[0] = 255 // while 129 is closer to 255 than 0
bits = 2 // = 4 colors
pixlesin[1] = 24
// will make the out to 0
pixlesout[1] = 0 // while 24 is closer to 0 than 85,170,255
and so on...
how can i make a nice formula for this? (without if and switch..)