int main() { gdImagePtr im; int white, black; char *path; im = gdImageCreateTrueColor(6, 6); white = gdImageColorAllocate(im, 255, 255, 255); black = gdImageColorAllocate(im, 0, 0, 0); gdImageFilledRectangle(im, 0,0, 5,5, white); gdImageLine(im, 4,4, 4,4, black); gdImageLine(im, 1,4, 2,4, black); gdImageLine(im, 4,1, 4,2, black); gdImageSetAntiAliased(im, black); gdImageLine(im, 1,1, 1,1, gdAntiAliased); path = gdTestFilePath2("gdimageline", "bug00315_exp.png"); gdAssertImageEqualsToFile(path, im); gdFree(path); gdImageDestroy(im); return gdNumFailures(); }
int main() { gdImagePtr im; int error = 0; char path[1024]; im = gdImageCreateTrueColor(300, 300); gdImageFilledRectangle(im, 0,0, 299,299, 0xFFFFFF); gdImageSetAntiAliased(im, 0x000000); gdImageArc(im, 300, 300, 600,600, 0, 360, gdAntiAliased); sprintf(path, "%s/gdimagearc/bug00079_exp.png", GDTEST_TOP_DIR); if (!gdAssertImageEqualsToFile(path, im)) { printf("%s failed\n", path); error = 1; } gdImageDestroy(im); return error; }
int gen_image(const char* filename, int idx, int reverse_x, int width, int height, int bgd) { double gradient = height / (width*2.0); int offset = idx*width; int x1,y1,x2,y2, error = 0; gdImagePtr im = gdImageCreateTrueColor(width,height); if (bgd==1) { gdImageFilledRectangle(im,0,0,width-1,height-1, gdTrueColorAlpha(255, 255, 255, 0)); } else { gdImageFilledRectangle(im,0,0,width-1,height-1, gdTrueColorAlpha(255, 255, 0, 0)); } gdImageSetAntiAliased(im, gdTrueColorAlpha(0,0,0,0)); /* test for potential segfault (introduced with AA improvements, fixed with the same patch - but I didn't notice it until later).*/ gdImageLine(im,-1,-1,-1,-1,gdAntiAliased); x1 = floor(reverse_x * -width + 0.5); y1 = (offset-width) * gradient + 0.5; x2 = floor(reverse_x * width*2 + 0.5); y2 = floor((offset+width*2) * gradient + 0.5); // draw an AA line gdImageLine(im, x1, y1, x2, y2, gdAntiAliased); gdImageLine(im, 0, im->sy - 1, im->sx, im->sy - 1, 0x40FF0000); if (!gdAssertImageEqualsToFile(filename, im)) { printf("%s failed\n", filename); error = 1; } gdImageDestroy(im); return error; }
static void fill_polygon(PLStream *pls) { png_Dev *dev=(png_Dev *)pls->dev; int i; gdPoint *points=NULL; if (pls->dev_npts < 1) return; points = malloc((size_t)pls->dev_npts * sizeof(gdPoint)); for (i = 0; i < pls->dev_npts; i++) { points[i].x = pls->dev_x[i]/dev->scale; points[i].y = dev->pngy - (pls->dev_y[i]/dev->scale); } #if GD2_VERS >= 2 if (dev->smooth==1) { gdImageSetAntiAliased(dev->im_out,dev->colour); gdImageFilledPolygon(dev->im_out, points, pls->dev_npts, gdAntiAliased); } else { gdImageFilledPolygon(dev->im_out, points, pls->dev_npts, dev->colour); } #else gdImageFilledPolygon(dev->im_out, points, pls->dev_npts, dev->colour); #endif free(points); }
void plD_line_png(PLStream *pls, short x1a, short y1a, short x2a, short y2a) { png_Dev *dev=(png_Dev *)pls->dev; int xx1 = x1a/dev->scale, yy1 = y1a/dev->scale; int xx2 = x2a/dev->scale, yy2 = y2a/dev->scale; yy1 = dev->pngy - yy1; yy2 = dev->pngy - yy2; #if GD2_VERS >= 2 if (dev->smooth==1) { gdImageSetAntiAliased(dev->im_out,dev->colour); gdImageLine(dev->im_out, xx1, yy1, xx2, yy2, gdAntiAliased); } else { gdImageLine(dev->im_out, xx1, yy1, xx2, yy2, dev->colour); } #else gdImageLine(dev->im_out, xx1, yy1, xx2, yy2, dev->colour); #endif }
int main (void) { #ifdef HAVE_LIBPNG /* Input and output files */ FILE *in; FILE *out; /* Input and output images */ gdImagePtr im_in = 0, im_out = 0; /* Brush image */ gdImagePtr brush; /* Color indexes */ int white; int blue; int red; int green; /* Points for polygon */ gdPoint points[3]; int i; /* Create output image, in true color. */ im_out = gdImageCreateTrueColor (256 + 384, 384); /* 2.0.2: first color allocated would automatically be background in a palette based image. Since this is a truecolor image, with an automatic background of black, we must fill it explicitly. */ white = gdImageColorAllocate (im_out, 255, 255, 255); gdImageFilledRectangle (im_out, 0, 0, gdImageSX (im_out), gdImageSY (im_out), white); /* Set transparent color. */ gdImageColorTransparent (im_out, white); /* Try to load demoin.png and paste part of it into the output image. */ in = fopen ("demoin.png", "rb"); if (!in) { fprintf (stderr, "Can't load source image; this demo\n"); fprintf (stderr, "is much more impressive if demoin.png\n"); fprintf (stderr, "is available.\n"); im_in = 0; } else { int a; im_in = gdImageCreateFromPng (in); fclose (in); /* Now copy, and magnify as we do so */ gdImageCopyResampled (im_out, im_in, 32, 32, 0, 0, 192, 192, 255, 255); /* Now display variously rotated space shuttles in a circle of our own */ for (a = 0; (a < 360); a += 45) { int cx = cos (a * .0174532925) * 128; int cy = -sin (a * .0174532925) * 128; gdImageCopyRotated (im_out, im_in, 256 + 192 + cx, 192 + cy, 0, 0, gdImageSX (im_in), gdImageSY (im_in), a); } } red = gdImageColorAllocate (im_out, 255, 0, 0); green = gdImageColorAllocate (im_out, 0, 255, 0); blue = gdImageColorAllocate (im_out, 0, 0, 255); /* Fat Rectangle */ gdImageSetThickness (im_out, 4); gdImageLine (im_out, 16, 16, 240, 16, green); gdImageLine (im_out, 240, 16, 240, 240, green); gdImageLine (im_out, 240, 240, 16, 240, green); gdImageLine (im_out, 16, 240, 16, 16, green); gdImageSetThickness (im_out, 1); /* Circle */ gdImageArc (im_out, 128, 128, 60, 20, 0, 720, blue); /* Arc */ gdImageArc (im_out, 128, 128, 40, 40, 90, 270, blue); /* Flood fill: doesn't do much on a continuously variable tone jpeg original. */ gdImageFill (im_out, 8, 8, blue); /* Polygon */ points[0].x = 64; points[0].y = 0; points[1].x = 0; points[1].y = 128; points[2].x = 128; points[2].y = 128; gdImageFilledPolygon (im_out, points, 3, green); /* 2.0.12: Antialiased Polygon */ gdImageSetAntiAliased (im_out, green); for (i = 0; (i < 3); i++) { points[i].x += 128; } gdImageFilledPolygon (im_out, points, 3, gdAntiAliased); /* Brush. A fairly wild example also involving a line style! */ if (im_in) { int style[8]; brush = gdImageCreateTrueColor (16, 16); gdImageCopyResized (brush, im_in, 0, 0, 0, 0, gdImageSX (brush), gdImageSY (brush), gdImageSX (im_in), gdImageSY (im_in)); gdImageSetBrush (im_out, brush); /* With a style, so they won't overprint each other. Normally, they would, yielding a fat-brush effect. */ style[0] = 0; style[1] = 0; style[2] = 0; style[3] = 0; style[4] = 0; style[5] = 0; style[6] = 0; style[7] = 1; gdImageSetStyle (im_out, style, 8); /* Draw the styled, brushed line */ gdImageLine (im_out, 0, 255, 255, 0, gdStyledBrushed); } /* Text (non-truetype; see gdtestft for a freetype demo) */ gdImageString (im_out, gdFontGiant, 32, 32, (unsigned char *) "hi", red); gdImageStringUp (im_out, gdFontSmall, 64, 64, (unsigned char *) "hi", red); /* Random antialiased lines; coordinates all over the image, but the output will respect a small clipping rectangle */ gdImageSetClip(im_out, 0, gdImageSY(im_out) - 100, 100, gdImageSY(im_out)); /* Fixed seed for reproducibility of results */ srand(100); for (i = 0; (i < 100); i++) { int x1 = rand() % gdImageSX(im_out); int y1 = rand() % gdImageSY(im_out); int x2 = rand() % gdImageSX(im_out); int y2 = rand() % gdImageSY(im_out); gdImageSetAntiAliased(im_out, white); gdImageLine (im_out, x1, y1, x2, y2, gdAntiAliased); } /* Make output image interlaced (progressive, in the case of JPEG) */ gdImageInterlace (im_out, 1); out = fopen ("demoout.png", "wb"); /* Write PNG */ gdImagePng (im_out, out); fclose (out); /* 2.0.12: also write a paletteized version */ out = fopen ("demooutp.png", "wb"); gdImageTrueColorToPalette (im_out, 0, 256); gdImagePng (im_out, out); fclose (out); gdImageDestroy (im_out); if (im_in) { gdImageDestroy (im_in); } #else fprintf (stderr, "No PNG library support.\n"); #endif /* HAVE_LIBPNG */ return 0; }
void Gd::setAntiAliased(int color) { gdImageSetAntiAliased(_imagePtr, color); }
int main(int argc, char *argv[]) { FILE *out; gdImage *im = NULL; int dc, bc; int c, i, arrdef[MAXAD]; int width = 0, height = 0, iwidth = 0, iheight = 0; char *file = NULL, *s; if (argc < 2) usage(argv[0]), exit(1); opterr = 0; while ((c = getopt(argc, argv, "f:h:nw:W:H:")) != -1) switch (c) { case 'f': file = optarg; break; case 'h': height = atoi(optarg); break; case 'n': windf_station_circle(0); break; case 'w': width = atoi(optarg); break; case 'H': iheight = atoi(optarg); break; case 'W': iwidth = atoi(optarg); break; } //for (; argv[optind]; optind++) fprintf(stderr, "%s,", argv[optind]); //if (!width) width = DEF_W; //if (!height) height = DEF_H; if (!iwidth) iwidth = DEF_W; if (!iheight) iheight = DEF_H; if (!width) width = iwidth; if (!height) height = iheight; if (file == NULL) out = stdout; else if ((out = fopen(file, "r")) == NULL) { if (errno != ENOENT) perror("fopen(r)"), exit(1); } else { im = gdImageCreateFromPng(out); fclose(out); } if (im == NULL) { //im = gdImageCreate(width << 1, height << 1); im = gdImageCreateTrueColor(iwidth, iheight); bc = gdImageColorAllocate(im, 255, 255, 255); gdImageColorTransparent(im, bc); gdImageFilledRectangle(im, 0, 0, iwidth, iheight, bc); } for (; argv[optind]; optind++) { memset(arrdef, -1, sizeof(arrdef)); s = strtok(argv[optind], ":"); for (i = 0; s && (i < MAXAD); i++) { if (*s == '#') { arrdef[C] = strtol(s + 1, NULL, 16); continue; } arrdef[i] = strtol(s, NULL, 0); s = strtok(NULL, ":"); } if (i < 2) fprintf(stderr, "ill wind_def\n"), exit(1); if (arrdef[CL] > 8) arrdef[CL] = 8; if (arrdef[CL] < 0) arrdef[CL] = 0; if (arrdef[X] == -1) arrdef[X] = im->sx >> 1; if (arrdef[Y] == -1) arrdef[Y] = im->sy >> 1; if (arrdef[W] == -1) arrdef[W] = width; if (arrdef[H] == -1) arrdef[H] = height; /* if (argc >= 4) { if ((out = fopen(argv[3], "w")) == NULL) perror("fopen"), exit(1); } else out = stdout; */ if (arrdef[C] == -1) arrdef[C] = 0; dc = gdImageColorAllocate(im, (arrdef[C] >> 16) & 0xff, (arrdef[C] >> 8) & 0xff, arrdef[C] & 0xff); gdImageSetAntiAliased(im, dc); windf_col(gdAntiAliased); windf_drawc0(im, arrdef[X], arrdef[Y], arrdef[W], arrdef[H], arrdef[WDIR], arrdef[WS], dc, arrdef[CL]); } if (file == NULL) out = stdout; else { if ((out = fopen(file, "w")) == NULL) perror("fopen(w)"), exit(1); } gdImagePng(im, out); gdImageDestroy(im); fclose(out); return 0; }