xref: /PHP-5.4/ext/gd/libgd/gd_arc.c (revision a008f130)
1 #if HAVE_GD_BUNDLED
2 # include "gd.h"
3 #else
4 # include <gd.h>
5 #endif
6 
7 #include "gd_intern.h"
8 
9 
10 /**
11  * Integer Ellipse functions (gdImageEllipse and gdImageFilledEllipse)
12  * Function added by Pierre-Alain Joye 02/08/2003 (paj@pearfr.org)
13  * See the ellipse function simplification for the equation
14  * as well as the midpoint algorithm.
15  */
16 
gdImageEllipse(gdImagePtr im,int mx,int my,int w,int h,int c)17 void gdImageEllipse(gdImagePtr im, int mx, int my, int w, int h, int c)
18 {
19 	int x=0,mx1=0,mx2=0,my1=0,my2=0;
20 	long aq,bq,dx,dy,r,rx,ry,a,b;
21 
22 	a=w>>1;
23 	b=h>>1;
24 	gdImageSetPixel(im,mx+a, my, c);
25 	gdImageSetPixel(im,mx-a, my, c);
26 	mx1 = mx-a;my1 = my;
27 	mx2 = mx+a;my2 = my;
28 
29 	aq = a * a;
30 	bq = b * b;
31 	dx = aq << 1;
32 	dy = bq << 1;
33 	r  = a * bq;
34 	rx = r << 1;
35 	ry = 0;
36 	x = a;
37 	while (x > 0){
38 		if (r > 0) {
39 			my1++;my2--;
40 			ry +=dx;
41 			r  -=ry;
42 		}
43 		if (r <= 0){
44 			x--;
45 			mx1++;mx2--;
46 			rx -=dy;
47 			r  +=rx;
48 		}
49 		gdImageSetPixel(im,mx1, my1, c);
50 		gdImageSetPixel(im,mx1, my2, c);
51 		gdImageSetPixel(im,mx2, my1, c);
52 		gdImageSetPixel(im,mx2, my2, c);
53 	}
54 }
55 
gdImageFilledEllipse(gdImagePtr im,int mx,int my,int w,int h,int c)56 void gdImageFilledEllipse (gdImagePtr im, int mx, int my, int w, int h, int c)
57 {
58 	int x=0,mx1=0,mx2=0,my1=0,my2=0;
59 	long aq,bq,dx,dy,r,rx,ry,a,b;
60 	int i;
61 	int old_y1,old_y2;
62 
63 	a=w>>1;
64 	b=h>>1;
65 
66 	for (x = mx-a; x <= mx+a; x++) {
67 		gdImageSetPixel(im, x, my, c);
68 	}
69 
70 	mx1 = mx-a;my1 = my;
71 	mx2 = mx+a;my2 = my;
72 
73 	aq = a * a;
74 	bq = b * b;
75 	dx = aq << 1;
76 	dy = bq << 1;
77 	r  = a * bq;
78 	rx = r << 1;
79 	ry = 0;
80 	x = a;
81 	old_y2=-2;
82 	old_y1=-2;
83 	while (x > 0){
84 		if (r > 0) {
85 			my1++;my2--;
86 			ry +=dx;
87 			r  -=ry;
88 		}
89 		if (r <= 0){
90 			x--;
91 			mx1++;mx2--;
92 			rx -=dy;
93 			r  +=rx;
94 		}
95 		if(old_y2!=my2){
96 			for(i=mx1;i<=mx2;i++){
97 				gdImageSetPixel(im,i,my1,c);
98 			}
99 		}
100 		if(old_y2!=my2){
101 			for(i=mx1;i<=mx2;i++){
102 				gdImageSetPixel(im,i,my2,c);
103 			}
104 		}
105 		old_y2 = my2;
106 		old_y1 = my1;
107 	}
108 }
109 
110 
111