Sign in to follow this  
edwinnie

A2R10G10B10 readback woes

Recommended Posts

edwinnie    122
hi! this is another of my readback woes again. I managed to solve the last one on G16R16 by using a WORD directly instead of a D3DXFLOAT16. This time I found that my current code for A2R10G10B10 readback is not correct. Unfortunately, I dun seem to understand how the bitshifting should work... perhaps someone or Jack can enlighten me again... thx! Edwin
//current code (not entirely correct)
if(format == D3DFMT_A2R10G10B10)
{
	for(int y=0; y<desc.Height; y++)
	{
		DWORD* pPixel = (DWORD*)(((BYTE*)theRect.pBits) + (y*theRect.Pitch));
                for(int x=0; x<desc.Width; x++) 
		{
			BYTE alpha = (*pPixel&0xff000000)>>30;
			unsigned short red = (*pPixel&0xff0000)>>20;
			unsigned short green = (*pPixel&0xff00)>>10;
			unsigned short blue = (*pPixel&0xff);
			pPixel++;
                }
	}
}

Share this post


Link to post
Share on other sites
Demirug    884
Your shifting is OK but masks are wrong.

Try this:

BYTE alpha = ((*pPixel)>>30) & 0x3;
unsigned short red = ((*pPixel)>>20) & 0x3FF;
unsigned short green = ((*pPixel)>>10) & 0x3FF;
unsigned short blue = (*pPixel) & 0x3FF;


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