flupke / pypotrace

Python bindings for potrace library
Other
166 stars 43 forks source link

Fix a bug in setpixel: bitshift unsigned long rather than int. #2

Closed jboy closed 12 years ago

jboy commented 12 years ago

Hi, thanks for creating this great wrapper around libpotrace!

I found a bug when I used pypotrace on my system. The result of pypotrace (plotted using matplotlib) looked like this: http://postimage.org/image/6w8uzfiit/ when it should have looked like this: http://postimage.org/image/5sntkqn4n/

I spent 2 days tracking it down: verifying that I was using pypotrace correctly; comparing the incorrect pypotrace result to the output from the potrace command-line program (which was correct); and tracing through the potrace, libpotrace and pypotrace code in detail.

Eventually I realised that the incorrect corner segments always started & ended on multiples of 64 pixels: http://postimage.org/image/z6y98a4qt/

This indicated that the contours of the binary image were being switched on/off into rectangular blocks by pypotrace before calling the potrace_trace function. So I suspected the setpixel function, specifically some sort of integer sign problem.

When I changed the bitshifted int 1 to an unsigned long 1uL in setpixel, it fixed the bug.

jboy commented 12 years ago

This patch also fixes the test failure described in this issue: https://github.com/flupke/pypotrace/issues/1

flupke commented 12 years ago

Thanks for the great detective work jboy!