RGB颜色中关于Alpha通道的计算

前景色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++;
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值