@H_502_0@int Draw_Line(int x0,int y0,// starting position
int x1,int y1,// ending position
UCHAR color,// color index
UCHAR *vb_start,int lpitch) // video buffer and memory pitch
{
// this function draws a line from xo,yo to x1,y1 using differential error
// terms (based on Bresenahams work)
@H_502_0@int dx,// difference in x's
dy,// difference in y's
dx2,// dx,dy * 2
dy2,
x_inc,// amount in pixel space to move during drawing
y_inc,// amount in pixel space to move during drawing
error,// the discriminant i.e. error i.e. decision variable
index; // used for looping
@H_502_0@// pre-compute first pixel address in video buffer
vb_start = vb_start + x0 + y0*lpitch;
@H_502_0@// compute horizontal and vertical deltas
dx = x1-x0;
dy = y1-y0;
@H_502_0@// test which direction the line is going in i.e. slope angle
if (dx>=0)
{
x_inc = 1;
@H_502_0@ } // end if line is moving right
else
{
x_inc = -1;
dx = -dx; // need absolute value
@H_502_0@ } // end else moving left
@H_502_0@// test y component of slope
@H_502_0@if (dy>=0)
{
y_inc = lpitch;
} // end if line is moving down
else
{
y_inc = -lpitch;
dy = -dy; // need absolute value
@H_502_0@ } // end else moving up
@H_502_0@// compute (dx,dy) * 2
dx2 = dx << 1;
dy2 = dy << 1;
@H_502_0@// now based on which delta is greater we can draw the line
if (dx > dy)
{
// initialize error term
error = dy2 - dx;
@H_502_0@ // draw the line
for (index=0; index <= dx; index++)
{
// set the pixel
*vb_start = color;
@H_502_0@ // test if error has overflowed
if (error >= 0)
{
error-=dx2;
@H_502_0@ // move to next line
vb_start+=y_inc;
@H_502_0@ } // end if error overflowed
@H_502_0@ // adjust the error term
error+=dy2;
@H_502_0@ // move to the next pixel
vb_start+=x_inc;
@H_502_0@ } // end for
@H_502_0@ } // end if |slope| <= 1
else
{
// initialize error term
error = dx2 - dy;
@H_502_0@ // draw the line
for (index=0; index <= dy; index++)
{
// set the pixel
*vb_start = color;
@H_502_0@ // test if error overflowed
if (error >= 0)
{
error-=dy2;
@H_502_0@ // move to next line
vb_start+=x_inc;
@H_502_0@ } // end if error overflowed
@H_502_0@ // adjust the error term
error+=dx2;
@H_502_0@ // move to the next pixel
vb_start+=y_inc;
@H_502_0@ } // end for
@H_502_0@ } // end else |slope| > 1
@H_502_0@// return success
return(1);
@H_502_0@} // end Draw_Line