| 1 |
void |
| 2 |
gdImageEllipse (gdImagePtr im, int cx, int cy, int w, int h, int color) |
| 3 |
{ |
| 4 |
long d, b_sq, b_sq_4, b_sq_6; |
| 5 |
long a_sq, a_sq_4, a_sq_6; |
| 6 |
int x, y, switchem; |
| 7 |
long lsqrt (long); |
| 8 |
int pix, half, pstart; |
| 9 |
int thick = im->thick; |
| 10 |
|
| 11 |
half = thick / 2; |
| 12 |
w /= 2; /* ImageArc uses diameter, not radius */ |
| 13 |
h /= 2; |
| 14 |
|
| 15 |
d = 2 * (long) h *h + (long) w *w - 2 * (long) w *w * h; |
| 16 |
b_sq = (long) h *h; |
| 17 |
b_sq_4 = 4 * (long) h *h; |
| 18 |
b_sq_6 = 6 * (long) h *h; |
| 19 |
a_sq = (long) w *w; |
| 20 |
a_sq_4 = 4 * (long) w *w; |
| 21 |
a_sq_6 = 6 * (long) w *w; |
| 22 |
|
| 23 |
x = 0; |
| 24 |
y = -h; |
| 25 |
switchem = a_sq / lsqrt (a_sq + b_sq); |
| 26 |
|
| 27 |
while (x <= switchem) |
| 28 |
{ |
| 29 |
pstart = y - half; |
| 30 |
for (pix = pstart; pix < pstart + thick; pix++) |
| 31 |
{ |
| 32 |
gdImageSetPixel (im, cx + x, cy + pix, color); |
| 33 |
gdImageSetPixel (im, cx - x, cy + pix, color); |
| 34 |
gdImageSetPixel (im, cx + x, cy - pix, color); |
| 35 |
gdImageSetPixel (im, cx - x, cy - pix, color); |
| 36 |
} |
| 37 |
if (d < 0) |
| 38 |
d += b_sq_4 * x++ + b_sq_6; |
| 39 |
else |
| 40 |
d += b_sq_4 * x++ + b_sq_6 + a_sq_4 * (++y); |
| 41 |
} |
| 42 |
|
| 43 |
/* Middlesplat! |
| 44 |
** Go a little further if the thickness is not nominal... |
| 45 |
*/ |
| 46 |
if (thick > 1) |
| 47 |
{ |
| 48 |
int xp = x; |
| 49 |
int yp = y; |
| 50 |
int dp = d; |
| 51 |
int thick2 = thick + 2; |
| 52 |
int half2 = half + 1; |
| 53 |
|
| 54 |
while (xp <= switchem + half) |
| 55 |
{ |
| 56 |
pstart = yp - half2; |
| 57 |
for (pix = pstart; pix < pstart + thick2; pix++) |
| 58 |
{ |
| 59 |
gdImageSetPixel (im, cx + xp, cy + pix, color); |
| 60 |
gdImageSetPixel (im, cx - xp, cy + pix, color); |
| 61 |
gdImageSetPixel (im, cx + xp, cy - pix, color); |
| 62 |
gdImageSetPixel (im, cx - xp, cy - pix, color); |
| 63 |
} |
| 64 |
if (dp < 0) |
| 65 |
dp += b_sq_4 * xp++ + b_sq_6; |
| 66 |
else |
| 67 |
dp += b_sq_4 * xp++ + b_sq_6 + a_sq_4 * (++yp); |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
d += -2 * (long) b_sq + 2 * (long) a_sq - 2 * (long) b_sq *(x - 1) + 2 * (long) a_sq *(y - 1); |
| 72 |
|
| 73 |
while (y <= 0) |
| 74 |
{ |
| 75 |
pstart = x - half; |
| 76 |
for (pix = pstart; pix < pstart + thick; pix++) |
| 77 |
{ |
| 78 |
gdImageSetPixel (im, cx + pix, cy + y, color); |
| 79 |
gdImageSetPixel (im, cx - pix, cy + y, color); |
| 80 |
gdImageSetPixel (im, cx + pix, cy - y, color); |
| 81 |
gdImageSetPixel (im, cx - pix, cy - y, color); |
| 82 |
} |
| 83 |
|
| 84 |
if (d < 0) |
| 85 |
d += a_sq_4 * y++ + a_sq_6 + b_sq_4 * (++x); |
| 86 |
else |
| 87 |
d += a_sq_4 * y++ + a_sq_6; |
| 88 |
} |
| 89 |
} |