分享]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(); } |