Assembly code snippets
Details
Title | Blend bitmap block |
---|---|
Author | Thomas |
Submitted by: | Thomas |
Date added: | 2002-02-17 21:30:47 |
Date modified: | 2002-02-17 21:30:47 |
Comments
This procedure can blend a given rectangle in a bitmap with a given color. In the rectangle (dwX, dwY, dwWidth, dwHeight) passed the color and the source image are blended 50%/50%. dwColor is a COLORREF value holding the blending color. dwBmpWidth is the width of the source bitmap.
restrictions:
dwWidth has to be a multiple of 4 pixels
dwX should be a multiple of 4 pixels for optimal results (not necessary though)
The procedure uses MMX.
Snippet
BlendFixed proc uses edi esi ebx lpData:DWORD,\
dwX:DWORD,dwY:DWORD,\
dwWidth:DWORD, dwHeight:DWORD,\
dwColor:DWORD, dwBmpWidth:DWORD
mov eax, dwColor
movd MM7, eax
pxor MM6, MM6
punpcklbw MM7, MM6 ; MM1: 0 C 0 C-0 C 0 C
mov esi, lpData
mov eax, dwBmpWidth
shl eax, 2
mov ecx, eax
mul dwY
add esi, eax
mov eax, dwX
shl eax, 2
add esi, eax
mov edi, dwHeight
xor ebx, ebx
ALIGN 16
@nextline:
mov edx, dwWidth
shr edx, 2
xor eax, eax
ALIGN 16
@nextpixel:
movq MM0, [esi+eax*8] ; MM0: X R G B-X R G B
movq MM2, [esi+eax*8+8] ; MM2: X R G B-X R G B
movq MM1, MM0
movq MM3, MM2
punpcklbw MM0, MM6 ; MM0: 0 X 0 R-0 X 0 B
punpckhbw MM1, MM6 ; MM1: 0 X 0 R-0 X 0 B
punpcklbw MM2, MM6 ; MM2: 0 X 0 R-0 X 0 B
punpckhbw MM3, MM6 ; MM3: 0 X 0 R-0 X 0 B
paddw MM0, MM7
paddw MM1, MM7
paddw MM2, MM7
paddw MM3, MM7
psrlw MM0, 1
psrlw MM1, 1
psrlw MM2, 1
psrlw MM3, 1
packuswb MM0, MM1
packuswb MM2, MM3
movq [esi+eax*8], MM0
movq [esi+eax*8+8], MM2
add eax, 2
dec edx
jnz @nextpixel
add esi, ecx
inc ebx
cmp ebx, edi
jb @nextline
emms
ret
BlendFixed endp
dwX:DWORD,dwY:DWORD,\
dwWidth:DWORD, dwHeight:DWORD,\
dwColor:DWORD, dwBmpWidth:DWORD
mov eax, dwColor
movd MM7, eax
pxor MM6, MM6
punpcklbw MM7, MM6 ; MM1: 0 C 0 C-0 C 0 C
mov esi, lpData
mov eax, dwBmpWidth
shl eax, 2
mov ecx, eax
mul dwY
add esi, eax
mov eax, dwX
shl eax, 2
add esi, eax
mov edi, dwHeight
xor ebx, ebx
ALIGN 16
@nextline:
mov edx, dwWidth
shr edx, 2
xor eax, eax
ALIGN 16
@nextpixel:
movq MM0, [esi+eax*8] ; MM0: X R G B-X R G B
movq MM2, [esi+eax*8+8] ; MM2: X R G B-X R G B
movq MM1, MM0
movq MM3, MM2
punpcklbw MM0, MM6 ; MM0: 0 X 0 R-0 X 0 B
punpckhbw MM1, MM6 ; MM1: 0 X 0 R-0 X 0 B
punpcklbw MM2, MM6 ; MM2: 0 X 0 R-0 X 0 B
punpckhbw MM3, MM6 ; MM3: 0 X 0 R-0 X 0 B
paddw MM0, MM7
paddw MM1, MM7
paddw MM2, MM7
paddw MM3, MM7
psrlw MM0, 1
psrlw MM1, 1
psrlw MM2, 1
psrlw MM3, 1
packuswb MM0, MM1
packuswb MM2, MM3
movq [esi+eax*8], MM0
movq [esi+eax*8+8], MM2
add eax, 2
dec edx
jnz @nextpixel
add esi, ecx
inc ebx
cmp ebx, edi
jb @nextline
emms
ret
BlendFixed endp