comparison 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
comparison
equal deleted inserted replaced
2895:9328f53a0ca2 2896:1ef2f1e75ff7
22 #include "SDL_config.h" 22 #include "SDL_config.h"
23 23
24 #include "SDL_video.h" 24 #include "SDL_video.h"
25 #include "SDL_blit.h" 25 #include "SDL_blit.h"
26 26
27 #define ABS(x) (x < 0 ? -x : x) 27 #define ABS(_x) ((_x) < 0 ? -(_x) : (_x))
28 28
29 #define SWAP(x, y) (x ^= y ^= x ^= y) 29 #define SWAP(_x, _y) do { int tmp; tmp = _x; _x = _y; _y = tmp; } while (0)
30 30
31 #define BRESENHAM(x0, y0, x1, y1, op, color) \ 31 #define BRESENHAM(x0, y0, x1, y1, op, color) \
32 { \ 32 { \
33 int deltax, deltay, steep, error, xstep, ystep, x, y; \ 33 int deltax, deltay, steep, error, xstep, ystep, x, y; \
34 \ 34 \
35 deltax = ABS(x1 - x0); \ 35 deltax = ABS(x1 - x0); \
36 deltay = ABS(y1 - y0); \ 36 deltay = ABS(y1 - y0); \
37 steep = deltay > deltax; \ 37 steep = (deltay > deltax); \
38 error = deltax / 2; \
39 if (steep) { \ 38 if (steep) { \
40 SWAP(x0, y0); \ 39 SWAP(x0, y0); \
41 SWAP(x1, y1); \ 40 SWAP(x1, y1); \
41 SWAP(deltax, deltay); \
42 } \ 42 } \
43 error = (x1 - x0) / 2; \
43 y = y0; \ 44 y = y0; \
44 if (x0 > x1) { \ 45 if (x0 > x1) { \
45 xstep = -1; \ 46 xstep = -1; \
46 deltax = -deltax; \
47 } else { \ 47 } else { \
48 xstep = 1; \ 48 xstep = 1; \
49 } \ 49 } \
50 if (y0 < y1) { \ 50 if (y0 < y1) { \
51 ystep = 1; \ 51 ystep = 1; \
55 if (!steep) { \ 55 if (!steep) { \
56 for (x = x0; x != x1; x += xstep) { \ 56 for (x = x0; x != x1; x += xstep) { \
57 op(x, y, color); \ 57 op(x, y, color); \
58 error -= deltay; \ 58 error -= deltay; \
59 if (error < 0) { \ 59 if (error < 0) { \
60 y = y + ystep; \ 60 y += ystep; \
61 error += deltax; \ 61 error += deltax; \
62 } \ 62 } \
63 } \ 63 } \
64 } else { \ 64 } else { \
65 for (x = x0; x != x1; x += xstep) { \ 65 for (x = x0; x != x1; x += xstep) { \
66 op(y, x, color); \ 66 op(y, x, color); \
67 error -= deltay; \ 67 error -= deltay; \
68 if (error < 0) { \ 68 if (error < 0) { \
69 y = y + ystep; \ 69 y += ystep; \
70 error += deltax; \ 70 error += deltax; \
71 } \ 71 } \
72 } \ 72 } \
73 } \ 73 } \
74 } 74 }