forked from php/php-src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgd_arc.c
104 lines (91 loc) · 1.66 KB
/
gd_arc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#if HAVE_GD_BUNDLED
# include "gd.h"
#else
# include <gd.h>
#endif
#include "gd_intern.h"
/**
* Integer Ellipse functions (gdImageEllipse and gdImageFilledEllipse)
* Function added by Pierre-Alain Joye 02/08/2003 ([email protected])
* See the ellipse function simplification for the equation
* as well as the midpoint algorithm.
*/
void gdImageEllipse(gdImagePtr im, int mx, int my, int w, int h, int c)
{
int x=0,mx1=0,mx2=0,my1=0,my2=0;
long aq,bq,dx,dy,r,rx,ry,a,b;
a=w>>1;
b=h>>1;
gdImageSetPixel(im,mx+a, my, c);
gdImageSetPixel(im,mx-a, my, c);
mx1 = mx-a;my1 = my;
mx2 = mx+a;my2 = my;
aq = a * a;
bq = b * b;
dx = aq << 1;
dy = bq << 1;
r = a * bq;
rx = r << 1;
ry = 0;
x = a;
while (x > 0){
if (r > 0) {
my1++;my2--;
ry +=dx;
r -=ry;
}
if (r <= 0){
x--;
mx1++;mx2--;
rx -=dy;
r +=rx;
}
gdImageSetPixel(im,mx1, my1, c);
gdImageSetPixel(im,mx1, my2, c);
gdImageSetPixel(im,mx2, my1, c);
gdImageSetPixel(im,mx2, my2, c);
}
}
void gdImageFilledEllipse (gdImagePtr im, int mx, int my, int w, int h, int c)
{
int x=0,mx1=0,mx2=0,my1=0,my2=0;
long aq,bq,dx,dy,r,rx,ry,a,b;
int i;
int old_y2;
a=w>>1;
b=h>>1;
for (x = mx-a; x <= mx+a; x++) {
gdImageSetPixel(im, x, my, c);
}
mx1 = mx-a;my1 = my;
mx2 = mx+a;my2 = my;
aq = a * a;
bq = b * b;
dx = aq << 1;
dy = bq << 1;
r = a * bq;
rx = r << 1;
ry = 0;
x = a;
old_y2=-2;
while (x > 0){
if (r > 0) {
my1++;my2--;
ry +=dx;
r -=ry;
}
if (r <= 0){
x--;
mx1++;mx2--;
rx -=dy;
r +=rx;
}
if(old_y2!=my2){
for(i=mx1;i<=mx2;i++){
gdImageSetPixel(im,i,my1,c);
gdImageSetPixel(im,i,my2,c);
}
}
old_y2 = my2;
}
}