Graphics 101 -- Clipping Blit

Graphics 101 Clipping Blit

image from book
Figure 19-7: 2D bitmap on left with 2-bit clipping plane on right

The same trick of using inverse logic can be used for expanding image clipping planes.

In the image on the left, no matter how it's encoded (8/16/24/32 bits), only a single bit in the clipping plane image on the right would be needed to represent a single pixel. If black=0 and white=1, then a sprite object could appear to pass in front of the fence as well as behind it but in front of the distant background. This could be done in a variety of ways. One would be to use masks where both the sprite pixel and the background pixel are masked so only one has a non-zero value. The resulting color is written to the destination buffer.

 ; esi = sprite image pointer ; ebx = clipping plane ; ebp = background image pointer ; edi = destination image buffer pointer             mov    edx,[ebx]         ; Get clipping plane         mov    ch,32             ; 32 pixels at a time     $L1:    mov    al,[esi]          ; Source sprite image         inc    esi               ; Next sprite pixel pointer         mov    cl,[ebp]          ; Source background image         inc    ebp               ; Next src background pixel             test   al,tcolor         ; transparent color         je     $T1               ; Jump if transparent pixel             shr    edx,1             ; Get a masking bit into carry         setnc  ah                ; 1=background 0=foreground         dec    ah                ; 00=background ff=foreground         and    cl,ah             ; ff=keep bgnd 00=kill it         not    ah                ; Flip masking bits         and    al,ah             ; ff=keep sprite 00=kill it         or     cl,al             ; (XOR type) Blend pixels $T1:    mov    [edi],cl          ; Save new pixel to destination         inc    edi               ; Next dst working pixel         dec    ch                ; 1 less pixel in run         jnz    $L1               ; Loop 

32.64-Bit 80X86 Assembly Language Architecture
32/64-Bit 80x86 Assembly Language Architecture
ISBN: 1598220020
EAN: 2147483647
Year: 2003
Pages: 191

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: