Question

I'm looking for a nice and efficient implementation of Xiaolin Wu's anti-aliased line drawing algorithm in C, does anyone have this code they could share with me?

Thanks

Was it helpful?

Solution

Wikipedia has pseudo code.

Google has many examples like this one or this one. And your question reminded me this nice article on antialiasing.

EDIT: It's time to discover Hugo Helias's website if you don't know it already.

OTHER TIPS

Wondering if implementation here is correct, because in

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));
      }

condition if (ErrorAcc <= ErrorAccTemp) is always false.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top