Mercurial > audlegacy-plugins
comparison src/paranormal/drawing.c @ 192:a7c823478180 trunk
[svn] - add fast linedrawing code
author | nenolod |
---|---|
date | Thu, 02 Nov 2006 22:19:05 -0800 |
parents | |
children | 4b48e6e9b3cb |
comparison
equal
deleted
inserted
replaced
191:6d5f164a8719 | 192:a7c823478180 |
---|---|
1 #include "paranormal.h" | |
2 #include "actuators.h" | |
3 #include "pn_utils.h" | |
4 | |
5 extern SDL_Surface *screen; | |
6 | |
7 void | |
8 pn_draw_line (guint _x0, guint _y0, guint _x1, guint _y1, guchar value) | |
9 { | |
10 gint x0 = _x0; | |
11 gint y0 = _y0; | |
12 gint x1 = _x1; | |
13 gint y1 = _y1; | |
14 | |
15 gint dy = y1 - y0; | |
16 gint dx = x1 - x0; | |
17 gint stepx, stepy; | |
18 gint fraction; | |
19 | |
20 if (dy < 0) | |
21 { | |
22 dy = -dy; | |
23 stepy = -(screen->pitch >> 2); | |
24 } | |
25 else | |
26 { | |
27 stepy = screen->pitch>>2; | |
28 } | |
29 if (dx < 0) | |
30 { | |
31 dx = -dx; | |
32 stepx = -1; | |
33 } | |
34 else | |
35 { | |
36 stepx = 1; | |
37 } | |
38 dy <<= 1; | |
39 dx <<= 1; | |
40 | |
41 y0 *= screen->pitch>>2; | |
42 y1 *= screen->pitch>>2; | |
43 pn_image_data->surface[0][PN_IMG_INDEX(x0, y0)] = value; | |
44 if (dx > dy) | |
45 { | |
46 fraction = dy - (dx >> 1); | |
47 while (x0 != x1) | |
48 { | |
49 if (fraction >= 0) | |
50 { | |
51 y0 += stepy; | |
52 fraction -= dx; | |
53 } | |
54 x0 += stepx; | |
55 fraction += dy; | |
56 pn_image_data->surface[0][PN_IMG_INDEX(x0, y0)] = value; | |
57 } | |
58 } | |
59 else | |
60 { | |
61 fraction = dx - (dy >> 1); | |
62 while (y0 != y1) | |
63 { | |
64 if (fraction >= 0) | |
65 { | |
66 x0 += stepx; | |
67 fraction -= dy; | |
68 } | |
69 y0 += stepy; | |
70 fraction += dx; | |
71 pn_image_data->surface[0][PN_IMG_INDEX(x0, y0)] = value; | |
72 } | |
73 } | |
74 } |