]> granicus.if.org Git - php/commitdiff
MFH:
authorPierre Joye <pajoye@php.net>
Sat, 8 Feb 2003 08:54:11 +0000 (08:54 +0000)
committerPierre Joye <pajoye@php.net>
Sat, 8 Feb 2003 08:54:11 +0000 (08:54 +0000)
Add gdImageEllipse
Replace gdImageFilledEllipse by a new function (backported from
the new phpgd)
the new gdImageFilledEllipse fix bug bug #22103 (ellipse part)

ext/gd/libgd/gd.c
ext/gd/libgd/gd.h

index bdca9d26cb8743bf7bad9c64d2887007f278ef37..3292caaeb74e52a8ba23bc028365c0a34675894f 100644 (file)
@@ -1338,7 +1338,11 @@ lsqrt (long n)
 void 
 gdImageArc (gdImagePtr im, int cx, int cy, int w, int h, int s, int e, int color)
 {
-  gdImageFilledArc (im, cx, cy, w, h, s, e, color, gdNoFill);
+       if( (s%360)==(e%360) ){
+               gdImageEllipse(im, cx, cy, w, h, color);
+       } else {
+               gdImageFilledArc (im, cx, cy, w, h, s, e, color, gdNoFill);
+       }
 }
 
 void 
@@ -1424,10 +1428,102 @@ gdImageFilledArc (gdImagePtr im, int cx, int cy, int w, int h, int s, int e, int
     }
 }
 
-void 
-gdImageFilledEllipse (gdImagePtr im, int cx, int cy, int w, int h, int color)
-{
-  gdImageFilledArc (im, cx, cy, w, h, 0, 360, color, gdPie);
+/**
+ * Integer Ellipse functions (gdImageEllipse and gdImageFilledEllipse)
+ * Function added by Pierre-Alain Joye 02/08/2003 (paj@pearfr.org)
+ * 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_y1,old_y2;
+
+       a=w>>1;
+       b=h>>1;
+
+       gdImageLine(im, mx-a, my, 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;
+       old_y2=-1;
+       old_y1=-1;
+       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);
+                       }
+               }
+               if(old_y2!=my2){
+                       for(i=mx1;i<=mx2;i++){
+                               gdImageSetPixel(im,i,my2,c);
+                       }
+               }
+               old_y2 = my2;
+               old_y1 = my1;
+       }
 }
 
 void
index 74201b7fd4331aa66f0bdc957e0b834d655d9666..4c23ed13908818710c02a8577a3f7de01eaa0478 100644 (file)
@@ -411,7 +411,7 @@ void* gdImageGdPtr(gdImagePtr im, int *size);
 /* Best to free this memory with gdFree(), not free() */
 void* gdImageGd2Ptr(gdImagePtr im, int cs, int fmt, int *size);
 
-void gdImageEllipse(gdImagePtr im, int cx, int cy, int w, int h, int color);
+void gdImageEllipse(gdImagePtr im, int cx, int cy, int w, int h, int c);
 
 /* Style is a bitwise OR ( | operator ) of these.
        gdArc and gdChord are mutually exclusive;