PocketMatrix forums

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

Display Rotation and Surface Orientation

Say I have surface in memory, but there's no corresponding file or resource.

If the display rotates, that surface now has the "wrong" orientation.

Can this surface still be used (e.g. blitted)? I assume it cannot.

What is the best way to rotate it so it has the proper orientation? I tried a blit, and CreateSurface(CGapiSurface*), but both return GDERR_INCOMPATIBLEPRIMARY.

Must I use get/set pixel to do the rotation myself? Or access the raw buffer? Isn't there a better way?
Hey this is strange...

I have a ROTATE90CCW surface.

I tried some manual pixel pushing in the buffer, but when I put RGB(255,0,255) instead of magenta I get yellow.

I guess I'm doing something incorrectly?
Strange. I'll try the RGB(255,0,255) and see if its the same on my end.

There's some "effects" possible with Alpha/Blt/BltFast in the GapiDraw docs.
Such as:
GDALPHABLT_MIRRORLEFTRIGHT
Mirrors the source image left-to-right in the destination rectangle.
GDALPHABLT_MIRRORUPDOWN
Mirrors the source image vertically in the destination rectangle.

I'm too tired right now to think it through, but could you use a combination of the mirror effects to get the effect of rotation? Surface rotation is a much needed feature if its not in GapiDraw yet, for reasons such as yours.

-Fraggler
What is the best way to rotate it so it has the proper orientation? I tried a blit, and CreateSurface(CGapiSurface*), but both return GDERR_INCOMPATIBLEPRIMARY.


Actually, it's not possible to rotate surfaces if the display rotation changes. The reasons are that pitch values etc changes, and if the surface is stored in video memory the memory required for the surface can be different if it is rotated or not (since row-pitch can be more than simply DWORD aligned width).

There are also numerous checks in the surface that effectively prevents all future blitting from the surface if the rotation of the surface differs from the display.

If the display is rotated, simply call CreateSurface again to re-create the surface.
I got it working by manually putting pixels in the raw buffer using the proper pitch.

But I found it strange that while testing, putting magenta would display as yellow. Oh well.
mlepage: If you use Palm, did you byteswap the words? The Palm display (and GapiDraw surfaces) are ARM native, which means that data values written directly to the surface needs to be byteswap (since the Motorola emulator environment uses Big Endian). This can cause incorrect colors.
Johan wrote:
If the display is rotated, simply call CreateSurface again to re-create the surface.


OK, but my point is, there is no PNG etc. to re-create the surface from. The data exists only in the existing surface, which you now say cannot be used. An example of this situation is a drawing program where you put pixels to a surface based on stylus input.

So we're back to my original question: to create a surface with the correct orientation, containing the data from the older surface, is putting pixels individually using SetPixel or the raw buffer the only way?
Johan wrote:mlepage: If you use Palm, did you byteswap the words? The Palm display (and GapiDraw surfaces) are ARM native, which means that data values written directly to the surface needs to be byteswap (since the Motorola emulator environment uses Big Endian). This can cause incorrect colors.


OK that sounds like the cause.
to create a surface with the correct orientation, containing the data from the older surface, is putting pixels individually using SetPixel or the raw buffer the only way?


Yes. Buy you could use a simple DWORD copy routine with raw buffer access to achieve this... No need to read color values.
Yup I'm just copying pixels from one buffer to the other. I was manually setting RGB values just for testing, to ensure I had the proper buffer format.