Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5131 | clevermous | 1 | /*! |
2 | \file Draw_FillEllipse.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 | |||
23 | #if SDL_DRAW_BPP == 1 |
||
24 | #define SDL_DRAW_PUTPIXEL \ |
||
25 | memset(((Uint8*)super->pixels+ (y0+y)*super->pitch+ (x0-x)), \ |
||
26 | color, 2*x+1); \ |
||
27 | memset(((Uint8*)super->pixels+ (y0-y)*super->pitch+ (x0-x)), \ |
||
28 | color, 2*x+1); |
||
29 | |||
30 | |||
31 | #elif SDL_DRAW_BPP == 2 |
||
32 | #define SDL_DRAW_PUTPIXEL \ |
||
33 | { \ |
||
34 | p0 = ((Uint8*)super->pixels+ (y0+y)*super->pitch+ (x0-x)*2); \ |
||
35 | p1 = ((Uint8*)super->pixels+ (y0-y)*super->pitch+ (x0-x)*2); \ |
||
36 | i = 2*x+1; \ |
||
37 | switch( i % 4 ) { \ |
||
38 | do{ \ |
||
39 | case 0: *(Uint16*)p0 = color; *(Uint16*)p1 = color; \ |
||
40 | p0+=2; p1+=2; \ |
||
41 | case 3: *(Uint16*)p0 = color; *(Uint16*)p1 = color; \ |
||
42 | p0+=2; p1+=2; \ |
||
43 | case 2: *(Uint16*)p0 = color; *(Uint16*)p1 = color; \ |
||
44 | p0+=2; p1+=2; \ |
||
45 | case 1: *(Uint16*)p0 = color; *(Uint16*)p1 = color; \ |
||
46 | p0+=2; p1+=2; \ |
||
47 | }while( (i-=4) > 0 ); \ |
||
48 | } \ |
||
49 | } |
||
50 | |||
51 | |||
52 | #elif SDL_DRAW_BPP == 3 |
||
53 | #define SDL_DRAW_PUTPIXEL_BPP_3_AUX \ |
||
54 | if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { \ |
||
55 | p0[0] = colorbyte2; \ |
||
56 | p0[1] = colorbyte1; \ |
||
57 | p0[2] = colorbyte0; \ |
||
58 | p1[0] = colorbyte2; \ |
||
59 | p1[1] = colorbyte1; \ |
||
60 | p1[2] = colorbyte0; \ |
||
61 | } else { \ |
||
62 | p0[0] = colorbyte0; \ |
||
63 | p0[1] = colorbyte1; \ |
||
64 | p0[2] = colorbyte2; \ |
||
65 | p1[0] = colorbyte0; \ |
||
66 | p1[1] = colorbyte1; \ |
||
67 | p1[2] = colorbyte2; \ |
||
68 | } |
||
69 | |||
70 | #define SDL_DRAW_PUTPIXEL \ |
||
71 | { \ |
||
72 | p0 = ((Uint8*)super->pixels+ (y0+y)*super->pitch+ (x0-x)*3); \ |
||
73 | p1 = ((Uint8*)super->pixels+ (y0-y)*super->pitch+ (x0-x)*3); \ |
||
74 | i = 2*x+1; \ |
||
75 | switch( i % 4 ) { \ |
||
76 | do{ \ |
||
77 | case 0: SDL_DRAW_PUTPIXEL_BPP_3_AUX \ |
||
78 | p0+=3; p1+=3; \ |
||
79 | case 3: SDL_DRAW_PUTPIXEL_BPP_3_AUX \ |
||
80 | p0+=3; p1+=3; \ |
||
81 | case 2: SDL_DRAW_PUTPIXEL_BPP_3_AUX \ |
||
82 | p0+=3; p1+=3; \ |
||
83 | case 1: SDL_DRAW_PUTPIXEL_BPP_3_AUX \ |
||
84 | p0+=3; p1+=3; \ |
||
85 | }while( (i-=4) > 0 ); \ |
||
86 | } \ |
||
87 | } |
||
88 | |||
89 | |||
90 | #elif SDL_DRAW_BPP == 4 |
||
91 | |||
92 | #ifdef __linux__ |
||
93 | #define SDL_DRAW_WMEMSET_START \ |
||
94 | if (sizeof(wchar_t) == sizeof(Uint32)) { \ |
||
95 | wmemset( (wchar_t*)((Uint8*)super->pixels+ (y0+y)*super->pitch+ (x0-x)*4), \ |
||
96 | color, 2*x+1); \ |
||
97 | wmemset( (wchar_t*)((Uint8*)super->pixels+ (y0-y)*super->pitch+ (x0-x)*4), \ |
||
98 | color, 2*x+1); \ |
||
99 | } else { |
||
100 | #define SDL_DRAW_WMEMSET_END } |
||
101 | #else |
||
102 | #define SDL_DRAW_WMEMSET_START |
||
103 | #define SDL_DRAW_WMEMSET_END |
||
104 | #endif |
||
105 | |||
106 | #define SDL_DRAW_PUTPIXEL \ |
||
107 | SDL_DRAW_WMEMSET_START \ |
||
108 | p0 = ((Uint8*)super->pixels+ (y0+y)*super->pitch+ (x0-x)*4); \ |
||
109 | p1 = ((Uint8*)super->pixels+ (y0-y)*super->pitch+ (x0-x)*4); \ |
||
110 | i = 2*x+1; \ |
||
111 | switch( i % 4 ) { \ |
||
112 | do{ \ |
||
113 | case 0: *(Uint32*)p0 = color; *(Uint32*)p1 = color; \ |
||
114 | p0+=4; p1+=4; \ |
||
115 | case 3: *(Uint32*)p0 = color; *(Uint32*)p1 = color; \ |
||
116 | p0+=4; p1+=4; \ |
||
117 | case 2: *(Uint32*)p0 = color; *(Uint32*)p1 = color; \ |
||
118 | p0+=4; p1+=4; \ |
||
119 | case 1: *(Uint32*)p0 = color; *(Uint32*)p1 = color; \ |
||
120 | p0+=4; p1+=4; \ |
||
121 | }while( (i-=4) > 0 ); \ |
||
122 | } \ |
||
123 | SDL_DRAW_WMEMSET_END |
||
124 | |||
125 | #endif /*SDL_DRAW_BPP*/ |
||
126 | |||
127 | |||
128 | |||
129 | void SDL_DRAWFUNCTION(SDL_Surface *super, |
||
130 | Sint16 x0, Sint16 y0, |
||
131 | Uint16 Xradius, Uint16 Yradius, |
||
132 | Uint32 color) |
||
133 | { |
||
134 | #if SDL_DRAW_BPP == 3 |
||
135 | Uint8 colorbyte0 = (Uint8) (color & 0xff); |
||
136 | Uint8 colorbyte1 = (Uint8) ((color >> 8) & 0xff); |
||
137 | Uint8 colorbyte2 = (Uint8) ((color >> 16) & 0xff); |
||
138 | #endif |
||
139 | |||
140 | #if SDL_DRAW_BPP != 1 |
||
141 | register Uint8 *p0; |
||
142 | register Uint8 *p1; |
||
143 | register Sint16 i; |
||
144 | #endif |
||
145 | |||
146 | Sint32 x, y; |
||
147 | Sint32 Xchange, Ychange; |
||
148 | Sint32 EllipseError; |
||
149 | Sint32 TwoASquare, TwoBSquare; |
||
150 | Sint32 StoppingX, StoppingY; |
||
151 | |||
152 | TwoASquare = 2*Xradius*Xradius; |
||
153 | TwoBSquare = 2*Yradius*Yradius; |
||
154 | |||
155 | /*1st set of points*/ |
||
156 | x = Xradius-1; /*radius zero == draw nothing*/ |
||
157 | y = 0; |
||
158 | |||
159 | Xchange = Yradius*Yradius*(1-2*Xradius); |
||
160 | Ychange = Xradius*Xradius; |
||
161 | |||
162 | EllipseError = 0; |
||
163 | |||
164 | StoppingX = TwoBSquare*Xradius; |
||
165 | StoppingY = 0; |
||
166 | |||
167 | /*Plot 2 ellipse scan lines for iteration*/ |
||
168 | while (StoppingX > StoppingY) { |
||
169 | |||
170 | SDL_DRAW_PUTPIXEL |
||
171 | |||
172 | ++y; |
||
173 | StoppingY += TwoASquare; |
||
174 | EllipseError += Ychange; |
||
175 | Ychange += TwoASquare; |
||
176 | if (( 2*EllipseError + Xchange) > 0) { |
||
177 | --x; |
||
178 | StoppingX -= TwoBSquare; |
||
179 | EllipseError += Xchange; |
||
180 | Xchange += TwoBSquare; |
||
181 | } |
||
182 | }/*while*/ |
||
183 | |||
184 | /*2nd set of points*/ |
||
185 | x = 0; |
||
186 | y = Yradius-1; /*radius zero == draw nothing*/ |
||
187 | Xchange = Yradius*Yradius; |
||
188 | Ychange = Xradius*Xradius*(1-2*Yradius); |
||
189 | EllipseError = 0; |
||
190 | StoppingX = 0; |
||
191 | StoppingY = TwoASquare*Yradius; |
||
192 | |||
193 | /*Plot 2 ellipse scan lines for iteration*/ |
||
194 | while (StoppingX < StoppingY) { |
||
195 | |||
196 | SDL_DRAW_PUTPIXEL |
||
197 | |||
198 | ++x; |
||
199 | StoppingX += TwoBSquare; |
||
200 | EllipseError += Xchange; |
||
201 | Xchange += TwoBSquare; |
||
202 | if ((2*EllipseError + Ychange) > 0) { |
||
203 | --y; |
||
204 | StoppingY -= TwoASquare; |
||
205 | EllipseError += Ychange; |
||
206 | Ychange += TwoASquare; |
||
207 | } |
||
208 | } |
||
209 | }/*Draw_FillEllipse*/ |
||
210 | |||
211 | |||
212 | #undef SDL_DRAW_PUTPIXEL |
||
213 | #undef SDL_DRAW_PUTPIXEL_BPP_3_AUX |
||
214 | |||
215 | #undef SDL_DRAW_WMEMSET_START |
||
216 | #undef SDL_DRAW_WMEMSET_END> |
||
217 |