Anonymous avatar Anonymous committed a52c979

fixed FS#100

Comments (0)

Files changed (6)

  95, Added Netware builds script (Guenter)
  97, ease the creation of regexp to match symbols/functions in the sources 
      (Guenter)
+100, spurious horizontal line drawn by gdImageFilledPolygon (Takeshi Abe)
 101, _gdCreateFromFile() can crash if gdImageCreate fails (Mattias Bengtsson)
 105, gdImageCreateFrom*Ptr() can crash if gdNewDynamicCtxEx() fails (Mattias)
 106, gdImageRectangle draws 1x1 rectangles as 1x3 rectangles (Pierre)
   int j;
   int index;
   int y;
-  int miny, maxy;
+  int miny, maxy, pmaxy;
   int x1, y1;
   int x2, y2;
   int ind1, ind2;
 	  maxy = p[i].y;
 	}
     }
+  pmaxy = maxy;
   /* 2.0.16: Optimization by Ilia Chipitsine -- don't waste time offscreen */
   /* 2.0.26: clipping rectangle is even better */
   if (miny < im->cy1)
 	      im->polyInts[ints++] = (int) ((float) ((y - y1) * (x2 - x1)) /
 		(float) (y2 - y1) + 0.5 + x1);
 	    }
-	  else if ((y == maxy) && (y > y1) && (y <= y2))
+	  else if ((y == pmaxy) && (y == y2))
 	    {
-	      im->polyInts[ints++] = (int) ((float) ((y - y1) * (x2 - x1)) /
-		(float) (y2 - y1) + 0.5 + x1);
+	      im->polyInts[ints++] = x2;
 	    }
 	}
       /* 
         }
         im->polyInts[j] = index;
       }
-      for (i = 0; (i < (ints)); i += 2)
+      for (i = 0; (i < (ints-1)); i += 2)
 	{
           /* 2.0.29: back to gdImageLine to prevent segfaults when
             performing a pattern fill */

tests/gdimagefilledpolygon/CMakeLists.txt

 	gdimagefilledpolygon1
 	gdimagefilledpolygon2
 	gdimagefilledpolygon3
+	bug00100
 )
 
 FOREACH(test_name ${TESTS_FILES})

tests/gdimagefilledpolygon/Makefile.am

 	gdimagefilledpolygon2.c \
 	gdimagefilledpolygon2.png \
 	gdimagefilledpolygon3.c \
-	gdimagefilledpolygon3.png
+	gdimagefilledpolygon3.png \
+	bug00100.c \
+	bug00100.png

tests/gdimagefilledpolygon/bug00100.c

