16位CFbsBitmap上的快速Alpha算法

分享]16位CFbsBitmap上的快速Alpha算法

本帖最后由 sigarron 于 2009-6-11 17:03 编辑

void fastAlpha(CFbsBitmap *aSrc, CFbsBitmap *aDest, TPoint &aPoint, TInt alpha)
/**
* 快速alpha算法,仅支持16位色,alpha取值范围1-32,当32时直接发生拷贝操作
*
* 详见http://blog.chinaunix.net/u/26691/showart_1089631.html
*/
        {
        //直接设定颜色,这样做有问题没?
        aSrc->SetDisplayMode(EColor64K);
        aDest->SetDisplayMode(EColor64K);
       
        //先处理alpha处理的区域信息,
        TUint width = aPoint.iX + aSrc->SizeInPixels().iWidth >        aDest->SizeInPixels().iWidth
                                        ?aDest->SizeInPixels().iWidth - aPoint.iX
                                        :aSrc->SizeInPixels().iWidth;
       
        TUint height = aPoint.iY + aSrc->SizeInPixels().iHeight > aDest->SizeInPixels().iHeight
                                        ?aDest->SizeInPixels().iHeight - aPoint.iY
                                        :aSrc->SizeInPixels().iHeight;

        //我想这些结果会总是为非负数
        TUint jumpD = aDest->SizeInPixels().iWidth - width;
        TUint jumpS = aSrc->SizeInPixels().iWidth - width;
        TUint lineLen = aDest->SizeInPixels().iWidth;
       
        aSrc->LockHeap();
        aDest->LockHeap();
       
        TUint16 *src = (TUint16*)aSrc->DataAddress();
        TUint16 *dest = (TUint16*)aDest->DataAddress();
       
        //确定绘制开始的点:TopLeft
        dest = &dest[lineLen * aPoint.iY + aPoint.iX];
       
        if(alpha != 32)
                {
                register TUint32 temp;
                register TUint16 *ptrS;
                register TUint16 *ptrD;
                for(int i = 0 ; i < height ; i++)
                        {
                        for(int j = 0 ; j < width ; j++)
                                {
                                ptrS = src++;
                                ptrD = dest;
                               
                                temp = (((((((*ptrS << 16) | *ptrS) & 0x7e0f81f)
                                                - (((*ptrD << 16) | *ptrD) & 0x7e0f81f)) * alpha) >> 5)
                                                + (((*ptrD << 16) | *ptrD) & 0x7e0f81f)) & 0x7e0f81f;
                                *dest++ = (temp & 0xffff0000)>>16 | (temp & 0xffff);
                                }
                        dest+=jumpD;
                        src+=jumpS;
                        }   
                }
        else//不计算,直接复制图片内容
                {
                for(int i = 0 ; i < height ; i++)
                        {
                        for(int j = 0 ; j < width ; j++)
                                {
                                *dest++ = *src++;
                                }
                        dest+=jumpD;
                        src+=jumpS;
                        }   
                }
        aSrc->UnlockHeap();
        aDest->UnlockHeap();
        }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值