前景色fgcolor=(r1,g1,b1,alpha)
背景色bgcolor=(r2,g2,b2)
那么最后显示的颜色为(r2,g2,b2),r2=(r2*(256-a)+r1*alpha)/256,其它颜色一样计算。
java中绘制带有alpha的png图片的时候 先把rgb颜色和alpha值跟当前背景计算一下,然后再用gc的alpha和当前背景色做计算 得到最终显示的颜色。
static void __test_fb_alpha_mix(const uint32_t* p_bg_color,
const uint32_t* p_fg_color, uint32_t len)
{
uint32_t* p_bg_clr = (uint32_t*)p_bg_color; /* background color */
uint32_t* p_fg_clr = (uint32_t*)p_fg_color; /* foreground color */
for (uint32_t i = 0; i < len; i++) {
uint8_t* p_bg_r = (uint8_t*)p_bg_clr + 0; /* background red color*/
uint8_t* p_bg_g = (uint8_t*)p_bg_clr + 1; /* background green color*/
uint8_t* p_bg_b = (uint8_t*)p_bg_clr + 2; /* background blue color*/
uint8_t* p_fg_r = (uint8_t*)p_fg_clr + 0; /* foreground red color*/
uint8_t* p_fg_g = (uint8_t*)p_fg_clr + 1; /* foreground green color*/
uint8_t* p_fg_b = (uint8_t*)p_fg_clr + 2; /* foreground blue color*/
uint8_t* p_fg_a = (uint8_t*)p_fg_clr + 3; /* alpha */
*p_fg_r = ((*p_bg_r * (256 - *p_fg_a) + (*p_fg_r) * (*p_fg_a)) / 256);
*p_fg_g = ((*p_bg_g * (256 - *p_fg_a) + (*p_fg_g) * (*p_fg_a)) / 256);
*p_fg_b = ((*p_bg_b * (256 - *p_fg_a) + (*p_fg_b) * (*p_fg_a)) / 256);
p_bg_clr++;
p_fg_clr++;
}
}