[A5] Load indexed bitmap
kenmasters1976

Is it possible to load an indexed/paletted bitmap using Allegro 5 while keeping the index information? I've tried using ALLEGRO_KEEP_INDEX but then how do I access the bitmap data? al_get_pixel() returns an ALLEGRO_COLOR, not an index. I've also tried locking the bitmap to access the data pointer but I can't get the index data either.

Erin Maus

Have you tried locking it with ALLEGRO_PIXEL_FORMAT_SINGLE_CHANNEL_8?

See the bitmap loading code: https://github.com/liballeg/allegro5/blob/999008dee8fe13c4775237c46b809670ef3e0376/addons/image/bmp.c#L1334

It's also in the docs on pixel formats: https://liballeg.org/a5docs/trunk/graphics.html#allegro_pixel_format

kenmasters1976

I have tried that, yes. After doing that, the data pointer of the locked region represents the red component of the image, as stated in the docs, but not the color index of the original bitmap.

[EDIT:] Nevermind, it seems the right way to do it is to load the bitmap with al_load_bitmap_flags() using the ALLEGRO_KEEP_INDEX flag and then locking the bitmap with the ALLEGRO_PIXEL_FORMAT_SINGLE_CHANNEL_8 format.

Thanks.

Edgar Reynaldo

Glad you got it working. The red channel should be the index when done correctly, I believe.

Thread #617561. Printed from Allegro.cc