PocketMatrix forums

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

RGBA surfaces and GetBuffer

Hi,

I've come across a strange problem, and I'm not sure where to start looking for the solution.

I'm loading a PNG image with transparency into an CGapiRGBASurface, where the pixel at 0,0 of the image is pure red. The format of the surface is 565A.

After I get to that pixel location using GetBuffer() & pBuffer, the WORD content of pixel 0,0 is 0x00ff, and that when turned to a colorref using gd565::NativeToColorref() gives 0x00f81c00... Not red at all...

I'm using the pitches and pBuffer correctly, because I can find all RGB(0,0,0) in the image correctly.

Is there something special I should know about RGBA surface memory?

Thanks!

--Eric
Yep, they use DWORD pixels (RGBA).. Basically its 8888 format (8 bits red, 8 bits green, 8 bits blue, 8 bits alpha).
Thanks!

So I just need to do this to retrieve the color:

DWORD *Buffer = (DWORD *) BufferDesc.pBuffer;

then add the proper pitches to Buffer and retrieve the color like this:

COLORREF Color = Buffer[whatever] & 0x00ffffff;

--Eric
Update: I must use xPitch >> 2 to get the number of DWORD to add for each x increment, right?

--Eric
So I just need to do this to retrieve the color:
DWORD *Buffer = (DWORD *) BufferDesc.pBuffer;
then add the proper pitches to Buffer and retrieve the color like this:
COLORREF Color = Buffer[whatever] & 0x00ffffff;


Not quite. The pixel format is explained in the header file and the online documents. You would first have to check the pixel format of the buffer. In the case of RGBA surfaces this can be:
GDPIXELFORMAT_555A = 0x0010, // 32-bit RGBA (xrrrrrgg gggbbbbb xxxxxxxx aaaaaaaa)
or
GDPIXELFORMAT_565A = 0x0020, // 32-bit RGBA (rrrrrggg gggbbbbb xxxxxxxx aaaaaaaa)

So.. You would have to do some shifting to get the value into a colorref structure...

Update: I must use xPitch >> 2 to get the number of DWORD to add for each x increment, right?


Um.. (xPitch >> 4) is what you want to use.. The xPitch is the value in bytes to add to each pixel..