$OpenBSD: patch-src_draw_c,v 1.1 2005/03/14 15:12:56 xsa Exp $
--- src/draw.c.orig	Thu Oct 16 08:13:22 2003
+++ src/draw.c	Mon Mar 14 16:02:09 2005
@@ -26,21 +26,11 @@
 #include "pygame.h"
 #include <math.h>
 
-#ifdef _MSC_VER
-#pragma warning (disable:4244)
+/* Many C libraries seem to lack the trunc call (added in C99) */
+#define trunc(d)   (((d) >= 0.0) ? (floor(d)) : (ceil(d)))
+#define FRAC(z)    ((z) - trunc(z))
+#define INVFRAC(z) (1 - FRAC(z))
 
-float trunc(float d)
-{
-    if (d >= 0)
-        return floor(d);
-    return ceil(d);
-}
-
-#endif
-
-#define FRAC(z) (z-trunc(z))
-#define INVFRAC(z) (1-(z-trunc(z)))
-
 static int clip_and_draw_line(SDL_Surface* surf, SDL_Rect* rect, Uint32 color, int* pts);
 static int clip_and_draw_aaline(SDL_Surface* surf, SDL_Rect* rect, Uint32 color, float* pts, int blend);
 static int clip_and_draw_line_width(SDL_Surface* surf, SDL_Rect* rect, Uint32 color, int width, int* pts);
@@ -1071,19 +1061,22 @@ static int set_at(SDL_Surface* surf, int
 
 #define DRAWPIX32(pixel,colorptr,br,blend) \
 	if(SDL_BYTEORDER == SDL_BIG_ENDIAN) color <<= 8; \
-	if(blend) { \
-		int x; \
-		x = colorptr[0]*br+pixel[0]; \
-		pixel[0]= (x>254) ? 255: x; \
-		x = colorptr[1]*br+pixel[1]; \
-		pixel[1]= (x>254) ? 255: x; \
-		x = colorptr[2]*br+pixel[2]; \
-		pixel[2]= (x>254) ? 255: x; \
-	} else { \
-		pixel[0]=(Uint8)(colorptr[0]*br); \
-		pixel[1]=(Uint8)(colorptr[1]*br); \
-		pixel[2]=(Uint8)(colorptr[2]*br); \
-	}
+        if(blend) { \
+                int x; \
+                float nbr = 1.0-br; \
+                x = colorptr[0]*br+pixel[0]*nbr; \
+                pixel[0]= (x>254) ? 255: x; \
+                x = colorptr[1]*br+pixel[1]*nbr; \
+                pixel[1]= (x>254) ? 255: x; \
+                x = colorptr[2]*br+pixel[2]*nbr; \
+                pixel[2]= (x>254) ? 255: x; \
+                if(hasalpha) pixel[3] = pixel[0]+(br*255) - (pixel[3]*br); \
+        } else { \
+                pixel[0]=(Uint8)(colorptr[0]*br); \
+                pixel[1]=(Uint8)(colorptr[1]*br); \
+                pixel[2]=(Uint8)(colorptr[2]*br); \
+                if(hasalpha) pixel[3] = br*255; \
+	} 
 
 /* Adapted from http://freespace.virgin.net/hugo.elias/graphics/x_wuline.htm */
 static void drawaaline(SDL_Surface* surf, Uint32 color, float x1, float y1, float x2, float y2, int blend) {
@@ -1096,8 +1089,9 @@ static void drawaaline(SDL_Surface* surf
 	Uint8* pixel;
 	Uint8* pm = (Uint8*)surf->pixels;
 	Uint8* colorptr = (Uint8*)&color;
+        const int hasalpha = surf->format->Amask;
 
-	pixx = surf->format->BytesPerPixel;
+        pixx = surf->format->BytesPerPixel;
 	pixy = surf->pitch;
 
 	xd = x2-x1;
@@ -1413,9 +1407,12 @@ static void draw_arc(SDL_Surface *dst, i
     x_last = x+cos(angle_start)*radius1;
     y_last = y-sin(angle_start)*radius2;
     for(a=angle_start+aStep; a<=angle_stop; a+=aStep) {
+      int points[4];
       x_next = x+cos(a)*radius1;
       y_next = y-sin(a)*radius2;
-      drawline(dst, color, x_last, y_last, x_next, y_next);
+      points[0] = x_last; points[1] = y_last;
+      points[2] = x_next; points[3] = y_next;
+      clip_and_draw_line(dst, &dst->clip_rect, color, points);
       x_last = x_next;
       y_last = y_next;
     }
@@ -1623,6 +1620,10 @@ static void draw_fillpoly(SDL_Surface *d
 	int ind1, ind2;
 	int ints;
 	int *polyints = PyMem_New(int, n);
+	if (polyints == NULL) {
+		PyErr_NoMemory();
+		return;
+	}
 
 
 	/* Determine Y maxima */
@@ -1670,6 +1671,7 @@ static void draw_fillpoly(SDL_Surface *d
 			drawhorzlineclip(dst, color, polyints[i], y, polyints[i+1]);
 		}
 	}
+	PyMem_Free(polyints);
 }
 
 
@@ -1720,5 +1722,6 @@ void initdraw(void)
 	import_pygame_rect();
 	import_pygame_surface();
 }
+
 
 
