Archived

This topic is now archived and is closed to further replies.

DefaultUser

Palettes in Paint Programs.

Recommended Posts

Does different programs generate different palettes, because when I copy and save a 420x380x8 (256) .BMP file to another Paint program like for example from Photoshop to MS-Paint, the file''s colors are reduced? Moreover, when I try to use different bitmaps from different Paint Programs for sprites in my game they don''t look like the original or the file won''t load (like what happen with the one I saved with Photoshop 5.5 - it won''t load), some of them looks perfect and some just looks crappy. So to fix the problem I always have to save the file using a single program, that is MS-Paint, eventhough it degrades the visual quality. Is there another way around to fix this problem? I''m using DirectDraw and I share one DDPalette to surfaces. -Thanks

Share this post


Link to post
Share on other sites
I don''t know about DirectDraw, but is this possible?
Save all your graphics in 24-bit. At the start of the program when you load the bmps in, convert them to 8-bit by iterating through every pixel and converting each 3 bytes into one according to how the palette is set. There may even be a command for this, which maps each 24b colour to the closest colour in 8b.

If you don''t know what the palette values are (if you just took what loaded in) a common palette to use is
for r=0 to 5, for g=0 to 5, for b=0 to 5
Set colour 1 + r + 6*g + 36*b to r/5 of red, g/5 of green, b/5 of blue.
(The 1 is so 0 can be transparent).

So for each pixel, you decide where on the 0-5 scale it is in r, g & b to decide what colour to convert to.
If you do something like this, make sure you know what your transparent colour is and convert it properly. I think it''s normally magenta (full red & blue) and it converts to colour 0.
I use Allegro for my graphics, but I have a similar start of program conversion, making new bitmaps and destroying the old ones.

For example, here''s my colour conversion function:

// Maps a colour from 24b to 8b

unsigned char c24_8(unsigned char R,unsigned char G,unsigned char B) {
unsigned char t,r,g,b;

r=R/40;
g=G/40;
b=B/40;

if (r==6) r=5;
if (b<6 && g==6) g=5;
t=b*36+g*6+r;
if (b==6) t=t-2;
return t+1;
}

Because I divide by 40, a level of 5 out of 5 for a component would be 200-239 out of 255. This means I''m changing colours in Paint however. You might want to divide by 50, but make sure you pick up the transparent colour first.
In my case, full white in 24b converts to transparent, with the remaining 39 available for if I want to do special colours or translucency in the future.

I''m sure someone else has better ideas than I on this one.

Share this post


Link to post
Share on other sites