Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » How to get a pointer to every pixel on bitmap?

This thread is locked; no one can reply to it. rss feed Print
How to get a pointer to every pixel on bitmap?
fuspepro
Member #20,275
June 2021

I solved my problem. The pitch was actually negative, I didn't noticed that at first.
Hi, I'm doing uni project using allegro library. I'm using c++.
I load an image onto the screen, and I would like to modify each pixel individually. I lock the bitmap region. After that I call the method:
locked_reg = al_lock_bitmap(bitmapPointer, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_READWRITE);
Then I get a pointer to the pixel data like so:
void* data1 = (locked_reg->data);
But according to the documentation, that gives me only array of pixels in the first row! https://www.allegro.cc/manual/5/ALLEGRO_LOCKED_REGION.
And this is true, when I modify each pixel I get access only to the first row.
Is there a way to get an array with all the pixels on the bitmap in a way that I can modify it?

According to this thread: https://www.allegro.cc/forums/thread/616922 (Edgar Reynaldo - Posted on 05/31/2017 4:44 PM):
The coordinate of the pixel should be: locked_reg->data + x * locked_reg->pixel_size + region->pitch * y.

Okay nevermind, the pitch was negative. It works now 8-)

Thanks for help

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Go to: