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 ?
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