Direct access to a pointer to bitmap
First post here, hello everyone
I recently started using Allegro 5, i need to access the pixel table of loaded BMP file.I know you could do it with Allegro 4 by line parameter, is there a way to do that in Allegro 5?
Thanks in advance
There is al_get_pixel() to read from graphic memory.
If you need something fast and/or you also want to write, please explain what you need it for.
If you don't use a memory bitmap, your data resides on the GPU side of things. Therefore, you should use bitmap locking, as reading / writing from/to the GPU is slow to do per-pixel. What it does is to cache (parts of) the bitmap in memory (CPU side of things). From there, you can also access the data directly via the ALLEGRO_LOCKED_REGION.
See al_lock_bitmap, al_unlock_bitmap and ALLEGRO_LOCKED_REGION.
What would be the fastest way to get array-level access to memory? I want to basically compare every single pixel on a bitmap structure. I was just trying this last week and noticed everything is in floats... if I could use integer comparisons that'd be probably a thousand times faster. Are the al_unmap_rgb/al_get_pixel functions all doing various checks and color space conversions? All I want is read access to values.
In theory, the fastest way would probably be to do it directly on the GPU in parallel.
In practice when using Allegro, you can request a certain pixel format (typically ALLEGRO_PIXEL_FORMAT_ABGR_8888) when locking and then just access it via the data pointer of the ALLEGRO_LOCKED_REGION al_lock_bitmap returns. Allegro will convert it for you when necessary.
Audric, I am doing a school project where we have to use a mix of C and intel assembler.So I need to pass to the assembler function a pointer to the beggining of a pixel array.I will than use it to do the affine transforms
Allegro 5 will give you access to a memory copy of the video memory. That's what happens when you lock a video bitmap. An ALLEGRO_LOCKED_REGION has a pointer to the data, a format, a pitch, and a pixel size. You use these to read and write the data.
Don't assume pitch is equivalent to pixel size times line width. It may differ, it may be different, or it may be negative.
You probably want to lock the region in a 24 or 32 bit format. Allegro will convert the bitmap to and from the format you lock it in.
In case the docs don't make it clear, "pitch" lets you know how to access lines after the first. Edgar refers to how lines can have padding between them (for memory alignment), or be arranged top to bottom.
In every case, the data of a given pixel will be at memory address: region->data + x * region->pixel_size + region->pitch * y
Thread #616922. Printed from Allegro.cc
So you are writing / have to write a software renderer?