/* alpha blend routine */
unsigned int AlphaBlend(const unsigned int bg, const unsigned int src)
{
unsigned int a = src >> 24; /* alpha */
/* If source pixel is transparent, just return the background */
if (0 == a)
return bg;
/* alpha blending the source and background colors */
unsigned int rb = (((src & 0x00ff00ff) * a) +
((bg & 0x00ff00ff) * (0xff - a))) & 0xff00ff00;
unsigned int g = (((src & 0x0000ff00) * a) +
((bg & 0x0000ff00) * (0xff - a))) & 0x00ff0000;
return (src & 0xff000000) | ((rb | g) >> 8);
}