I think I get what you're trying to do. Try adapting this code to your use.
Code:
#include <stdio.h>
struct RGBA
{
unsigned int R : 8;
unsigned int G : 8;
unsigned int B : 8;
unsigned int A : 8;
};
unsigned
to_unsigned( const struct RGBA* color );
int
main( void )
{
struct RGBA color = {0, 0xFF, 0, 0xFF}; // R = 0x00, G = 0xFF, B = 0x00, A = 0xFF
unsigned final = to_unsigned( &color ); // Pack into a single uint.
fprintf( stdout, "%#0X\n", final ); // Output: 0XFF00FF00
return 0;
}
// Pack it ABGR; e.g. A in MSB, R in LSB.
unsigned
to_unsigned( const struct RGBA* color )
{
unsigned packed_rgba = 0;
packed_rgba |= color->A;
packed_rgba <<= 8;
packed_rgba |= color->B;
packed_rgba <<= 8;
packed_rgba |= color->G;
packed_rgba <<= 8;
packed_rgba |= color->R;
return packed_rgba;
}
You can increment and decrement individual RGBA fields as needed. There is likely a better way to implement this, but this is what I came up.
If you have questions, feel free to ask them. If anyone feels like correcting my quick hack, please do. I will be grateful.