Pixmaps - never used one before

BlitzMax Forums/BlitzMax Beginners Area/Pixmaps - never used one before

Dax Trajero(Posted 2007) [#1]
BlitzMax doesn't do a good job of differentiating between using images and pixmaps.

In this scenario, I need to read the color of pixel x,y on my 800x600x32 .png background image

So, looking through all the BMax commands, I assume I use LoadPixMap instead of LoadImage then use ReadPixel to find the colour ?

Is this correct ?


Gabriel(Posted 2007) [#2]
If you already have the image loaded, you can convert it to a pixmap with LockImage, I think. I don't use Max2D, but that's what the docs suggest. If you you don't have the image loaded already then yes, LoadPixmap.


JazzieB(Posted 2007) [#3]
Gabriel is correct. Use LockImage to allow pixel operations on an image. When you're done, use UnlockImage. I think the two commands basically move the image from VRAM into RAM and vice-versa.

If you need to do this sort of thing in real time you may need to think of an alternative way of achieving whatever it is you need to achieve, as this can be relatively slow - especially on large images.


grable(Posted 2007) [#4]
Actualy UnlockImage does nothing. The transfer is done on next DrawImage..

But id still use UnlockImage, cuz you never know when it WILL do something ;)


Dax Trajero(Posted 2007) [#5]
Question: Assuming I use LoadPixMap do I still have to lock / unlock in order to ReadPixel ?

JazzieB, can you suggest alternatives, if this really is as slow as you say ? All I need is to determine the colour of a pixel on an offscreen image at position x,y ? I need to do this 4 times per frame.


Dreamora(Posted 2007) [#6]
Alternatives: No, readpixel is only possible on pixmaps.
Possibility which I don't see as alternative but the RAM intensive way: Make own sprite objects (class) which holds the image and pixmap reference. That way you can read from the pixmap but draw the image. Whenever you update the pixmap, just use obj.thatImage = loadimage(obj.thatPixmap) (or similar) to update the image data.


Grey Alien(Posted 2007) [#7]
In this scenario, I need to read the color of pixel x,y on my 800x600x32 .png background image
If this was because they clicked rectangle which is a certain colour, your Rectangle type could contain a colour field. then when they click the mouse, you work out which rectangle is clicked via the coords (and see which is uppermost if they overlap) and then when you know which one, simply read the colour field. No Pixmaps involved :-)


JazzieB(Posted 2007) [#8]
Question: Assuming I use LoadPixMap do I still have to lock / unlock in order to ReadPixel ?

JazzieB, can you suggest alternatives, if this really is as slow as you say ? All I need is to determine the colour of a pixel on an offscreen image at position x,y ? I need to do this 4 times per frame.


If the image is never drawn (as your comment would seem to suggest) then you can load the image as a Pixmap, and therefore in RAM, and do your check as you are currently doing so. 4 times per frame is not much at all, especially if this is all you're doing and the image is stopping in normal RAM. It would be a problem if it were an image that is being drawn, as then the image would need to be continually swapped between normal and video RAM.

I don't think that you would need to use LockImage on a Pixmap, although I haven't checked this.

As for alternative ways of doing things without using ReadPixel, that would depend on why you are doing these checks in the first place, so making suggestions right now would be difficult - although a couple have been mentioned above.


FlameDuck(Posted 2007) [#9]
I don't think that you would need to use LockImage on a Pixmap, although I haven't checked this.
You can't LockImage a PixMap. LockImage takes a TImage as a parameter, not pixmap. Besides which getting a TPixmaps related TPixmap, seems somewhat redundant.


Dax Trajero(Posted 2007) [#10]
Thanks all.

JazzieB appears to have answered my question.

And yes, I can confirm the pixmap never gets drawn to the screen or modified in any way. Its a monochrome image used for sprite > background collision detection.


MadMax(Posted 2007) [#11]
@Dax >> You could always use an array to do that


Dax Trajero(Posted 2007) [#12]
MadMax, the background image is very irregularly shaped eg. can't be saved as a series of collision rectangles.

So does that rule out what you mean ?


Gabriel(Posted 2007) [#13]
I haven't looked into them, but I would assume that pixmaps are basically just a block of memory and a pointer to it. So they're more or less arrays anyway.


Dax Trajero(Posted 2007) [#14]
Is it possible to do the following:

Put my 800x600 png into a collision layer using the collideImage command

check my sprite for collision with background image by doing a

if collideImage...?

If this is possible, I presume I can put my 800x600 collision image into the collision layer once before my main loop (eg. I don't have to keep putting it there every frame as the background never changes) ?


MadMax(Posted 2007) [#15]
Well you just need a 2-dimensional array, in your case
collision_map[800,600]

Then if you want you can create a small routine to read the png into the array.

In my "mutant turmites" post I use an array to check the background, it's easy to use and I'm quite sure it's faster and easier than this pixmax business.


Dax Trajero(Posted 2007) [#16]
MadMax,

Ah, sounds good - my game uses very little RAM, and I suppose a nice simple array would be very processor friendly ;-)

Gawd, I've juse found another collision function called ImagesCollide now!! Don't get me wrong I love BMax, but the docs are a PAIN!!


FlameDuck(Posted 2007) [#17]
Put my 800x600 png into a collision layer using the collideImage command

check my sprite for collision with background image by doing a

if collideImage...?
Not quite. But if you seperate your bsackground image into the seperate collision zones, and draw those instead that should work.


Dax Trajero(Posted 2007) [#18]
Thanks all.

Flameduck - now I've found the command, it would seem imagescollide could also be of use.

But, because the BMax docs are so vague, I'm going to have to mock up examples using each technique and see whats best. Any pointers ? (pardon the pun)

Is it possible to put a non-monochrome image into an array, where each pixel is an RGBA value eg. FF001100 from the 800x600 .png ?


Dreamora(Posted 2007) [#19]
Assaris tutorials are great to understande the collision system and its unique capabilities.