Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » [A5] Load indexed bitmap

This thread is locked; no one can reply to it. rss feed Print
[A5] Load indexed bitmap
kenmasters1976
Member #8,794
July 2007

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
Member #7,537
July 2006
avatar

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

---
ItsyRealm, a quirky 2D/3D RPG where you fight, skill, and explore in a medieval world with horrors unimaginable.
they / she

kenmasters1976
Member #8,794
July 2007

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
Major Reynaldo
May 2007
avatar

Go to: