- Online Community Forums » Programming Questions » I'm haveing trouble with 256-color bitmaps.

Credits go to Tobias Dammers for helping out!
This thread is locked; no one can reply to it. rss feed Print
I'm haveing trouble with 256-color bitmaps.
Member #6,642
December 2005

First the game is set up to be at any color depth.
Second I got all my data in a datafile.

Now I want to be able to use the palette in the datafile with my 256-color bitmaps (also in the datafile) by bliting it on another bitmap whose color depth may not be 256-colors.

How can I do all of this?

Tobias Dammers
Member #2,604
August 2002

Generally, allegro was not intended to mix bitmaps of different color depths at all. That said:
To use a palette from a datafile, you have to cast the dat member of the corresponding datafile record to a PALETTE (or an RGB*). You can pass that to set_palette() like so:


load_datafile(dat, "data.dat");

Assuming that PALETTE_PCX is defined in the (properly included) datafile header and that the corresponding datafile entry is in fact a palette.

If you are in a >8bpp mode, then you need to set the proper color conversion. The easiest (and least error prone) procedure is this:
1) set_color_conversion(COLORCONV_TOTAL | COLORCONV_KEEP_TRANS);
2) Use load_datafile_object() to temporarily load the palette from the datafile
3) set the palette
4) load_datafile() the entire datafile; color conversion takes care of the palette and everything else for you. The resulting bitmaps will be in the current color depth

Alternatively, you can:
1) disable color conversion
2) load the datafile in one go
3) find the palette in the datafile and set it
4) enable color conversion
Note that only a few functions support color conversions (blit() and to some extent draw_sprite() do), while others will just assume equal color depths (stretch_blit() etc.) for performance reasons.

Me make music: Triofobie
"We need Tobias and his awesome trombone, too." - Johan Halmén

Member #6,642
December 2005

Thank you Tobias Dammers. This was a problem that stumped me in almost every allegro game I made. since I could figure it out I just make the whole game one or the other.
but this time I must do a 8-bit to 24-bit conversion. The first way that you metion works very well. The second way is usefull too. In-case I want to change palette rapidly (e.g. to make a NES like watterfall).
Thank you for all you help.

Go to: