al_get_pixel performance
Alianix

I was aware that al_get_pixel would be slow on video bitmaps, but I'm getting approximately on the order of 100 pixels per second? Is this normal? This is under linux with intel chip and the open source driver, this system is very new.

Matthew Leverton

Are you locking the bitmap?

Thomas Fjellstrom

It is incredibly slow on video bitmaps. Allegro has to pretty much download the entire texture to get your pixel. for every pixel. Try wrapping your al_get_pixels in a al_lock_bitmap call. Or you can access the locked pixel data directly if you wish. may be a bit faster than calling al_get_pixel a load of times.

Alianix

Thanks guys, I really haven't looked into optimizing this part of my code but it looks like now is the time. I really need a fast routine in the end, I will try your suggestions first, (and no I was not locking the bitmaps) but I was thinking of keeping a memory bitmap copy of these bitmaps when using al_get_pixel. Would you say this is the best approach?

Trent Gamblin

If you can spare the memory, yes.

Alianix

Locking the bitmap gave a lot better performance about 100x faster, I still think it could be done faster.

Matthew Leverton

Are you still using al_get_pixel()? You can also access the raw data directly. Pay attention to the locking pixel format if you do that.

Luiji99

I'd say first try circumventing al_get_pixel and access the downloaded data directly, and if that's not fast enough utilize the extra memory with a RAM copy. What exactly are you using this for, anyway? If you're testing for pixel existence instead of value, you can store the RAM copy as a literal bit map (one bit per pixel) and use some nice &, << and >> operators to get some nice, memory efficient and speedy checks.

Alianix

I need to map the video bitmap to an actual memory "bitmap" so i need to scan the entire bitmap for pixel values. It is only necessary to do this once and i can save the bitmap to disk also easily. The locking works ok for now i will improve the mapping function later by using allegro memory bitmaps.

Update...

Done some more testing and it looks like using memory bitmaps is a bit faster then video bitmaps but still too slow. I don't see how to portably read pixels directly as I'm not sure how pixels are mapped. Can I trust that the pixel values will stay the same across platforms? Looks like now the only safe resort is to save the maps to a file and read it back, but then I have to worry about compression...Any ideas here?

guilt

Hi,

I had initially written old code for Allegro 4 using getpixel. When going to A5, I saw that the code which used to run in 40ms now took a minute on video bitmaps. All that changed when I implemented my own pixel shader in Allegro 5.1... I guess getting values to-fro video memory is not a good idea for pixel processing.

Luiji99
Thread #610635. Printed from Allegro.cc