Assembly code snippets
Details
Title | Pre-multply bitmap with alpha channel |
---|---|
Author | bitRAKE |
Submitted by: | Qweerdy |
Date added: | 2003-01-03 13:54:06 |
Date modified: | 2003-01-03 13:54:06 |
Comments
This snippet is used to "premultiply" a bitmap with its alpha channel. This is required by the Windows 2000 / XP API's AlphaBlend and UpdateLayeredWindow, as well as the CompositeBlend snippet that's also in this library. You only have to premultiply a bitmap once, and if you blend/copy two bitmaps that are already premultiplied onto eachother, you don't have to premultiply again.
Original proc by Qweerdy, inner loop rewritten by bitRAKE.
Snippet
PreMul proc uses esi hBmp:dword
LOCAL bminfo:BITMAP
; R = R * A / 256
; G = G * A / 256
; B = B * A / 256
invoke GetObject,hBmp,sizeof bminfo,addr bminfo
cmp bminfo.bmBitsPixel,32
jne Abort
mov esi,bminfo.bmBits
yloop:
mov ecx,bminfo.bmWidth
xloop:
; This code by bitRAKE
mov eax,[esi]
mov edx,eax
rol eax,16
shr edx,24 ; A
mul dl ; B * A
rol eax,8
mul dl ; G * A
rol eax,8
mul dl ; R * A
mov al,dl
ror eax,8
mov [esi],eax
add esi,4
dec ecx
jnz xloop
dec bminfo.bmHeight
jnz yloop
Abort:
ret
PreMul endp
LOCAL bminfo:BITMAP
; R = R * A / 256
; G = G * A / 256
; B = B * A / 256
invoke GetObject,hBmp,sizeof bminfo,addr bminfo
cmp bminfo.bmBitsPixel,32
jne Abort
mov esi,bminfo.bmBits
yloop:
mov ecx,bminfo.bmWidth
xloop:
; This code by bitRAKE
mov eax,[esi]
mov edx,eax
rol eax,16
shr edx,24 ; A
mul dl ; B * A
rol eax,8
mul dl ; G * A
rol eax,8
mul dl ; R * A
mov al,dl
ror eax,8
mov [esi],eax
add esi,4
dec ecx
jnz xloop
dec bminfo.bmHeight
jnz yloop
Abort:
ret
PreMul endp