I have two colors and I use this method to do a simple alpha blending:
int Color::blend(int col1, int col2)
{
float a1 = ((col1 & 0x000000FF) / 255.0);
return ((int)((((col1 & 0xFF000000) >> 24) * a1) + (((col2 & 0xFF000000) >> 24) * (1.0 - a1)))) << 24 |
((int)((((col1 & 0x00FF0000) >> 16) * a1) + (((col2 & 0x00FF0000) >> 16) * (1.0 - a1)))) << 16 |
((int)((((col1 & 0x0000FF00) >> 8 ) * a1) + (((col2 & 0x0000FF00) >> 8 ) * (1.0 - a1)))) << 8 | 255;
}
(The colors are in RGBA8888 format)
This works, but i was wondering: is this the fastest way, or is there a more efficient one?