PocketMatrix forums

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

Copy CGapiRGBASurface?

Hello,

How do I make a copy of a CGapiRGBASurface? With a CGapiSurface I just created a new surface and then used BltFast.

Thanks,

Lars
Anyone?

/ Lars
surely an AlphaBltFast would do the job?
How do I make a copy of a CGapiRGBASurface? With a CGapiSurface I just created a new surface and then used BltFast.


Good question. Actually it's not that simple.. I'll add it to my "make easy" list. To make an exact copy you would have to call GetBuffer() on both surfaces, and then copy each RGBA value individually, like:

DWORD* pSrc = srcBuffer;
DWORD* pDest = destBuffer;
while (each line)
{
while (each column)
{
*pSrc = *pDest;
pSrc += srcXPitch;
pSrc += dstXPitch;
}
pSrc += srcYPitch;
pSrc += dstYPitch;
}
Don't forget to adjust the pitch value (srcPitch = (xPitch >> 4)).... I'll see if I can make all this easier in the next release...

//Johan
Ok, I'll try that, thanks!

/ Lars
I thought I post my result here if anyone else is interested:

Code:

CGapiRGBASurface m_pic1, m_pic2;

// Read the surface to copy
m_pic1.CreateSurface(0, TEXT("picture.png"));

// Create an empty surface with the same width and height
m_pic2.CreateSurface(GDRGBASURFACE_CLEAR, m_pic1.GetWidth(), m_pic1.GetHeight());

GDBUFFERDESC BufDesc1, BufDesc2;
memset(&BufDesc1;, 0, sizeof(BufDesc1));
memset(&BufDesc2;, 0, sizeof(BufDesc2));

// Get the buffers
m_pic1.GetBuffer(&BufDesc1;);
m_pic2.GetBuffer(&BufDesc2;);
DWORD *pSrc = (DWORD *)BufDesc1.pBuffer;
DWORD *pDst = (DWORD *)BufDesc2.pBuffer;

DWORD xPitch = (BufDesc1.xPitch >> 2);

// Make the copy
for (DWORD row = 0; row < BufDesc1.dwHeight; row++)
{
for (DWORD col = 0; col < BufDesc1.dwWidth; col++)
{
*pDst = *pSrc;
pSrc += xPitch;
pDst += xPitch;
}
}

// Release the buffers
m_pic1.ReleaseBuffer();
m_pic2.ReleaseBuffer();
beautiful piece of code

exactly what I was just looking for ;)

please ignore my stupid answer earlier, didn't realise the problem until I needed to do it for myself

many thanks for posting :D