|
|
自己写的一个24色位图的色增强混合函数,大家评评这样做效率怎么样,
不怕排砖的,呵呵。
// Alpha Add混合函数-不考虑关键色
void Bitmap24::AlphaAddBlend(Bitmap24 *SrcBmp,
int sx, int sy, int width, int height,
int dx, int dy)
{
unsigned char *pSrcBits, *pDestBits;
unsigned char *pTemp1, *pTemp2;
int iDestSkip, iSrcSkip;
iDestSkip = m_iWidth * 3;
iSrcSkip = SrcBmp->GetWidth() * 3;
width *= 3; // 转换为byte
int iRemain = width & 0x07; // 0000 0111
width -= iRemain;
pSrcBits = (unsigned char*)SrcBmp->GetBmpDataXY(sx, sy);
pDestBits = (unsigned char*)GetBmpDataXY(dx, dy);
for(int y = 0; y < height; y ++){
// pSrcBits和pDestBits必须是8位对齐的
__asm{// 每次处理两个24bits点 + 后16bits
mov ecx, 0;
mov esi, pSrcBits;
mov edi, pDestBits;
cmp ecx, width;
jnl loop_End;
loop_W:
movq mm0, [esi];// source pixel
movq mm1, [edi];// destination pixel
paddusb mm1, mm0;
movq [edi], mm1;
add esi, 8;
add edi, 8;
add ecx, 8;
cmp ecx, width;
jl loop_W;
loop_End:
mov pTemp1, esi;
mov pTemp2, edi;
emms;
}
// 计算剩下的点
for(int i = 0, clr; i < iRemain; i++){
clr = *pTemp1 + *pTemp2;
if(clr >= 0xff) *pTemp2 = 0xff;
else *pTemp2 = clr;
pTemp2++; pTemp1++;
}
pSrcBits -= iSrcSkip;
pDestBits -= iDestSkip;
}
} |
|