bresenham算法绘制直线(未优化)

参数为2点坐标,32位颜色值,指向绘图表面开头的内存指针,绘图表面的实际行字节大小

 

 

 

int Draw_Line_32( int iX0, int iY0, int iX1, int iY1, DWORD dwColor, DWORD * lpdwStart, int iPitch ) { int iDx, iDy, iXInc, iYInc, iError; iDx = iX1 - iX0; iDy = iY1 - iY0; iError = 0; // 32递增的pitch iPitch >>= 2; //初始起始绘制位置 lpdwStart += iX0 + iY0 * iPitch; //点的绘制方向 if( iDx >= 0 ) { iXInc = 1; } else { iXInc = -1; iDx = -iDx; } if( iDy >= 0 ) { iYInc = iPitch; } else { iYInc = -( iPitch ); iDy = -iDy; } //近x轴线段所作的处理 if( iDx > iDy ) { int iIndex; for( iIndex = 0; iIndex <= iDx; ++iIndex ) { //画点 *lpdwStart = dwColor; lpdwStart += iXInc; iError += iDy; if( iError > iDx ) { lpdwStart += iYInc; iError -= iDx; } } } //近y轴线段所作的处理 else { int iIndex; for( iIndex = 0; iIndex <= iDy; ++iIndex ) { *lpdwStart = dwColor; lpdwStart += iYInc; iError += iDx; if( iError > iDy ) { lpdwStart += iXInc; iError -= iDy; } } } return 1; }

你可能感兴趣的:(bresenham算法绘制直线(未优化))