Assuming the the linesegment are clipped and the n points are stored
in an array p, the algorithm follows.
1) find the point with maximal y coordinate(max_point), and the minimal
y coordinate( min_y)
2) find how to get form max_point to the next point on the left
and on the right side of the polygon
i.e.
tmp=max_point-1;
if (tmp<0) tmp=n-1;
if (p[tmp].x < p[(max_point+1) % n].x
{
left_incr=-1;
right_incr=1;
}
else
{
left_incr=1;
right_incr=-1;
}
3) do a modified bresenham line-traversal on from max_y to min_y
through the line-segments on the left side of the polygon, which
stores the offsets in an offset buffer. (i.e. offset for intersection
with scan-line y is stored in ofs_buf[y].left)
4) repeat this for the right side of the polygon, and store offsets
in ofs_buf[y].right
5) do a loop from max_y to min_y
and fill the offsets from ofs_buf[i].left to ofs_buf[i].right with
assembly stosd (for 386/486) and the rest with stosb
i have implemeted a slower variety of this algorithm which used C
except for the offset fill, for which i used inline assmebler.
I also wonder how much could be earned by converting the whole routine
to assembler, if anyone has any answers to this, then feel free to reply.
Paal K Holmberg
UiB
Norway
"To program, or not to program - that is the question."