Manually alpha blending an RGBA pixel with an RGB pixel

前端 未结 3 1443
眼角桃花
眼角桃花 2020-12-24 13:00

I am trying to do an alpha blend operation of an RGBA image (foreground image), on to a RGB image (background image). However, while doing so I think I may be doing the wron

相关标签:
3条回答
  • 2020-12-24 13:21

    alpha_blend_sse:)

    ;example usage
    ;mov eax, 0xabcdef
    ;mov edx, 0xAAAAAADD
    ;call alph_blend_see
    
    
    ; In\   EAX = background color (ZRBG) 32bit (Z mean zero, always is zero)
    ; In\   EDX = foreground color (RBGA) 32bit
    ; Out\  EAX = new color
    alph_blend_sse:
        xor r14, r14
        xor r12, r12
        xor r13, r13
    
        movzx r15, dl               ; av: alpha number (0x00--->0xFF)
        movzx ecx, dl
        not ecx                     ; faster than 255 - dl
        mov r14b, cl                ; rem
    
        shr edx, 8
        and edx, 0x00FFFFFF
        mov r12d, edx
        mov r13d, eax               ; RBGA ---> ZRGB
    
        mov rax, 0x0000FF
        movq xmm3, rax
    
        ; s: eax
        ; d: edx
    
        ;=============================red = ((s >> 16) * rem + (d >> 16) * av) >> 8;
        movq xmm0, r12
        psrld xmm0, 0x10
        movq xmm1, r14
        pmuludq xmm1, xmm0
        movq xmm0, r13
        psrld xmm0, 0x10
        movq xmm2, r15
        pmuludq xmm2, xmm0
        addps xmm2, xmm1
        psrld xmm2, 0x8
        movq rax, xmm2
        mov r9b, al
        shl r9d, 8
    
        ;=============================green = (((s >> 8) & 0x0000ff) * rem + ((d >> 8) & 0x0000ff) * av) >> 8;
        movq xmm0, r12
        psrld xmm0, 0x8
        andps xmm0, xmm3
        movq xmm1, r14
        pmuludq xmm1, xmm0
        movq xmm0, r13
        psrld xmm0, 0x8
        andps xmm0, xmm3
        movq xmm2, r15
        pmuludq xmm2, xmm0
        addps xmm2, xmm1
        psrld xmm2, 0x8
        movq rax, xmm2
        mov r9b, al
        shl r9d, 8
    
        ;=============================blue = ((s & 0x0000ff) * rem + (d & 0x0000ff) * av) >> 8;
        movq xmm0, r12
        andps xmm0, xmm3
        movq xmm1, r14
        andps xmm1, xmm3
        pmuludq xmm1, xmm0
        movq xmm0, r13
        andps xmm0, xmm3
        movq xmm2, r15
        andps xmm2, xmm3
        pmuludq xmm2, xmm0
        addps xmm2, xmm1
        psrld xmm2, 0x8
        movq rax, xmm2
        mov r9b, al
    
        mov eax, r9d
        ret
    
    0 讨论(0)
  • 2020-12-24 13:32

    A typical "Over" blend is done in the following way:

    outputRed = (foregroundRed * foregroundAlpha) + (backgroundRed * (1.0 - foregroundAlpha));
    

    And then repeating for the blue and green channels. Do this for every pixel.

    0 讨论(0)
  • 2020-12-24 13:32

    It seems that you have missed out (1-Alpha) multiplier for background (currentPixelColor)

    0 讨论(0)
提交回复
热议问题