View Single Post
Old 12 April 2011, 01:10   #1
Lord Riton
Registered User
 
Lord Riton's Avatar
 
Join Date: Jan 2011
Location: France
Age: 52
Posts: 507
ISO true color to 256 color algorithm

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:
Click image for larger version

Name:	023.png
Views:	948
Size:	58.6 KB
ID:	28388


- 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:
Click image for larger version

Name:	024.png
Views:	744
Size:	76.0 KB
ID:	28389


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:
Click image for larger version

Name:	026.png
Views:	728
Size:	55.2 KB
ID:	28391

With the first , simplier algorithm, these green pixels aren't there:
Click image for larger version

Name:	025.png
Views:	745
Size:	45.2 KB
ID:	28390


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:
Click image for larger version

Name:	027.png
Views:	772
Size:	68.9 KB
ID:	28392

and with the advanced algorithm:
Click image for larger version

Name:	028.png
Views:	816
Size:	86.7 KB
ID:	28393

Last edited by Lord Riton; 12 April 2011 at 01:40.
Lord Riton is offline  
 
Page generated in 0.05464 seconds with 12 queries