Help with understanding bitmap locking
jmasterx

Essentially I want to lock the bitmap and get the alpha component of each pixel.

I have the following code:

```  //lock the bitmap
ALLEGRO_LOCKED_REGION* region;
region = al_lock_bitmap
(m_bitmap,
ALLEGRO_PIXEL_FORMAT_ABGR_8888,

for(int y = 0; y < m_bitmapDimensions.y; ++y)
{
for(int x = 0; x < m_bitmapDimensions.x; ++x)
{

}
}
```

But after that I'm stuck. I'm not sure how to get the 32 bit integer representing the color components, and then I'm unsure how the logical shifts work to extract the alpha in an endian independent way.

Thanks

Elias
```ALLEGRO_LOCKED_REGION* region;
for(int y = 0; y < al_get_bitmap_height(bitmap); ++y) {
unsigned char *row = region->data;
row += y * region->pitch;
uint32_t *pixel = row;
for(int x = 0; x < al_get_bitmap_width(bitmap); ++x) {
int alpha = *pixel >> 24;
/* do something with alpha */
pixel++;
}
}
al_unlock_bitmap(bitmap);
```

[edit:]
A simpler solution:

```ALLEGRO_LOCKED_REGION* region;
for(int y = 0; y < al_get_bitmap_height(bitmap); ++y) {
unsigned char *pixel = region->data;
pixel += y * region->pitch;
for(int x = 0; x < al_get_bitmap_width(bitmap); ++x) {
pixel += 3;
int alpha = *pixel;
/* do something with alpha */
pixel++;
}
}
al_unlock_bitmap(bitmap);
```

Both solution are endian independent (not that you will still find a lot of big endian hardware).

Matthew Leverton
```uint32_t *p = lock->data;
int a;

for each pixel: a = p[x] >> 24

at end of row: p += lock->pitch;
```

jmasterx

Thank you to both of you