+#include <stdlib.h>
+#include "gd.h"
+#include "gdtest.h"
+
+/* This is a quickie test program to show a bug in gd.
+ * There is a red line that is drawn across the bottom of
+ * the image that shouldn't be there.
+ */
+int
+main(void)
+{
+  gdPoint pointy[5];
+  gdPoint diamond[4];
+  int d, x, y, top, bot, left, right, r;
+
+  //                              R    G    B
+  int white   = gdTrueColorAlpha(255, 255, 255, 10);
+  int black   = gdTrueColorAlpha(  0,   0,   0, 10);
+  int red     = gdTrueColorAlpha(255,   0,   0, 10);
+  int green   = gdTrueColorAlpha(  0, 255,   0, 10);
+  int blue    = gdTrueColorAlpha(  0,   0, 255, 10);
+  int yellow  = gdTrueColorAlpha(255, 255,   0, 10);
+  int cyan    = gdTrueColorAlpha(  0, 255, 255, 10);
+  int magenta = gdTrueColorAlpha(255,   0, 255, 10);
+  int purple  = gdTrueColorAlpha(100,   0, 100, 10);
+
+  gdImagePtr im = gdImageCreateTrueColor(256, 256);
+  if (!im) exit(EXIT_FAILURE);
+
+  gdImageFilledRectangle(im, 0, 0, 256, 256, white);
+
+  // M (bridge)
+  top = 240;
+  bot = 255;
+  d = 30;
+  x = 100;
+  pointy[0].x = x;
+  pointy[0].y = top;
+  pointy[1].x = x+2*d;
+  pointy[1].y = top;
+  pointy[2].x = x+2*d;
+  pointy[2].y = bot;
+  pointy[3].x = x+d;
+  pointy[3].y = (top+bot)/2;
+  pointy[4].x = x;
+  pointy[4].y = bot;
+  gdImageFilledPolygon(im, pointy, 5, yellow);
+
+  // left-facing M not on baseline
+  top = 40;
+  bot = 70;
+  left = 120;
+  right = 180;
+  pointy[0].x = left;
+  pointy[0].y = top;
+  pointy[1].x = right;
+  pointy[1].y = top;
+  pointy[2].x = right;
+  pointy[2].y = bot;
+  pointy[3].x = left;
+  pointy[3].y = bot;
+  pointy[4].x = (left+right)/2;
+  pointy[4].y = (top+bot)/2;
+  gdImageFilledPolygon(im, pointy, 5, purple);
+
+  // left-facing M on baseline
+  top = 240;
+  bot = 270;
+  left = 20;
+  right = 80;
+  pointy[0].x = left;
+  pointy[0].y = top;
+  pointy[1].x = right;
+  pointy[1].y = top;
+  pointy[2].x = right;
+  pointy[2].y = bot;
+  pointy[3].x = left;
+  pointy[3].y = bot;
+  pointy[4].x = (left+right)/2;
+  pointy[4].y = (top+bot)/2;
+  gdImageFilledPolygon(im, pointy, 5, magenta);
+
+  // left-facing M on ceiling
+  top = -15;
+  bot = 15;
+  left = 20;
+  right = 80;
+  pointy[0].x = left;
+  pointy[0].y = top;
+  pointy[1].x = right;
+  pointy[1].y = top;
+  pointy[2].x = right;
+  pointy[2].y = bot;
+  pointy[3].x = left;
+  pointy[3].y = bot;
+  pointy[4].x = (left+right)/2;
+  pointy[4].y = (top+bot)/2;
+  gdImageFilledPolygon(im, pointy, 5, blue);
+
+  d = 30;
+  x = 150;
+  y = 150;
+  diamond[0].x = x-d;
+  diamond[0].y = y;
+  diamond[1].x = x;
+  diamond[1].y = y+d;
+  diamond[2].x = x+d;
+  diamond[2].y = y;
+  diamond[3].x = x;
+  diamond[3].y = y-d;
+  gdImageFilledPolygon(im, diamond, 4, green);
+
+  x = 180;
+  y = 225;
+  diamond[0].x = x-d;
+  diamond[0].y = y;
+  diamond[1].x = x;
+  diamond[1].y = y+d;
+  diamond[2].x = x+d;
+  diamond[2].y = y;
+  diamond[3].x = x;
+  diamond[3].y = y-d;
+  gdImageFilledPolygon(im, diamond, 4, red);
+
+  x = 225;
+  y = 255;
+  diamond[0].x = x-d;
+  diamond[0].y = y;
+  diamond[1].x = x;
+  diamond[1].y = y+d;
+  diamond[2].x = x+d;
+  diamond[2].y = y;
+  diamond[3].x = x;
+  diamond[3].y = y-d;
+  gdImageFilledPolygon(im, diamond, 4, cyan);
+
+  // M (bridge) not touching bottom boundary
+  top = 100;
+  bot = 150;
+  x = 30;
+  pointy[0].x = x;
+  pointy[0].y = top;
+  pointy[1].x = x+2*d;
+  pointy[1].y = top;
+  pointy[2].x = x+2*d;
+  pointy[2].y = bot;
+  pointy[3].x = x+d;
+  pointy[3].y = (top+bot)/2;
+  pointy[4].x = x;
+  pointy[4].y = bot;
+  gdImageFilledPolygon(im, pointy, 5, black);
+
+  r = gdAssertImageEqualsToFile(GDTEST_TOP_DIR "/gdimagefilledpolygon/bug00100.png", im);
+  gdImageDestroy(im);
+  if (!r) exit(EXIT_FAILURE);
+  return EXIT_SUCCESS;
+}
Add a comment to this file

tests/gdimagefilledpolygon/bug00100.png

Added
New image
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.