Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » al_get_pixel performance

This thread is locked; no one can reply to it. rss feed Print
al_get_pixel performance
Alianix
Member #10,518
December 2008
avatar

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
Supreme Loser
January 1999
avatar

Are you locking the bitmap?

Thomas Fjellstrom
Member #476
June 2000
avatar

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.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Alianix
Member #10,518
December 2008
avatar

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
Member #261
April 2000
avatar

If you can spare the memory, yes.

Alianix
Member #10,518
December 2008
avatar

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

Matthew Leverton
Supreme Loser
January 1999
avatar

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
Member #12,254
September 2010

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.

Programming should be fun. That's why I hate Java.
http://www.entertainingsoftware.com/

Alianix
Member #10,518
December 2008
avatar

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
Member #2,553
July 2002
avatar

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
Member #12,254
September 2010

Programming should be fun. That's why I hate Java.
http://www.entertainingsoftware.com/

Go to: