Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Byte Swapping

Status
Not open for further replies.

Gorecki

Programmer
May 14, 1999
40
US
I have a COLORREF DWORD value (0x00bbggrr) that I want to convert to a D3DCOLOR DWORD value (0x00rrggbb). As you can see the 2nd and 4th bytes need to be exchanged.

Any suggestions would be appreciated.

Gorecki
 
It probably isn't the cleanest approach, but I think this will work:

// initialize to some value for the sake of this example
COLORREF cr = RGB( 0xAA, 0xBB, 0xCC );

// Swap blue and red
D3DCOLOR d3d = RGB( GetBValue( cr ), GetGValue( cr ), GetRValue( cr ) );
 
I figured it out a differnet way but yours should work as well.

//Get RGB Values from bits 0xRRGGBB00
wFromL = LOWORD(cc.rgbResult);
wFromH = HIWORD(cc.rgbResult);
bRed = LOBYTE(wFromL);
bGreen = HIBYTE(wFromL);
bBlue = LOBYTE(wFromH);
// Convert to 0x00RRGGBB
d3dcol = D3DCOLOR_XRGB(bRed,bGreen,bBlue);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top