diff src/video/SDL_drawline.c @ 2896:1ef2f1e75ff7

Date: Sat, 20 Dec 2008 23:25:19 +0100 From: Couriersud Subject: 32 & 16 bit versions of blendrect and blendline attached are 32, 16 and 15 bit versions of the blendrect and blendline functionality. There was an issue with the bresenham alg. in drawline which I also fixed.
author Sam Lantinga <slouken@libsdl.org>
date Sat, 20 Dec 2008 23:19:20 +0000
parents 1863c8b59658
children e40448bc7727
line wrap: on
line diff
--- a/src/video/SDL_drawline.c	Sat Dec 20 23:10:20 2008 +0000
+++ b/src/video/SDL_drawline.c	Sat Dec 20 23:19:20 2008 +0000
@@ -24,9 +24,9 @@
 #include "SDL_video.h"
 #include "SDL_blit.h"
 
-#define ABS(x) (x < 0 ? -x : x)
+#define ABS(_x) ((_x) < 0 ? -(_x) : (_x))
 
-#define SWAP(x, y) (x ^= y ^= x ^= y)
+#define SWAP(_x, _y) do { int tmp; tmp = _x; _x = _y; _y = tmp; } while (0)
 
 #define BRESENHAM(x0, y0, x1, y1, op, color) \
 { \
@@ -34,16 +34,16 @@
  \
     deltax = ABS(x1 - x0); \
     deltay = ABS(y1 - y0); \
-    steep = deltay > deltax; \
-    error = deltax / 2; \
+    steep = (deltay > deltax); \
     if (steep) { \
         SWAP(x0, y0); \
         SWAP(x1, y1); \
+        SWAP(deltax, deltay); \
     } \
+    error = (x1 - x0) / 2; \
     y = y0; \
     if (x0 > x1) { \
         xstep = -1; \
-        deltax = -deltax; \
     } else { \
         xstep = 1; \
     } \
@@ -57,7 +57,7 @@
             op(x, y, color); \
             error -= deltay; \
             if (error < 0) { \
-                y = y + ystep; \
+                y += ystep; \
                 error += deltax; \
             } \
         } \
@@ -66,7 +66,7 @@
             op(y, x, color); \
             error -= deltay; \
             if (error < 0) { \
-                y = y + ystep; \
+                y += ystep; \
                 error += deltax; \
             } \
         } \