Do you have a quick way to re-map the colors in an image to a preset pallete?
Lets suppose I have loaded a typical 16 million color image and I want to change it's colors to a 4 color pallete of say:
0 - $000000 ' black
1 - $ffffff ' white
2 - $cc1211 ' red
3 - $32ef30 ' green
What routine/function would you use?
I have a modified GreyScale converter (Birdies) which is along the lines of what I'm trying to do:
Lets suppose I have loaded a typical 16 million color image and I want to change it's colors to a 4 color pallete of say:
0 - $000000 ' black
1 - $ffffff ' white
2 - $cc1211 ' red
3 - $32ef30 ' green
What routine/function would you use?
I have a modified GreyScale converter (Birdies) which is along the lines of what I'm trying to do:
Function ConvertToGreyScale(i:TPixmap) For Local y=0 Until i.height For x=0 Until i.width Local col = ReadPixel( i, x, y ) Local a = ( col & $ff000000) Local r = ( col & $ff0000 ) Shr 16 Local g = ( col & $ff00 ) Shr 8 Local b = ( col & $ff ) Local cc= (r+g+b)/3 col = a | (cc Shl 16) | (cc Shl 8) | cc WritePixel i, x, y, col Next Next EndFunctionThe bit I'm stuck on is comparing the source pixel color with the available palette colors and choosing the nearest match.
