int main(int argc, char **argv) { gdImagePtr A, B, C; unsigned char black, white; unsigned int minSX, minSY, maxSX, maxSY; bool rc; #ifdef HAVE_GD_PNG FILE *f; #endif if (argc < 3) { fprintf(stderr, "Usage: diffimg image1 image2 [outimage]\n"); exit(EX_USAGE); } A = imageLoad(argv[1]); B = imageLoad(argv[2]); minSX = (gdImageSX(A) < gdImageSX(B)) ? gdImageSX(A) : gdImageSX(B); minSY = (gdImageSY(A) < gdImageSY(B)) ? gdImageSY(A) : gdImageSY(B); maxSX = (gdImageSX(A) > gdImageSX(B)) ? gdImageSX(A) : gdImageSX(B); maxSY = (gdImageSY(A) > gdImageSY(B)) ? gdImageSY(A) : gdImageSY(B); C = gdImageCreatePalette (maxSX, maxSY); white = gdImageColorAllocate(C, gdRedMax, gdGreenMax, gdBlueMax); black = gdImageColorAllocate(C, 0, 0, 0); if (maxSX > minSX && maxSY > minSY) gdImageFilledRectangle(C, minSX, minSY, maxSX-1, maxSY-1, black); rc = imageDiff (A, B, C, minSX, minSY, black, white); #ifdef HAVE_GD_PNG if ((argc > 3) && ((f = fopen(argv[3], "wb")))) { gdImagePng (C, f); fclose(f); } else gdImagePng (C, stdout); #else fprintf(stderr, "PNG output support is not available\n"); #endif gdImageDestroy(A); gdImageDestroy(B); gdImageDestroy(C); return (rc ? EXIT_FAILURE : EXIT_SUCCESS); }
void after_nodes() { gdImagePtr im = gdImageCreate(m_xsize, m_ysize); for (int i=0; i <= 255; ++i) { gdImageColorAllocate(im, i, i, i); } int n=0; for (int y=0; y < m_ysize; ++y) { for (int x=0; x < m_xsize; ++x) { int val = in_range(m_min, m_node_count[n], m_max); ++n; gdImageSetPixel(im, x, y, static_cast<uint8_t>((val - m_min) * 255 / m_diff)); } } FILE* out = fopen("node_density.png", "wb"); if (!out) { std::cerr << "Can't open file 'node_density.png': " << strerror(errno) << std::endl; } gdImagePng(im, out); fclose(out); gdImageDestroy(im); }
/* saves the data stored in the image_data array of given width and height into an output .png file returns: 0 on success 1 otherwise */ int save_image_data(char *file_name, color_t *imageData, int width, int height) { gdImagePtr img = gdImageCreateTrueColor(width, height); unsigned x, y; for(y = 0; y < height; ++y) { for(x = 0; x < width; ++x) { int index = y*width + x; int gd_color = gdImageColorAllocate(img, imageData[index].r, imageData[index].g, imageData[index].b); gdImageSetPixel(img, x, y, gd_color); } } FILE *img_file = fopen(file_name, "w+"); if (img_file == NULL) { gdImageDestroy(img); perror("error opening file"); return 1; } gdImagePng(img, img_file); gdImageDestroy(img); if (fclose(img_file)) { perror("error closing file"); return 1; } return 0; }
static void writePng(char *filename, wlImage pic) { gdImagePtr output; int x, y, i; int palette[16]; FILE *file; output = gdImageCreate(pic->width, pic->height); for (i = 0; i < 16; i++) { palette[i] = gdImageColorAllocate(output, wlPalette[i].red, wlPalette[i].green, wlPalette[i].blue); } for (y = 0; y < pic->height; y++) { for (x = 0; x < pic->width; x++) { gdImageSetPixel(output, x, y, palette[pic->pixels[y * pic->width + x]]); } } file = fopen(filename, "wb"); if (!file) { die("Unable to write PNG to %s: %s\n", filename, strerror(errno)); } gdImagePng(output, file); gdImageDestroy(output); fclose(file); }
PngSurface::~PngSurface() { gdImagePtr im; FILE* out; im = gdImageCreateTrueColor(width(), height()); if (!(out = fopen(m_fname.c_str(), "wb"))) { std::cerr << "Unable to open/create file " << m_fname << std::endl; return; } for (int h = 0; h < m_height; ++h) { for (int w = 0; w < m_width; ++w) { gdImageSetPixel(im, w, h, data[h][w]); } } gdImagePng(im, out); fclose(out); gdImageDestroy(im); for (int i = 0; i < m_height; ++i) { delete[] data[i]; data[i] = NULL; } delete[] data; data = NULL; }
void dotest (char *font, int w, int h, char *string, const char *filename) { gdImagePtr im; FILE *out; int bg; int fc; im = gdImageCreate (w, h); bg = gdImageColorAllocate (im, 0, 0, 0); gdImageFilledRectangle (im, 1, 1, w - 1, h - 1, bg); fc = gdImageColorAllocate (im, 255, 192, 192); out = fopen (filename, "wb"); dosizes (im, fc, font, 20, 20, string); #if defined(HAVE_LIBPNG) gdImagePng (im, out); #elif defined(HAVE_LIBJPEG) gdImageJpeg (im, out, -1); #endif fclose (out); }
value ImagePng(value img,value filename) { ImageData _img = getImage(img); FILE *_file = openFileWrite(filename); gdImagePng(imageImage(_img),_file); fclose(_file); return val_null; }
int main() { gdImagePtr im; FILE *fp; int cor_rad = 60; im = gdImageCreateTrueColor(400, 400); gdImageFilledRectangle(im, 0, 0, 399, 399, 0x00FFFFFF); gdImageFilledArc (im, cor_rad, 399 - cor_rad, cor_rad *2, cor_rad *2, 90, 180, 0x0, gdPie); fp = fopen("b.png", "wb"); if (!fp) { fprintf(stderr, "Can't save png image.\n"); gdImageDestroy(im); return 1; } #ifdef HAVE_LIBPNG gdImagePng(im, fp); #else printf("No PNG support. Cannot save image.\n"); #endif fclose(fp); gdImageDestroy(im); return 0; }
int main(void) { /* 2.0.22: can't depend on PNG either */ #ifndef HAVE_LIBPNG fprintf(stderr, "Requires PNG support, gd was compiled without it\n"); return 0; #else char *error; FILE *in = 0; FILE *out; gdImagePtr im; int radius; /* Create an image of text on a circle, with an * alpha channel so that we can copy it onto a * background * TBB: 2.0.18: shouldn't depend on JPEG */ #ifdef HAVE_LIBJPEG in = fopen("eleanor.jpg", "rb"); if(!in) { im = gdImageCreateTrueColor(300, 300); } else { im = gdImageCreateFromJpeg(in); fclose(in); } #else im = gdImageCreateTrueColor(300, 300); #endif /* HAVE_LIBJPEG */ if(!im) { fprintf(stderr, "gdImageCreateTrueColor failed \n"); return 1; } if(gdImageSX(im) < gdImageSY(im)) { radius = gdImageSX(im) / 2; } else { radius = gdImageSY(im) / 2; } error = gdImageStringFTCircle(im, gdImageSX(im) / 2, gdImageSY(im) / 2, radius, radius / 2, 0.8, "arial", 24, "top text", "bottom text", gdTrueColorAlpha(192, 100, 255, 32) ); if(error) { fprintf(stderr, "gdImageStringFTEx error: %s\n", error); } out = fopen("gdfx.png", "wb"); if(!out) { fprintf(stderr, "Can't create gdfx.png\n"); return 1; } gdImagePng(im, out); fclose(out); gdImageDestroy(im); #endif /* HAVE_LIBPNG */ return 0; }
static void gd_end_graph_to_file(void) { /* * Windows will do \n -> \r\n translations on stdout unless told otherwise. */ #ifdef HAVE_SETMODE #ifdef O_BINARY setmode(fileno(Output_file), O_BINARY); #endif #endif /* * Write IM to OUTFILE as a JFIF-formatted JPEG image, using quality * JPEG_QUALITY. If JPEG_QUALITY is in the range 0-100, increasing values * represent higher quality but also larger image size. If JPEG_QUALITY is * negative, the IJG JPEG library's default quality is used (which * should be near optimal for many applications). See the IJG JPEG * library documentation for more details. */ #define JPEG_QUALITY -1 if (Output_lang == GD) { gdImageGd(im, Output_file); #ifdef HAVE_LIBZ } else if (Output_lang == GD2) { #define GD2_CHUNKSIZE 128 #define GD2_RAW 1 #define GD2_COMPRESSED 2 gdImageGd2(im, Output_file, GD2_CHUNKSIZE, GD2_COMPRESSED); #endif #ifdef WITH_GIF } else if (Output_lang == GIF) { gdImageGif(im, Output_file); #endif #ifdef HAVE_LIBPNG #ifdef HAVE_LIBZ } else if (Output_lang == PNG) { gdImagePng(im, Output_file); #endif #endif #ifdef HAVE_LIBJPEG } else if (Output_lang == JPEG) { gdImageJpeg(im, Output_file, JPEG_QUALITY); #endif } else if (Output_lang == WBMP) { /* Use black for the foreground color for the B&W wbmp image. */ gdImageWBMP(im, black, Output_file); #ifdef HAVE_LIBXPM } else if (Output_lang == XBM) { gdImageXbm(im, Output_file); #endif } if (ImageDict) { dtclose(ImageDict); ImageDict = 0; } gdImageDestroy(im); #ifdef MYTRACE fprintf(stderr,"gd_end_graph_to_file\n"); #endif }
int main(int argc, char **argv) { gdImagePtr im; FILE *in, *out; if (argc != 3) { fprintf(stderr, "Usage: gd2topng filename.gd2 filename.png\n"); exit(1); } in = fopen(argv[1], "rb"); if (!in) { fprintf(stderr, "Input file does not exist!\n"); exit(1); } im = gdImageCreateFromGd2(in); fclose(in); if (!im) { fprintf(stderr, "Input is not in GD2 format!\n"); exit(1); } out = fopen(argv[2], "wb"); if (!out) { fprintf(stderr, "Output file cannot be written to!\n"); gdImageDestroy(im); exit(1); } gdImagePng(im, out); fclose(out); gdImageDestroy(im); return 0; }
int main(int argc, char *argv[]) { FILE *pngout = {0}; gdImagePtr img; int fgcol, bgcol; char *str = NULL; char *fname = NULL; if(argc != 5) { fprintf(stderr, "Usage: ./imstr \"STRING\" FFFFFF 000000 image.png\n"); return 1; } else { str = argv[1]; img = gdImageCreate((gdFontGiant->w * strlen(str)) + 2, gdFontGiant->h + 2); setupcolor(argv[2]); bgcol = gdImageColorAllocate(img, red, green, blue); setupcolor(argv[3]); fgcol = gdImageColorAllocate(img, red, green, blue); fname = argv[4]; } gdImageString(img, gdFontGiant, gdImageSX(img) / 2 - (strlen(str) * gdFontGiant->w / 2), gdImageSY(img) / 2 - gdFontGiant->h / 2, str, fgcol); if((pngout = fopen(fname, "w")) == NULL) error(1, 0, "Error - fopen(): %s", fname); else { gdImagePng(img, pngout); fclose(pngout); } gdImageDestroy(img); return 0; }
void sendImage() { gdImagePtr image; image = gdImageCreate(88, 31); int background = gdImageColorAllocate(image, 0xFF, 0xFF, 0xFF); fputs("Content-Type: image/png\n\n", stdout); gdImagePng(image, stdout); gdImageDestroy(image); }
int main(int argc, char *argv[]) { #ifndef HAVE_LIBTTF fprintf(stderr, "gd was not compiled with HAVE_LIBTTF defined.\n"); fprintf(stderr, "Install the FreeType library, including the\n"); fprintf(stderr, "header files. Then edit the gd Makefile, type\n"); fprintf(stderr, "make clean, and type make again.\n"); return 1; #else gdImagePtr im; int black; int white; int brect[8]; int x, y; char *err; #ifdef JISX0208 char *s = "Hello. こんにちは Qyjpqg,"; /* String to draw. */ #else char *s = "Hello. Qyjpqg,"; /* String to draw. */ #endif double sz = 40.; double angle = DEG2RAD(-90); #ifdef JISX0208 char *f = "/usr/openwin/lib/locale/ja/X11/fonts/TT/HG-MinchoL.ttf"; /* UNICODE */ /* char *f = "/usr/local/lib/fonts/truetype/DynaFont/dfpop1.ttf"; */ /* SJIS */ #else char *f = "/usr/local/lib/fonts/truetype/misc/times.ttf"; /* TrueType font */ #endif /* obtain brect so that we can size the image */ err = gdImageStringTTF((gdImagePtr)NULL,&brect[0],0,f,sz,angle,0,0,s); if (err) {fprintf(stderr,err); return 1;} /* create an image just big enough for the string */ x = MAXX(brect) - MINX(brect) + 6; y = MAXY(brect) - MINY(brect) + 6; im = gdImageCreate(x,y); /* Background color (first allocated) */ white = gdImageColorResolve(im, 255, 255, 255); black = gdImageColorResolve(im, 0, 0, 0); /* render the string, offset origin to center string*/ x = 0 - MINX(brect) + 3; y = 0 - MINY(brect) + 3; err = gdImageStringTTF(im,&brect[0],black,f,sz,angle,x,y,s); if (err) {fprintf(stderr,err); return 1;} /* Write img to stdout */ gdImagePng(im, stdout); /* Destroy it */ gdImageDestroy(im); return 0; #endif /* HAVE_TTF */ }
int main (int argc, char **argv) { gdImagePtr im; FILE *in, *out; int x, y, w, h; if ((argc != 3) && (argc != 7)) { fprintf (stderr, "Usage: gd2topng filename.gd2 filename.png [srcx srcy width height]\n"); fprintf (stderr, "If the coordinates are absent,t he entire image is converted.\n"); exit (1); } if (argc == 7) { x = atoi (argv[3]); y = atoi (argv[4]); w = atoi (argv[5]); h = atoi (argv[6]); } in = fopen (argv[1], "rb"); if (!in) { fprintf (stderr, "Input file does not exist!\n"); exit (1); } if (argc == 7) { im = gdImageCreateFromGd2Part (in, x, y, w, h); } else { im = gdImageCreateFromGd2 (in); } fclose (in); if (!im) { fprintf (stderr, "Input is not in GD2 format!\n"); exit (1); } out = fopen (argv[2], "wb"); if (!out) { fprintf (stderr, "Output file cannot be written to!\n"); gdImageDestroy (im); exit (1); } #ifdef HAVE_LIBPNG gdImagePng (im, out); #else fprintf (stderr, "No PNG library support available.\n"); #endif fclose (out); gdImageDestroy (im); return 0; }
static void vrml_end_node(GVJ_t *job) { if (im) { gdImagePng(im, PNGfile); fclose(PNGfile); gdImageDestroy(im); im = NULL; } }
int write_image(gdImagePtr image, char *filename) { FILE *out = fopen(filename, "wb"); if (!out) { return 0; } gdImagePng(image, out); fclose(out); return 1; }
/* If palette is true, we convert from truecolor to palette at the end, to test gdImageTrueColorToPalette and see file size/ quality tradeoffs. */ void testDrawing (gdImagePtr im_in, double scale, int blending, int palette, char *filename) { gdImagePtr im_out; FILE *out; /* Create output image. */ im_out = gdImageCreateTrueColor ((int) (gdImageSX (im_in) * scale), (int) (gdImageSY (im_in) * scale)); /* Request alpha blending. This causes future drawing operations to perform alpha channel blending with the background, resulting in an opaque image. Without this call, pixels in the foreground color are copied literally, *including* the alpha channel value, resulting in an output image which is potentially not opaque. This flag can be set and cleared as often as desired. */ gdImageAlphaBlending (im_out, blending); /* Flood with light blue. */ gdImageFill (im_out, (int) (gdImageSX (im_in) * scale / 2), (int) (gdImageSY (im_in) * scale / 2), gdTrueColor (192, 192, 255)); /* Copy the source image. Alpha blending should result in compositing against red. With blending turned off, the browser or viewer will composite against its preferred background, or, if it does not support an alpha channel, we will see the original colors for the pixels that ought to be transparent or semitransparent. */ gdImageCopyResampled (im_out, im_in, 0, 0, 0, 0, (int) (gdImageSX (im_in) * scale), (int) (gdImageSY (im_in) * scale), gdImageSX (im_in), gdImageSY (im_in)); /* Write PNG */ out = fopen (filename, "wb"); /* If this image is the result of alpha channel blending, it will not contain an interesting alpha channel itself. Save a little file size by not saving the alpha channel. Otherwise the file would typically be slightly larger. */ gdImageSaveAlpha (im_out, !blending); /* If requested, convert from truecolor to palette. */ if (palette) { /* Dithering, 256 colors. */ gdImageTrueColorToPalette (im_out, 1, 256); } gdImagePng (im_out, out); fclose (out); gdImageDestroy (im_out); }
/* Safe the image */ void flush_viewport_png(png_t* handle, button_event_t* position) { /* Safe the image. */ gdImagePng(handle->im,handle->output_file); /* Call the main function that the programm is over. */ position->type=autozoom_quit; return; }
void Ebalda::Draw(const char *outfile) { gdImagePtr im; FILE *pngout; int black, white; char buf[512]; snprintf(buf, 512, "%s Age: %d Size %d x %d", name, step, endcol - startcol + 1, endrow - startrow + 1); im = gdImageCreateTrueColor((width + 1) * DOT_SIZE, (height + 1) * DOT_SIZE + 20); white = gdImageColorAllocate(im, 255, 255, 255); // first allocated color is background black = gdImageColorAllocate(im, 0, 0, 0); int brect[8]; gdImageStringFT(im, brect, white, (char *)FONT_FILE, 11.0, 0.0, /*x*/5, /*y*/(height + 1) * DOT_SIZE + 10, buf); for(int row = startrow; row <= endrow; row++) { for(int col = startcol; col <= endcol; col++) { int color; int c = ebalda_himself[ (width + 2) * row + col ] - 'A'; if (row == headrow && col == headcol) color = gdImageColorAllocate(im, 255, 0, 0); else color = gdImageColorAllocate(im, 250 - c * 25, 250 - c * 25, 250 - c * 25); gdImageFilledRectangle(im, (col - startcol) * DOT_SIZE, (row - startrow) * DOT_SIZE, (col - startcol) * DOT_SIZE + DOT_SIZE - 1, (row - startrow) * DOT_SIZE + DOT_SIZE - 1, color); } } pngout = fopen(outfile, "wb"); gdImagePng(im, pngout); fclose(pngout); if (step % SCREENSHOT_EACH == 0) { snprintf(buf, 512, "%s/%08d.png", SCREENSHOT_DIR, step); pngout = fopen(buf, "wb"); gdImagePng(im, pngout); fclose(pngout); } gdImageDestroy(im); }
static void TermImage(gdImagePtr im) { DrawTickLines(im); imgheader(); #ifdef SYS_IMGFMT_PNG gdImagePng (im, stdout); #else gdImageGif (im, stdout); #endif gdImageDestroy (im); }
void save_png(gdImagePtr im, const char *filename) { FILE *fp; fp = fopen(filename, "wb"); if (!fp) { fprintf(stderr, "Can't save png image %s\n", filename); return; } gdImagePng(im, fp); fclose(fp); }
int main() { /* Declare the image */ gdImagePtr im; /* Declare output files */ FILE *pngout, *jpegout; /* Declare color indexes */ int black; int white; int cyan; int orange; /* Allocate the image: 64 pixels across by 64 pixels tall */ im = gdImageCreate(64, 64); /* Allocate the color black (red, green and blue all minimum). Since this is the first color in a new image, it will be the background color. */ black = gdImageColorAllocate(im, 0, 0, 0); /* Allocate the color white (red, green and blue all maximum). */ white = gdImageColorAllocate(im, 255, 255, 255); /* Allocate the color cyan and orange. */ cyan = gdImageColorAllocate(im, 0, 192, 255); orange = gdImageColorAllocate(im, 255, 128, 0); /* Draw a line from the upper left to the lower right, using white color index. */ gdImageLine(im, 0, 0, 63, 63, white); gdImageLine(im, 15, 0, 15, 63, cyan); gdImageLine(im, 31, 0, 31, 63, orange); /* Open a file for writing. "wb" means "write binary", important under MSDOS, harmless under Unix. */ pngout = fopen("test.png", "wb"); /* Do the same for a JPEG-format file. */ jpegout = fopen("test.jpg", "wb"); /* Output the image to the disk file in PNG format. */ gdImagePng(im, pngout); /* Output the same image in JPEG format, using the default JPEG quality setting. */ gdImageJpeg(im, jpegout, -1); /* Close the files. */ fclose(pngout); fclose(jpegout); /* Destroy the image in memory. */ gdImageDestroy(im); return(0); }
void piechart_write(FILE *pieoutf, char *filename, logical jpegcharts) { #ifdef HAVE_GD if (jpegcharts) gdImageJpeg(im, pieoutf, 100); else #endif gdImagePng(im, pieoutf); debug('F', "Closing %s", filename); fclose(pieoutf); gdImageDestroy(im); }
void MessageEncryption::encrypt(std::string imgpath,std::string outpath){ std::default_random_engine rand (this->key); int currand; int i, j; int width, height; FILE* in, *out; gdImagePtr img; printf("o\n"); int ext = getexten(imgpath); printf("a\n"); in = fopen(imgpath.c_str(),"rb"); if(ext==0){ img=gdImageCreateFromJpeg(in); } else if(ext==1){ img=gdImageCreateFromPng(in); } else{ exit(1); } fclose(in); printf("b\n"); width = gdImageSX(img); height = gdImageSY(img); for(i=0;i<ITER_COUNT;i++){ currand = rand()%FLIP_CHANCE; if(currand==0){ // flip horizontally fliphoriz(img); } else if(currand==1){ // flip vertically flipvert(img); } else if(currand<=1+FLIP_CHANCE/2){ // shift some rows for(j=0;j<=(currand%(width/3));j++){ shiftcol(img,(3*i+j)%width,(7*currand+4*i)%height); } } else{ // shift some columns for(j=0;j<=(currand%(height/3));j++){ shiftrow(img,(3*i+j)%height,(7*currand+4*i)%width); } } } printf("c\n"); ext = getexten(outpath); out = fopen(outpath.c_str(),"wb"); if(ext==0){ gdImageJpeg(img,out,-1); } else if(ext==1){ gdImagePng(img,out); } else{ exit(1); } fclose(out); gdImageDestroy(img); }
int filetopng(FILE *fin, FILE *fout, int im_w, char *banner) { struct stat fin_stat; gdImagePtr im = NULL; fstat(fileno(fin), &fin_stat); long data_size = fin_stat.st_size; int im_w_bytes = im_w * 3; int im_h = ((data_size + im_w_bytes - 1) / im_w_bytes) + BANNER_HEIGHT; /* ceil((float)data_size / im_w_bytes) + BANNER_HEIGHT */ im = gdImageCreateTrueColor(im_w, im_h); unsigned char buf[3]; long bytes_read = 0; long total_bytes = 0; int x = 0; int y = 0; while((bytes_read = fread(buf, 1, 3, fin)) > 0) { total_bytes += bytes_read; gdImageSetPixel(im, x, y, gdImageColorAllocate(im, buf[0], buf[1], buf[2])); if(x + 1 < im_w) { x++; } else { x = 0; y++; } } gdImageFilledRectangle(im, 0, gdImageSY(im) - BANNER_HEIGHT, im_w - 1, gdImageSY(im) + BANNER_HEIGHT, gdImageColorAllocate(im, 255, 255, 255)); gdImageString(im, (gdFontPtr) gdFontGetTiny(), 5, gdImageSY(im) - BANNER_HEIGHT, (unsigned char *)banner, gdImageColorAllocate(im, 0, 0, 0)); /* store data_size at last pixel */ gdImageSetPixel(im, gdImageSX(im) - 1, gdImageSY(im) - 1, gdImageColorAllocate(im, (data_size & 0xff0000) >> 8*2, (data_size & 0xff00) >> 8*1, data_size & 0xff)); if(verbose) fprintf(stderr, "Width: %d\nHeight: %d\n", im_w, im_h); gdImagePng(im, fout); /* int c = gdImageGetPixel(im, gdImageSX(im) - 1, gdImageSY(im) - 1); int ds = (gdImageRed(im, c) << 8*2) + (gdImageGreen(im, c) << 8*1) + (gdImageBlue(im, c)); printf("debug: ds %d, data_size %d\n", ds, data_size); //printf("c: %d %d %d\n", (data_size & 0xff0000) >> 8*2, (data_size & 0xff00) >> 8*1, data_size & 0xff); //printf("d: %d %d %d\n", (gdImageRed(im, c) << 8*2), (gdImageGreen(im, c) << 8*1), (gdImageBlue(im, c))); */ gdImageDestroy(im); return 1; }
int main( int argc, char* argv[] ) { JBMaze* maze; gdImagePtr image; JBMazePt* path; int len; PARMOPTS opts; memset( &opts, 0, sizeof( opts ) ); parseArgs( argc, argv, &opts); fprintf( stderr, "current seed: %ld\n", opts.seed ); /* construct the maze */ maze = new JBMaze( opts.width, opts.height, opts.depth, opts.seed, opts.randomness, opts.startx, opts.starty, opts.startz, opts.endx, opts.endy, opts.endz ); /* load the mask */ if( opts.maskFile[0] != 0 ) { maze->setMask( new JBMazeMask( opts.maskFile ) ); } /* generate it */ maze->generate(); /* solve it */ maze->solve( &path, &len ); /* sparsify it */ maze->sparsify( opts.sparseness ); /* clear up the deadends by reconnecting them into an existing passage */ maze->clearDeadends( opts.deadends ); /* draw it */ drawAsStructure( &image, maze, path, len, &opts ); free( path ); gdImagePng( image, stdout ); gdImageDestroy( image ); delete maze; return 0; }
/* ------------------------------------------------------------------------ */ void out_err( int IMGWIDTH, int IMGHEIGHT, FILE *fptr, unsigned long BGColor, unsigned long LineColor, char *err_str ) { gdImagePtr im; int lineclr; int bgclr; if( (GDC_hold_img & GDC_REUSE_IMAGE) && GDC_image != (void*)NULL ) im = GDC_image; else im = gdImageCreate( IMGWIDTH, IMGHEIGHT ); bgclr = gdImageColorAllocate( im, l2gdcal(BGColor) ); lineclr = gdImageColorAllocate( im, l2gdcal(LineColor) ); gdImageString( im, gdFontMediumBold, IMGWIDTH/2 - GDC_fontc[GDC_MEDBOLD].w*strlen(err_str)/2, IMGHEIGHT/3, (unsigned char*)err_str, lineclr ); /* usually GDC_generate_img is used in conjunction with hard or hold options */ if( GDC_generate_img ) { fflush(fptr); /* clear anything buffered */ switch( GDC_image_type ) { #ifdef HAVE_JPEG case GDC_JPEG: gdImageJpeg( im, fptr, GDC_jpeg_quality ); break; #endif case GDC_WBMP: gdImageWBMP( im, lineclr, fptr ); break; case GDC_GIF: gdImageGif( im, fptr); break; case GDC_PNG: default: gdImagePng( im, fptr ); } } if( GDC_hold_img & GDC_EXPOSE_IMAGE ) GDC_image = (void*)im; else gdImageDestroy(im); return; }
int main (int argc, char **argv) { gdImagePtr im; FILE *in, *out; int x, y, w, h; if (argc != 7) { fprintf (stderr, "Usage: gdparttopng filename.gd filename.png x y w h\n"); exit (1); } in = fopen (argv[1], "rb"); if (!in) { fprintf (stderr, "Input file does not exist!\n"); exit (1); } x = atoi (argv[3]); y = atoi (argv[4]); w = atoi (argv[5]); h = atoi (argv[6]); printf ("Extracting from (%d, %d), size is %dx%d\n", x, y, w, h); im = gdImageCreateFromGd2Part (in, x, y, w, h); fclose (in); if (!im) { fprintf (stderr, "Input is not in PNG format!\n"); exit (1); } out = fopen (argv[2], "wb"); if (!out) { fprintf (stderr, "Output file cannot be written to!\n"); gdImageDestroy (im); exit (1); } #ifdef HAVE_LIBPNG gdImagePng (im, out); #else fprintf (stderr, "No PNG library support.\n"); #endif fclose (out); gdImageDestroy (im); return 0; }
void save_png(gdImagePtr im, const char *filename) { FILE *fp; fp = fopen(filename, "wb"); if (!fp) { fprintf(stderr, "Can't save png image %s\n", filename); return; } #ifdef HAVE_LIBPNG gdImagePng(im, fp); #else printf("No PNG support. Cannot save image.\n"); #endif fclose(fp); }