Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5131 | clevermous | 1 | /*! |
2 | \file Draw_Ellipse.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 | #define SDL_DRAW_PUTPIXEL_BPP(A, B, C) \ |
||
24 | *(##A##(##B##(Uint8*)super->pixels + (y0+y)*super->pitch + \ |
||
25 | (x0+x)*SDL_DRAW_BPP)) = ##C##; \ |
||
26 | *(##A##(##B##(Uint8*)super->pixels + (y0-y)*super->pitch + \ |
||
27 | (x0+x)*SDL_DRAW_BPP)) = ##C##; \ |
||
28 | *(##A##(##B##(Uint8*)super->pixels + (y0+y)*super->pitch + \ |
||
29 | (x0-x)*SDL_DRAW_BPP)) = ##C##; \ |
||
30 | *(##A##(##B##(Uint8*)super->pixels + (y0-y)*super->pitch + \ |
||
31 | (x0-x)*SDL_DRAW_BPP)) = ##C##; |
||
32 | |||
33 | |||
34 | #if SDL_DRAW_BPP == 1 |
||
35 | #define SDL_DRAW_PUTPIXEL SDL_DRAW_PUTPIXEL_BPP(0+,0+,color) |
||
36 | |||
37 | #elif SDL_DRAW_BPP == 2 |
||
38 | #define SDL_DRAW_PUTPIXEL SDL_DRAW_PUTPIXEL_BPP((Uint16*),0+,color) |
||
39 | |||
40 | #elif SDL_DRAW_BPP == 3 |
||
41 | #define SDL_DRAW_PUTPIXEL \ |
||
42 | SDL_DRAW_PUTPIXEL_BPP(0+,1+,colorbyte1) \ |
||
43 | if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { \ |
||
44 | SDL_DRAW_PUTPIXEL_BPP(0+,0+,colorbyte2) \ |
||
45 | SDL_DRAW_PUTPIXEL_BPP(0+,2+,colorbyte0) \ |
||
46 | }else{ \ |
||
47 | SDL_DRAW_PUTPIXEL_BPP(0+,0+,colorbyte0) \ |
||
48 | SDL_DRAW_PUTPIXEL_BPP(0+,2+,colorbyte2) \ |
||
49 | } |
||
50 | |||
51 | #elif SDL_DRAW_BPP == 4 |
||
52 | #define SDL_DRAW_PUTPIXEL SDL_DRAW_PUTPIXEL_BPP((Uint32*),0+,color) |
||
53 | |||
54 | #endif /*SDL_DRAW_BPP*/ |
||
55 | |||
56 | |||
57 | void SDL_DRAWFUNCTION(SDL_Surface *super, |
||
58 | Sint16 x0, Sint16 y0, |
||
59 | Uint16 Xradius, Uint16 Yradius, |
||
60 | Uint32 color) |
||
61 | { |
||
62 | Sint32 x, y; |
||
63 | Sint32 Xchange, Ychange; |
||
64 | Sint32 EllipseError; |
||
65 | Sint32 TwoASquare, TwoBSquare; |
||
66 | Sint32 StoppingX, StoppingY; |
||
67 | |||
68 | #if SDL_DRAW_BPP == 3 |
||
69 | Uint8 colorbyte0 = (Uint8) (color & 0xff); |
||
70 | Uint8 colorbyte1 = (Uint8) ((color >> 8) & 0xff); |
||
71 | Uint8 colorbyte2 = (Uint8) ((color >> 16) & 0xff); |
||
72 | #endif |
||
73 | |||
74 | TwoASquare = 2*Xradius*Xradius; |
||
75 | TwoBSquare = 2*Yradius*Yradius; |
||
76 | |||
77 | /*1st set of points*/ |
||
78 | x = Xradius-1; /*radius zero == draw nothing*/ |
||
79 | y = 0; |
||
80 | |||
81 | Xchange = Yradius*Yradius*(1-2*Xradius); |
||
82 | Ychange = Xradius*Xradius; |
||
83 | |||
84 | EllipseError = 0; |
||
85 | |||
86 | StoppingX = TwoBSquare*Xradius; |
||
87 | StoppingY = 0; |
||
88 | |||
89 | /*Plot four ellipse points by iteration*/ |
||
90 | while (StoppingX > StoppingY) { |
||
91 | |||
92 | SDL_DRAW_PUTPIXEL |
||
93 | |||
94 | ++y; |
||
95 | StoppingY += TwoASquare; |
||
96 | EllipseError += Ychange; |
||
97 | Ychange += TwoASquare; |
||
98 | if (( 2*EllipseError + Xchange) > 0) { |
||
99 | --x; |
||
100 | StoppingX -= TwoBSquare; |
||
101 | EllipseError += Xchange; |
||
102 | Xchange += TwoBSquare; |
||
103 | } |
||
104 | }/*while*/ |
||
105 | |||
106 | /*2nd set of points*/ |
||
107 | x = 0; |
||
108 | y = Yradius-1; /*radius zero == draw nothing*/ |
||
109 | Xchange = Yradius*Yradius; |
||
110 | Ychange = Xradius*Xradius*(1-2*Yradius); |
||
111 | EllipseError = 0; |
||
112 | StoppingX = 0; |
||
113 | StoppingY = TwoASquare*Yradius; |
||
114 | |||
115 | /*Plot four ellipse points by iteration*/ |
||
116 | while (StoppingX < StoppingY) { |
||
117 | |||
118 | SDL_DRAW_PUTPIXEL |
||
119 | |||
120 | ++x; |
||
121 | StoppingX += TwoBSquare; |
||
122 | EllipseError += Xchange; |
||
123 | Xchange += TwoBSquare; |
||
124 | if ((2*EllipseError + Ychange) > 0) { |
||
125 | --y; |
||
126 | StoppingY -= TwoASquare; |
||
127 | EllipseError += Ychange; |
||
128 | Ychange += TwoASquare; |
||
129 | } |
||
130 | } |
||
131 | |||
132 | }/*Draw_Ellipse*/ |
||
133 | |||
134 | |||
135 | #undef SDL_DRAW_PUTPIXEL |
||
136 | #undef SDL_DRAW_PUTPIXEL_BPP> |
||
137 |