| ||
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