I am trying to convert an UINT32 color format from AaBbGgRr to AaRrGgBb in c++. Aa = Alpha, Bb = Blue, Gg = Green Rr = Red. By converting I mean switching the values of Bb and Rr. Does somebody know how I can achieve that ?
Asked
Active
Viewed 1,580 times
1 Answers
3
You can use mask and bit shifting to achieve this:
uint32_t newValue = oldValue;
newValue = newValue & 0xFF00FF00; // open new space to insert the bits
newValue = ((oldValue & 0xFF)<< 16) | newValue; // change BB
newValue = ((oldValue & 0x00FF0000) >> 16) | newValue; // Change RR

Amadeus
- 10,199
- 3
- 25
- 31