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
Thanks for help
Glad you solved it. The manual can be very helpful, make sure to make good use of it.
https://liballeg.org/a5docs/trunk/graphics.html#al_lock_bitmap
https://liballeg.org/a5docs/trunk/graphics.html#allegro_locked_region