[AD] load_bitmap() and 24->8 conversion

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Hi,

This problem has existed for a long time, and I guess no one reported it because work-arounds are possible and, at least in my case, it never really affected me. However, maybe it should be fixed...

Consider the following code:

BITMAP *bmp;
PALETTE pal;
allegro_init();
set_color_depth(8);
set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0);
create_my_uber1337_palette(pal);
bmp = load_bitmap("my_uber1337_true_colour_bitmap.bmp", pal);

The user obviously wants the bitmap converted to 8-bit using the palette passed. However, this is not what load_bitmap() does. The palette is initialised with a 332 palette, and then colour 0 is set to Magic Pink. IMHO this is a completely useless palette...

My first thought was to have load_bitmap() read in a palette for you if the bitmap on disk was paletted, or return a palette to you if the bitmap on disk was true colour. However, this is a little ugly because the meaning of the parameter changes depending on the file.

An alternative would be to provide some complementary functions which use your palette:

BITMAP *load_bitmap_conv(AL_CONST char *filename, AL_CONST PALETTE pal);
BITMAP *load_bmp_conv(AL_CONST char *filename, AL_CONST PALETTE pal);
etc.

These functions load the bitmap and convert it to 8-bit. If it's already 8-bit, these functions 'transcolorise' it (they convert the bitmap so it uses the palette passed, bypassing the conversion if the palettes are identical).

Note that these functions would always convert to 8-bit. People use 8-bit sprites in true-colour modes, don't they? :) That also makes palette remapping possible, allowing for fast tinting and so on.

Opinions?

I should add that I don't really have the resources to work on this myself.

- entheh



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/