diff --git a/examples/Makefile.am b/examples/Makefile.am
index 88fd0d0..80f7d1d 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -2,7 +2,7 @@
 
 AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/pipi
 
-bin_PROGRAMS = edd img2rubik sharpen floodfill line
+bin_PROGRAMS = edd img2rubik sharpen floodfill line bezier
 
 edd_SOURCES = edd.c
 edd_LDADD = ../pipi/libpipi.la
@@ -18,3 +18,6 @@ floodfill_LDADD = ../pipi/libpipi.la
 
 line_SOURCES = line.c
 line_LDADD = ../pipi/libpipi.la
+
+bezier_SOURCES = bezier.c
+bezier_LDADD = ../pipi/libpipi.la
diff --git a/examples/line.c b/examples/line.c
index 899713b..95dc164 100644
--- a/examples/line.c
+++ b/examples/line.c
@@ -37,7 +37,7 @@ int main(int argc, char *argv[])
 
     while(count--) {
         pipi_draw_line(newimg,
-                       rand() % w, rand() % h,
+                       rand()  , rand() % h,
                        rand() % w, rand() % h,
                        rand(),
                        1);
diff --git a/pipi/Makefile.am b/pipi/Makefile.am
index 71462e8..f971eda 100644
--- a/pipi/Makefile.am
+++ b/pipi/Makefile.am
@@ -44,6 +44,7 @@ codec_sources =
 paint_sources = \
 	paint/floodfill.c \
 	paint/line.c paint/line_template.h paint/aline_template.h \
+	paint/bezier.c \
 	paint/tile.c
 
 render_sources = \
diff --git a/pipi/paint/aline_template.h b/pipi/paint/aline_template.h
index 7b36e73..101be7b 100644
--- a/pipi/paint/aline_template.h
+++ b/pipi/paint/aline_template.h
@@ -70,7 +70,7 @@ if (fabsf(xd) > fabsf(yd)) {
         val2 += 0.3*focus;
 
         PLOT(x, yf, val1);
-        PLOT(x, yf+1, val2);
+        PLOT(x, (yf+1)<y1?(yf+1):yf, val2);
 
         yf = yf + g;
 		}
diff --git a/pipi/paint/line.c b/pipi/paint/line.c
index 6f385c9..21a72b0 100644
--- a/pipi/paint/line.c
+++ b/pipi/paint/line.c
@@ -24,6 +24,11 @@
 #include <stdlib.h>
 #include <string.h>
 
+#undef __USE_MISC  /* THAT sucks */
+#undef __USE_XOPEN /* THAT sucks, too (avoid declaring y1 in math.h) */
+#include <math.h>
+
+
 #include "pipi.h"
 #include "pipi_internals.h"
 
@@ -268,10 +273,11 @@ static void draw_aliased_line_gray(pipi_image_t *img, struct line* s)
 
 /* Xiaolin Wu's line algorithm, as seen at http://portal.acm.org/citation.cfm?id=122734 */
 
-/* math.h doesn't like y0 (sucker) */
+/* math.h doesn't like y1 (sucker) */
 float floorf(float x);
 float truncf(float x);
 float fabsf(float x);
+
 static float fractf(float d) { return (d - floorf(d)); }
 static float fractinvf(float d) { return (1 - (d - floorf(d))); }
 
@@ -286,13 +292,13 @@ static void draw_antialiased_line_float(pipi_image_t *img, struct line* s)
     s->buf_f[qwer] = (c*s->colorf[0]) + (1-c) * s->buf_f[qwer]; \
     s->buf_f[qweg] = (c*s->colorf[1]) + (1-c) * s->buf_f[qweg]; \
     s->buf_f[qweb] = (c*s->colorf[2]) + (1-c) * s->buf_f[qweb]; \
-    if(s->buf_f[qwer] > 0.8f) s->buf_f[qwer] = 0.8f;   /* DEBUG LOL !*/ \
-    if(s->buf_f[qwer] < 0.2f) s->buf_f[qwer] = 0.2f; \
-    if(s->buf_f[qweg] > 0.8f) s->buf_f[qweg] = 0.8f; \
-    if(s->buf_f[qweg] < 0.2f) s->buf_f[qweg] = 0.2f; \
-    if(s->buf_f[qweb] > 0.8f) s->buf_f[qweb] = 0.8f; \
-    if(s->buf_f[qweb] < 0.2f) s->buf_f[qweb] = 0.2f; \
-  }
+    if(s->buf_f[qwer] > 1.0f) s->buf_f[qwer] = 1.0f; \
+    if(s->buf_f[qwer] < 0.0f || isnan(s->buf_f[qwer])) s->buf_f[qwer] = 0.0f; \
+    if(s->buf_f[qweg] > 1.0f) s->buf_f[qweg] = 1.0f; \
+    if(s->buf_f[qweg] < 0.0f || isnan(s->buf_f[qweg])) s->buf_f[qweg] = 0.0f; \
+    if(s->buf_f[qweb] > 1.0f) s->buf_f[qweb] = 1.0f; \
+    if(s->buf_f[qweb] < 0.0f || isnan(s->buf_f[qweb])) s->buf_f[qweb] = 0.0f;  }
+
 #include "aline_template.h"
 }
 
@@ -301,6 +307,10 @@ static void draw_antialiased_line_gray(pipi_image_t *img, struct line* s)
 {
 #undef  PLOT
 #define PLOT(x, y, c) s->buf_f[((int)(x))+((int)(y))*img->w] =  \
-    (c*s->colorf[0]) + (1-c) * s->buf_f[((int)(x))+((int)(y))*img->w];
+    (c*s->colorf[0]) + (1-c) * s->buf_f[((int)(x))+((int)(y))*img->w]; \
+    if(s->buf_f[((int)(x))+((int)(y))*img->w] > 1.0f) s->buf_f[((int)(x))+((int)(y))*img->w] = 1.0f; \
+    if(s->buf_f[((int)(x))+((int)(y))*img->w] < 0.0f) s->buf_f[((int)(x))+((int)(y))*img->w] = 0.0f; \
+    if(isnan(s->buf_f[((int)(x))+((int)(y))*img->w])) s->buf_f[((int)(x))+((int)(y))*img->w] = 0.0f;
+
 #include "aline_template.h"
 }
diff --git a/pipi/pipi.h b/pipi/pipi.h
index 751b339..49f970d 100644
--- a/pipi/pipi.h
+++ b/pipi/pipi.h
@@ -156,6 +156,7 @@ extern int pipi_flood_fill(pipi_image_t *,
 extern int pipi_draw_line(pipi_image_t *, int, int, int, int, uint32_t, int);
 extern int pipi_draw_polyline(pipi_image_t *, int const[], int const[],
                               int , uint32_t, int);
+extern int pipi_draw_bezier4(pipi_image_t *,int, int, int, int, int, int, int, int, uint32_t, int, int);
 extern pipi_image_t *pipi_reduce(pipi_image_t *, int, double const *);
 
 extern pipi_image_t *pipi_dither_ediff(pipi_image_t *, pipi_image_t *,