PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Surface memory access

Hi,

How do I gain access to the Surface memory? I'm trying to read/write on a pixel basis.

Thanks,

Pam
Conan · 24 Jun 2002, 16:26 UTC — GetPixels, for internal use only ?
If I'm correct it looks like the GetPixels function is only for internal use by PocketFrog ?

It's a method of GraphicBuffer found in graphicbuffer.h

You could probably figure out how to get at them by looking at this source but my understanding is that internal stuff is not useable from the user's game.

You could request a new function? I had not gone looking for this yet. Seems to me that many user-written special effects will rely on getting at the Pixels

ps: what are you trying to do ? just in case there's an alternative approach
Basically you access the pixels by locking the surface (it works pretty much the same way as DirectX):

Code:

...
Surface::LockInfo lockinfo;
pSurface->Lock( lockinfo );
... do some pixel manipulations
pSurface->Unlock();


After the call to Lock(), The lockinfo variable will hold a pointer to the pixels and the pitch value.

This is not highly efficient as the locked region will get Swizzled/Unswizzled each time you Lock/Unlock. Both Lock/Unlock takes an optional parameter "bDiscard" used to save this swizzling operation (but will discard the buffer's content).

Internal::GraphicBuffer is not currently accessible (it's in namespace Internal). It might be needed to allow for special effects such as plasma demos... But I don't feel this is the right interface to provide to users.
Ah, thanks, that makes sense. I'll give it a shot. I'm trying a fire effect. I had done one using EasyCE, but I was using the whole display as my surface for the effect.

I had thought to use a smaller surface for manipulating the effect, then just Blit that onto the display.

Pam
BurningSheep · 24 Jun 2002, 21:12 UTC
the lock/unlock thing is what I used for my plasma effect (download plasma), didn't get what the discard parameter was about though (didn't really think about it either), so I just omitted it altogether :)
I selected the default value for "bDiscard" as being false. This way, if you don't know what it's for, Lock/Unlock will work as you expect it.

Basically, if bDiscard is set to true on Lock(), the content of the surface can be discarded (i.e. erased). This is really useful to save time when I load images.

The bDiscard on Unlock() is really similar. If you only lock to surface to read the pixels (read only access), there is no need to re-swizzle the temporary buffer. So you can use Unlock( true ) to save time.

Of course, when writting a plasma effect, you should use the default values (bDiscard = false).
Conan · 25 Jun 2002, 06:52 UTC — Nice demo, shame about the sheep
A very nice demo. Did you manipulate a surface or the back buffer directly?
Really nice plasma effect!

There is some artifacts on my Casio E-125 that leads me to believe that you may not be handling the pitch properly when initializing the plasma values. (I see some diagonal lines accross the screeen).

After you Lock() the buffer, are you using the returned pitch to properly access lines?

Any source code available? I'm curious how a plasma effect is implemented...
BurningSheep · 25 Jun 2002, 09:37 UTC
I'll look up the source code when I'm at home, I've only ran it on ipaqs and it worked fine on them. I suspect there is a memory leak in there as well, but I haven't found the time to look into it and recompile it. I'll post the code later today
Conan · 25 Jun 2002, 10:23 UTC — Pitch not understood yet
I need to read up about this pitch issue as I don;t follow what it's about. I have PocketGL source plus the EasyCE toolkit & GapiDraw in addition to PocketFrog so between them I'm sure to find out enough. I want to do some special effect & the plasma type effects will look nice in a space game
BurningSheep · 25 Jun 2002, 10:48 UTC
What I figured is that the pitch is the width of the surface in bytes. Since Surface::LockInfo.pixels is of type (Pixel*) I basicly use the following formula to calculate the offset for pixel (x, y)

Code:

long offset = y * (pitch >> 1) + x;
BurningSheep · 25 Jun 2002, 11:26 UTC
Download source code here:
http://vulcanus.its.tudelft.nl/robert/P ... smaSRC.zip

Basic recipy I used for my plasma:

First of all the sine function is your friend :)

- create a palette (just an array that holds a number of colors). I use sine functions to get a nice looking palette, you need the first and last color to be the same to make the plasma look good.

- make plasma LUTs, what I did is create 2 arrays twice the size of the display. Then use sine functions with the x and y coordinates to make some nice images.
In my case one is based on the distance to centre of the image, the other is just me being creative ;)
The trick here to make it faster is use values between 0 and 127 so if you add 2 values they won't exceed 256 (if your palette consist of 256 colors ofcourse), you don't have to check that later this way. I used values between 0 and 63 so I could also mix in an image as well.

- when that's done you are ready to create some plasma. based on the time you use... sine functions to calculate an initial x and y position for each of the buffers (in my case 2 plasma buffers and an image)
Then simply add the values from the buffers, use that value with the palette to get the color to blit, increment all the offsets and repeat all of this until the screen is full.

Btw, I said sine is your friend, but it definitely isn't your ppc's friend. It's horribly slow, that's why I was forced to use sine/cosine lookup tables as well.
You can also use much smaller buffers when you are going to use this effect in a game since your not going to use it fullscreen precalcing won't take as long and after pre-calcing it hardly takes any cpu power to draw it.

Ok, I'm not very good at explaining stuff, so just check the code and you'll see it's all pretty simple.
Thanks for the source code Sheep!

Two comments:

1) It seems you are not handling the pitch (hence the problems on the Casio E-125)
2) There is no need for this "filepath" Easy-CE rip... PocketFrog already has a function to do just that: PocketPC::GetFullPathName(). (Yeah yeah, I know, docs are needed).

I would like to request your permission to adapt your source code so that it becomes another sample in the next release of PocketFrog. Let me know!
BurningSheep · 26 Jun 2002, 09:01 UTC
Kzinti wrote:
I would like to request your permission to adapt your source code so that it becomes another sample in the next release of PocketFrog. Let me know!


sure, feel free to use it in any way you want