//< 24位光栅转换成32位,使用MMX指令处理
//< 24位光栅从低地址看起的像素格式为BBGGRR
//< 转换效果为 BBGGRR BBGGRR... -> BBGGRRAA BBGGRRAA...
/************************************************************************/
void RGB24ToRaster32( void *pDst, unsigned int dst_pitch, unsigned int width, unsigned int height, void *pSrc, unsigned int src_pitch)
{
char * pSrcLine = (char *)pSrc;
char * pDstLine = (char *)pDst;
int mask[] = { 0xff000000, 0xffffffff, 0xffffffff, 0xff000000 }; //two quadwords
_asm movq mm7, mask
_asm movq mm6, mask+8
for ( int i = height; i-- > 0; )
{
_asm
{
mov esi, pSrcLine
mov edi, pDstLine
mov ecx, width
shr ecx, 2
jz short i_lpRest
i_lpMain:
movq mm0, [esi]
movq mm2, [esi+4]
add esi, 16
movq mm1, mm0
movq mm3, mm2
psllq mm1, 8
psllq mm3, 8
por mm0, mm7
por mm2, mm7
por mm1, mm6
por mm3, mm6
pand mm0, mm1
pand mm2, mm3
movq [edi], mm0
movq [edi+8], mm2
add edi, 16
dec ecx
jnz short i_lpMain
//
i_lpRest:
mov ecx, width
and ecx, 3
jz short i_lpExit
i_lpEnd:
movd mm0, [esi]
add esi, 3
por mm0, mm7
movd [edi], mm0
add edi, 4
dec ecx
jnz short i_lpEnd
i_lpExit:
}
pSrcLine += src_pitch;
pDstLine += dst_pitch;
}
_asm emms
}
游戏开发中常用光栅处理函数(一)
最新推荐文章于 2022-12-15 01:04:25 发布