GrabPixmap

BlitzMax Forums/BlitzMax Programming/GrabPixmap

maverick69(Posted 2005) [#1]
Hello!

I have a little program where the user can put various shapes with different colors on the screen.

Now I need to know how may pixels of the whole screen are completely black.

To to this I grab the whole screen into a Pixmap using GrabPixmap(0,0,640,480). Then I read pixel by pixel and if the pixel has the required rgb values I increment a counter variable.

Luckily I only need this when the user puts a new shape on the screen so the speed is not a very important issue.

However, I wondered if anyone of you has an better and much faster idea on how to get the numbers of black pixels on the screen.


Tom(Posted 2005) [#2]
Can the shapes be defined by primitive polygon shapes?
Do they overlap?
Does it need to be 100% pixel perfect?

If yes, No and No... how about totalling up polygon/shape areas? In other words, create some polygon representations of your shapes. I'm guessing this would need some overlapping code...hmm.



Tom


maverick69(Posted 2005) [#3]
Thank you for your suggestion. Currently I only have very simple shapes, so you suggestion should work. But in the future I might to include more complex forms.

I have choosed another solution now:

I grab a little image from the screen each loop, for example 40x40 Pixels and check it for black pixels. This is very fast, in the next loop I will check the next 40x40 rectangle of the screen and so on.

When I reached the end of the screen I add all pixels counted in the previous loops and voilá I have the correct number of black pixels.

Of course this solution only works if you don't need the correct number in each loop, but it my case it's perfect.


Dreamora(Posted 2005) [#4]
You mean you grab a little Pixmap, not image? (GrabImage is grabpixmap + convert. For readout you would have to convert back to pixmap which is done through lockimage. So using GrabPixmap straight aways is much faster :))


maverick69(Posted 2005) [#5]
@Dreamora:

yes, you're right!