直线绘制中出现的锯齿现象称为走样,消除走样的方法称为反走样。文中通过对直线走样产生的原因进行理论上的分析,总结了现有的反走样技术。通过对经典的DDA直线绘制算法和Wu直线反走样绘制算法的研究,在二者结合的基础上,给出了一种任意宽度和复杂背景色下的直线反走样快速绘制算法:对于直线f(x)=mx+b,0≤m≤1,x轴上每移动一个像素单位,根据直线所需绘制的宽度,在y轴上进行跨度像素着色,填充的色深值取决于该像素到对应直线边缘线的距离、原有背景色深和当前直线绘制色深。对算法进行了去浮点优化,给出了复杂度分析和实验结果,实践证明,该算法有很好的执行效率和反走样效果。
Theoretically analyzes anti-aliasing problem.A solution based on the classical DDA(digital differential analyzer) algorithm and Wu anti-aliasing algorithm is proposed to address the issue.The solution offers an efficient line drawing algorithm which is applicable to arbitrary line width and complex background color:for line f(x)=mx+b,0≤m≤1.Specifically the algorithm makes pixel by pixel step wise move along x(y) axis while filling span pixels along line direction of y(x) based on line width.The filling color is dependent on three factors including current pixel's distance from the line's centerline,original background color and current line drawing color.The algorithm is further optimized with floating-point and complexity analysis,experiment result and application of the new algorithm are presented.