Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5131 | clevermous | 1 | /*! |
2 | \file Draw_Line.c |
||
3 | \author Mario Palomo |
||
4 | \author Jose M. de la Huerga Fernández |
||
5 | \author Pepe González Mora |
||
6 | \date 05-2002 |
||
7 | |||
8 | This library is free software; you can redistribute it and/or |
||
9 | modify it under the terms of the GNU Library General Public |
||
10 | License as published by the Free Software Foundation; either |
||
11 | version 2 of the License, or (at your option) any later version. |
||
12 | |||
13 | This library is distributed in the hope that it will be useful, |
||
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||
16 | Library General Public License for more details. |
||
17 | |||
18 | You should have received a copy of the GNU Library General Public |
||
19 | License along with this library; if not, write to the Free Foundation, |
||
20 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
21 | */ |
||
22 | #define SDL_DRAW_PUTPIXEL_BPP(A, B, C) \ |
||
23 | *(##A##(##B##(Uint8*)super->pixels + y*super->pitch + x*SDL_DRAW_BPP))=##C##; |
||
24 | |||
25 | #if SDL_DRAW_BPP == 1 |
||
26 | #define SDL_DRAW_PUTPIXEL SDL_DRAW_PUTPIXEL_BPP(0+,0+,color) |
||
27 | |||
28 | #elif SDL_DRAW_BPP == 2 |
||
29 | #define SDL_DRAW_PUTPIXEL SDL_DRAW_PUTPIXEL_BPP((Uint16*),0+,color) |
||
30 | |||
31 | #elif SDL_DRAW_BPP == 3 |
||
32 | #define SDL_DRAW_PUTPIXEL \ |
||
33 | SDL_DRAW_PUTPIXEL_BPP(0+,1+,(Uint8)colorbyte1) \ |
||
34 | if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { \ |
||
35 | SDL_DRAW_PUTPIXEL_BPP(0+,0+,(Uint8)colorbyte2) \ |
||
36 | SDL_DRAW_PUTPIXEL_BPP(0+,2+,(Uint8)colorbyte0) \ |
||
37 | }else{ \ |
||
38 | SDL_DRAW_PUTPIXEL_BPP(0+,0+,(Uint8)colorbyte0) \ |
||
39 | SDL_DRAW_PUTPIXEL_BPP(0+,2+,(Uint8)colorbyte2) \ |
||
40 | } |
||
41 | |||
42 | #elif SDL_DRAW_BPP == 4 |
||
43 | #define SDL_DRAW_PUTPIXEL SDL_DRAW_PUTPIXEL_BPP((Uint32*),0+,color) |
||
44 | |||
45 | #endif /*SDL_DRAW_BPP*/ |
||
46 | |||
47 | |||
48 | void SDL_DRAWFUNCTION(SDL_Surface *super, |
||
49 | Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, |
||
50 | Uint32 color) |
||
51 | { |
||
52 | #if SDL_DRAW_BPP == 3 |
||
53 | Uint8 colorbyte0 = (Uint8) (color & 0xff); |
||
54 | Uint8 colorbyte1 = (Uint8) ((color >> 8) & 0xff); |
||
55 | Uint8 colorbyte2 = (Uint8) ((color >> 16) & 0xff); |
||
56 | #endif |
||
57 | |||
58 | Sint16 x = x1; |
||
59 | Sint16 y = y1; |
||
60 | Sint16 dy = y2 - y1; |
||
61 | Sint16 dx = x2 - x1; |
||
62 | |||
63 | Sint16 G, DeltaG1, DeltaG2, minG, maxG; |
||
64 | Sint16 swap; |
||
65 | Sint16 inc = 1; |
||
66 | |||
67 | SDL_DRAW_PUTPIXEL |
||
68 | |||
69 | if (abs(dy) < abs(dx)) { /* -1 < ramp < 1 */ |
||
70 | if (dx < 0) { |
||
71 | dx = -dx; |
||
72 | dy = -dy; |
||
73 | |||
74 | swap = y2; |
||
75 | y2 = y1; |
||
76 | y1 = swap; |
||
77 | |||
78 | swap = x2; |
||
79 | x2 = x1; |
||
80 | x1 = swap; |
||
81 | } |
||
82 | if (dy < 0) { |
||
83 | dy = -dy; |
||
84 | inc = -1; |
||
85 | } |
||
86 | |||
87 | G = 2 * dy - dx; |
||
88 | DeltaG1 = 2 * (dy - dx); |
||
89 | DeltaG2 = 2 * dy; |
||
90 | |||
91 | while (x++ < x2) { |
||
92 | if (G > 0) { G += DeltaG1; y += inc; } |
||
93 | else G += DeltaG2; |
||
94 | |||
95 | SDL_DRAW_PUTPIXEL |
||
96 | }/*while*/ |
||
97 | |||
98 | } else { /* ramp < -1 or ramp > 1 */ |
||
99 | if (dy < 0) { |
||
100 | dx = -dx; |
||
101 | dy = -dy; |
||
102 | |||
103 | swap = y2; |
||
104 | y2 = y1; |
||
105 | y1 = swap; |
||
106 | |||
107 | swap = x2; |
||
108 | x2 = x1; |
||
109 | x1 = swap; |
||
110 | } |
||
111 | if (dx < 0) { |
||
112 | dx = -dx; |
||
113 | inc = -1; |
||
114 | } |
||
115 | |||
116 | G = 2 * dx - dy; |
||
117 | minG = maxG = G; |
||
118 | DeltaG1 = 2 * (dx - dy); |
||
119 | DeltaG2 = 2 * dx; |
||
120 | |||
121 | while (y++ < y2) { |
||
122 | if (G > 0) { G += DeltaG1; x += inc; } |
||
123 | else G += DeltaG2; |
||
124 | |||
125 | SDL_DRAW_PUTPIXEL |
||
126 | }/*while*/ |
||
127 | |||
128 | }/*if*/ |
||
129 | |||
130 | }/*Draw_Line*/ |
||
131 | |||
132 | |||
133 | #undef SDL_DRAW_PUTPIXEL |
||
134 | #undef SDL_DRAW_PUTPIXEL_BPP>>>>>>>>>> |
||
135 |