Hello,
I'm trying to transform 24 bit color images into 256 color images.
I have a fixed palette of 255 colors as restriction which cannot be changed (it's for a game and i need to have several different bitmaps on the screen at the same time)
Just in case of anyone interested into the actual color palette, i creat it like that:
Code:
creatColorTable
move.l #1,d0 ; color counter
move.l #21,d1 ; Red counter
cct02 move.l #21,d2 ; Green counter
cct03 move.l #21,d3 ; Blue counter
cct04 PALETTE vp4,d0,d1,d2,d3,CM
add.l #1,d0
add.l #42,d3
cmp.l #255,d3
bmi.b cct04
add.l #42,d2
cmp.l #255,d2
bmi.b cct03
add.l #42,d1
cmp.l #255,d1
bmi.b cct02
It creats a 216 color entry table, with 6 values of red, green and blue, all mixed up.
I add to that a 32 color table with only gray , from white to black), and that's pretty much it.
I have created 2 algorithms to convert 24 bit images into 256 color images using this palette above.
- One normal algorithm that simply chooses the color from the 256 color table that is closest to the actual 24 bit color pixel at it's same place. this doesn't give great results, here is an exemple of the conversion:
- One other algorithm that affter choosing the closest color pixel does compute the difference between the color it picked up and the color it actually should have been, and gives that diff passed to the next right and the next botom pixel (each get a half of the value). This gives much better conversion, but not always, here also an exemple with that algorithm:
But sometimes with the 2nd algorithm i get some unwanted color particles in the picture that were never there, like that one, with some green pixels into the gray wall:
With the first , simplier algorithm, these green pixels aren't there:
I tryed to look on the internet for the best algorithm, but always only found some algorithm that computes the palette new, and that i don't want, i need the conversion to be done with my actual choosen palette.
Does anyone have the "right" algorithm that would make the pictures look a lot better ? that would be great, thanks in advance
Edit:
Here is another picture showing better the difference of quality of the 2 algorithms.
This with the simple algorithm:
and with the advanced algorithm: