DOCS : Graphics : Scanline Clipping:

HOME . DOCS FILES LINKS
Scanline Clipping.

There have been a number of different methods of implementing clipping for various applications. One of the early methods for on screen graphics is Scanline Clipping, that keeps a list of inversion points (in and out of the visible area). This method was used in a number of graphical applications in the 1970's, and continues to be used for some things.

Most implementations apply Scanline Clipping to game Sprite Objects or similar kinds of graphics. This is used for game "Sprites" generally.

Put simply there is a list of inversion points for each scanline of the graphic object to be clipped to the desired shape. There is some means of knowing how many inversion points are on a given scanline, often a byte value at the beginning of the scanline holds this count. Then the graphic object is only drawn between sets of inversion points, with the first being start drawing, the second being stop, the third start again, etc. Usually an even number of inversion points is required, so that the stop point always comes before the next line.

This method has some advantages over other methods, especially in the area of game graphics and similar. This method is a bit faster and a lot smaller than using a bitmask for larger graphics, it is more dynamic than rectangle clipping, etc.

Quick Example

The most common application of scanline clipping is in masking game sprite objects. As such we will use this as our example, we will draw a background then move a simple sprite object around that background for our example. Unlike the rectangle example we will use complete tested code here.

Note that a bit mask would take 1/8th the number of pixels in bytes, in this case that would be 2048 bytes for a bitmask, while the scanline inversion mask for 4 inversion points per line takes only 640 bytes (128 entry count bytes (one per scanline) and 4 inversion points per line). There are cases where scanline clipping can be worse, though in general it saves space relitive to bitmask clipping, and almost always is faster.

With the method used here each inversion point contains the number of pixels from the left edge to the inversion point. This is fairly simple to work with.

Code being tested before posting.
WIP : Work In Progress : WIP

...

This site created on RISC OS using !Zap.
Hosting for this site provided by David F
This page viewable with Any Browser
LAST UPDATED: Nov 14th 2022