8位模式下画线(Bresenham算法,光栅化)

8位模式下画线(Bresenham算法,光栅化),第1张

概述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 bu
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)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// pre-compute first pixel address in vIDeo buffervb_start = vb_start + x0 + y0*lpitch;// compute horizontal and vertical deltasdx = x1-x0;dy = y1-y0;// test which direction the line is going in i.e. slope angleif (dx>=0)   {   x_inc = 1;   } // end if line is moving rightelse   {   x_inc = -1;   dx    = -dx;  // need absolute value   } // end else moving left// test y component of slopeif (dy>=0)   {   y_inc = lpitch;   } // end if line is moving downelse   {   y_inc = -lpitch;   dy    = -dy;  // need absolute value   } // end else moving up// compute (dx,dy) * 2dx2 = dx << 1;dy2 = dy << 1;// Now based on which delta is greater we can draw the lineif (dx > dy)   {   // initialize error term   error = dy2 - dx;    // draw the line   for (index=0; index <= dx; index++)       {       // set the pixel       *vb_start = color;       // test if error has overflowed       if (error >= 0)           {          error-=dx2;          // move to next line          vb_start+=y_inc;	   } // end if error overflowed       // adjust the error term       error+=dy2;       // move to the next pixel       vb_start+=x_inc;       } // end for   } // end if |slope| <= 1else   {   // initialize error term   error = dx2 - dy;    // draw the line   for (index=0; index <= dy; index++)       {       // set the pixel       *vb_start = color;       // test if error overflowed       if (error >= 0)          {          error-=dy2;          // move to next line          vb_start+=x_inc;          } // end if error overflowed       // adjust the error term       error+=dx2;       // move to the next pixel       vb_start+=y_inc;       } // end for   } // end else |slope| > 1// return successreturn(1);} // end Draw_line
总结

以上是内存溢出为你收集整理的8位模式下画线(Bresenham算法光栅化)全部内容,希望文章能够帮你解决8位模式下画线(Bresenham算法,光栅化)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1290758.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-09
下一篇 2022-06-09

发表评论

登录后才能评论

评论列表(0条)

保存