Xiaolin Wu在C语言中的行算法的源代码?

时间:2009-12-14 14:56:27

标签: c algorithm graphics line antialiasing

我正在寻找一个很好的和有效的实现小林吴的抗锯齿线绘图算法在C,有没有人有这个代码,他们可以与我分享?

由于

2 个答案:

答案 0 :(得分:13)

维基百科有pseudo code

Google有很多例子,例如this onethis one。你的问题提醒了我关于antialiasing的好文章。

编辑:如果您还不知道,可以发现Hugo Helias's website

答案 1 :(得分:0)

想知道实现here是否正确,因为

ErrorAdj = ((unsigned long) DeltaX << 16) / (unsigned long) DeltaY;
      /* Draw all pixels other than the first and last */
while (--DeltaY) {
         ErrorAccTemp = ErrorAcc;   /* remember current accumulated error */
         ErrorAcc += ErrorAdj;      /* calculate error for next pixel */
         if (ErrorAcc <= ErrorAccTemp) {
            /* The error accumulator turned over, so advance the X coord */
            X0 += XDir;
         }
         Y0++; /* Y-major, so always advance Y */
         /* The IntensityBits most significant bits of ErrorAcc give us the
            intensity weighting for this pixel, and the complement of the
            weighting for the paired pixel */
         Weighting = ErrorAcc >> IntensityShift;
         DrawPixel(pDC,X0, Y0, BaseColor + Weighting);
         DrawPixel(pDC,X0 + XDir, Y0,
               BaseColor + (Weighting ^ WeightingComplementMask));
      }

条件if (ErrorAcc <= ErrorAccTemp)始终为假。