This algorithm proved to be effective when two images are combined. The picture beneath (background) is seen if alpha component of fronth picture is less then 0xFF. If alpha of front picture (src in snippet) is zero then all we see is background picture. The format of colour is ARGB which means 32 bit variables are used to represent the color of pixels (off course alpha, red, green, blue are one bytes).
Alpha blend algorithm
/* 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);
}
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.