Sign in to follow this  
thuong

problem with copy data

Recommended Posts

Hi All, i have problem with copy data i have backbuffer format: D3DFMT_R5G6B5: 16-bit RGB pixel format with 5 bits for red, 6 bits for green, and 5 bits for blue. following is my code: LPDIRECT3DSURFACE9 pRenderTarget = NULL; m_pDevice->GetRenderTarget(0, &pRenderTarget); m_pDevice->GetRenderTargetData(pRenderTarget, pTemp); // Lock surface D3DLOCKED_RECT lockedRect; pTemp->LockRect(&lockedRect, NULL, D3DLOCK_READONLY | D3DLOCK_NOSYSLOCK) D3DSURFACE_DESC textureDesc; pTemp->GetDesc(&textureDesc); // reverse the buffer int iPitch = lockedRect.Pitch; BYTE *pData = (BYTE*)lockedRect.pBits + (iPitch * (textureDesc.Height - 1)); BYTE *pDestData = m_pMyBuffer; (init with : width * height * 4) for (int i = 0; i < textureDesc.Height; i ++) { int iDestIndex = 0; int iSourceIndex = 0; for (int j = 0;j < textureDesc.Width;j++) { int iPixel = pData[iSourceIndex++]; int iHi = pData[iSourceIndex++]; iHi = iHi << 8; iPixel = iPixel | iHi; int iBlue = iPixel & 0x1F; // 5 bit for blue int iGreen = (iPixel >> 5) & 0x3F; // 6 bit for green int iRed = (iPixel >> 11) & 0x1F; / 5 biet for red pDestData [iDestIndex++] = iBlue; pDestData [iDestIndex++] = iGreen; pDestData [iDestIndex++] = iRed; pDestData [iDestIndex++] = 0xFF; } pDestData += iPitch * 3 / 2; } pData -= iPitch; } when i display this buffer(m_pMyBuffer) then incorrect. my code is not work ok, but i can not see anything error, pls anybody help me???

Share this post


Link to post
Share on other sites
Are you using the debug runtimes with the debug output set to maximum? Is there any debug output? Do you check that all of the D3D calls succeed? Did you create the device with the D3DCREATE_LOCKABLE_BACKBUFFER (or whatever it is) flag?
What do you mean it "doesn't look right"? Any chance of a screenshot?
I'm not sure what this is supposed to do, but it doesn't look right:
pDestData += iPitch * 3 / 2;

Share this post


Link to post
Share on other sites
Since you created your destdata with width*height*4 you can use width * 4 safely. You should not use the sources' pitch for your destination data since they are in no way related.

Change the line:

pDestData += iPitch * 3 / 2;

to:

pDestData += width * 4;

or:

pDestData += textureDesc.Width * 4;

depending on how you want the target data arranged.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this