Example #1
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;
}
Example #2
0
void makeMeme(char *input, char *output, char *text)
{
    FILE *in, *out;
    gdImagePtr im;
    int black;
    int white;
    in = fopen(input, "r");
   // if (in == NULL) return 1;

    //im = gdImageCreateFromPng(in);
    im = gdImageCreateFromJpeg(in);
    fclose(in);

    black = gdImageColorAllocate(im, 0, 0, 0);
    white = gdImageColorAllocate(im, 255, 255, 255);

    gdImageString(im, gdFontGetLarge(),
                  im->sx / 2 - (strlen(text) * gdFontGetLarge()->w / 2),
                  im->sy - im->sy / 10,
                  text, black);

    //gdImagePng(im, out);
    out = fopen(output, "w");
//    printf("Meme created!\n");
    gdImageJpeg(im, out, 95);
    gdImageDestroy(im);
    //if (out == NULL) return 1;
    fclose(out);
    //return 0;
}
Example #3
0
int main()
{
	gdImagePtr im, tile;
	int tile_red, tile_blue;
	int error = 0;
	char path[1024];
	
	im = gdImageCreate(200, 150);

	tile = gdImageCreateTrueColor(2, 2);
	
	tile_red = gdImageColorAllocate(tile, 255, 0, 0);
	tile_blue = gdImageColorAllocate(tile, 0, 0, 255);
	
	gdImageSetPixel(tile, 0, 0, tile_red);
	gdImageSetPixel(tile, 1, 1, tile_red);
	gdImageSetPixel(tile, 1, 0, tile_blue);
	gdImageSetPixel(tile, 0, 1, tile_blue);
	
	gdImageSetTile(im, tile);
	gdImageFill(im, 11, 12, gdTiled);

	sprintf(path, "%s/gdimagefill/bug00104_1_exp.png", GDTEST_TOP_DIR);
	if (!gdAssertImageEqualsToFile(path, im)) {
		error = 1;
	}
	
	gdImageDestroy(im);
	gdImageDestroy(tile);
	return error;
}
Example #4
0
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);
}
Example #5
0
int
main(void)
{
	gdImagePtr im;
	int white, black, r;
	gdPointPtr points;

	im = gdImageCreate(100, 100);
	if (!im) exit(EXIT_FAILURE);
	white = gdImageColorAllocate(im, 0xff, 0xff, 0xff);
	black = gdImageColorAllocate(im, 0, 0, 0);
	gdImageFilledRectangle(im, 0, 0, 99, 99, white);
	points = (gdPointPtr)gdCalloc(3, sizeof(gdPoint));
	if (!points) {
		gdImageDestroy(im);
		exit(EXIT_FAILURE);
	}
	points[0].x = 10;
	points[0].y = 10;
	points[1].x = 50;
	points[1].y = 70;
	points[2].x = 90;
	points[2].y = 30;
	gdImageOpenPolygon(im, points, 3, black);
	r = gdAssertImageEqualsToFile(GDTEST_TOP_DIR "/gdimageopenpolygon/gdimageopenpolygon3.png", im);
	gdFree(points);
	gdImageDestroy(im);
	if (!r) exit(EXIT_FAILURE);
	return EXIT_SUCCESS;
}
Example #6
0
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();
}
Example #7
0
gdImagePtr ca_make_gif(CA *ca_ptr, int generations, 
                    int br, int bg, int bb,   
                    int wr, int wg, int wb )  {      
    gdImagePtr img;
    int black, white;
    int gen;
    int cell;

    img = gdImageCreate(ca_ptr->width, generations);
    if (!img) {
        fprintf(stderr,"Can't allocate image!\n");
        exit(1);
    }

    black = gdImageColorAllocate(img, br, bg, bb);
    white = gdImageColorAllocate(img, wr, wg, wb);

    for(gen=0; gen < generations; gen++) {
        for(cell=0; cell < ca_ptr->width; cell++) {
            gdImageSetPixel(img, cell, gen, 
                            *(ca_ptr->c_row + cell) ? white : black);
        }
        ca_gen_next_row(ca_ptr);
    }
    return img;    
}
Example #8
0
int main()
{
	gdImagePtr im;
	int black;
	FILE *outFile;
	gdIOCtx *out;
	off_t length;

	/* create the test image */
	im = gdImageCreate(11, 11);
	gdImageColorAllocate(im, 255, 255, 255);
	black = gdImageColorAllocate(im, 0, 0, 0);
	gdImageArc(im, 5, 5, 10, 10, 0, 360, black);

	/* write the file to disk, note the file length and delete the file */
	outFile = gdTestTempFp();
	out = gdNewFileCtx(outFile);
	gdTestAssert(out != NULL);
	gdImageXbmCtx(im, "github_bug_170.xbm", 1, out);
	out->gd_free(out);
	length = ftello(outFile);
	fclose(outFile);

	gdImageDestroy(im);

	gdTestAssertMsg(length == 250, "expected to write 250 bytes; %jd bytes written", (intmax_t) length);
	return gdNumFailures();
}
Example #9
0
File: charts.c Project: fm4dd/edacs
/* -------------------------------------------------------------------- */
void init_monthgraph(char *title) {
   int i  = 0;
   int xsize = 670;
   int ysize = 160;

   imgbuf_mon = gdImageCreate(xsize,ysize);

   /* allocate color maps, background color first (grey) */
   grey    = gdImageColorAllocate(imgbuf_mon, 204, 204, 204);
   dkblue  = gdImageColorAllocate(imgbuf_mon, 0, 0, 153);
   white   = gdImageColorAllocate(imgbuf_mon, 255, 255, 255);
   dkgrey  = gdImageColorAllocate(imgbuf_mon, 128, 128, 128);
   black   = gdImageColorAllocate(imgbuf_mon, 0, 0, 0);

   /* makes shadow effect around the image, 2 pixels wide */
   for (i=0; i<2 ;i++) { /* do shadow effect around the image, 2 pixels wide */
      gdImageLine(imgbuf_mon, i, i, xsize-i, i, white);
      gdImageLine(imgbuf_mon, i, i, i, ysize-i, white);
      gdImageLine(imgbuf_mon, i, ysize-i-1, xsize-i-1, ysize-i-1, dkgrey);
      gdImageLine(imgbuf_mon, xsize-i-1, i, xsize-i-1, ysize-i-1, dkgrey);
   }

   /* draw the inner frame around the data, 2 pixels wide */
   gdImageRectangle(imgbuf_mon, 19, 20, xsize-19, ysize-27, black);
   gdImageFilledRectangle(imgbuf_mon, 20, 21, xsize-20, ysize-28, white);

   /* draw the outermost black frame line around the image, 1 pixel wide */
   gdImageRectangle(imgbuf_mon, 0, 0, xsize-1, ysize-1, black);

   /* display the graph title */
   gdImageString(imgbuf_mon, gdFontMediumBold, 26, 5, (unsigned char*) title, dkblue);
   if(DEBUG>=2) printf("Finished init_monthgraph().\n");
   return;
}
Example #10
0
int main()
{
	gdImagePtr im;
	int error = 0;
	int c, c1, c2, c3, c4, color, i;

	im = gdImageCreateTrueColor(5, 5);
	c = gdImageColorExact(im, 255, 0, 255);
	c2 = gdImageColorExactAlpha(im, 255, 0, 255, 100);
	gdImageDestroy(im);

	if (gdTestAssert(c == 0xFF00FF) != 1) {
		error = -1;
	}
	if (gdTestAssert(c2 == 0x64FF00FF) != 1) {
		error = -1;
	}

	im = gdImageCreate(5, 5);
	c1 = gdImageColorAllocate(im, 255, 0, 255);
	c2 = gdImageColorAllocate(im, 255, 200, 0);
	c3 = gdImageColorAllocateAlpha(im, 255, 0, 255, 100);

	c1 = gdImageColorExact(im, 255, 0, 255);
	c2 = gdImageColorExact(im, 255, 200, 0);
	c3 = gdImageColorExactAlpha(im, 255, 0, 255, 100);
	c4 = gdImageColorExactAlpha(im, 255, 34, 255, 100);

	if (gdTestAssert(c1 == 0) != 1) {
		error = -1;
	}
	if (gdTestAssert(c2 == 1) != 1) {
		error = -1;
	}
	if (gdTestAssert(c3 == 2) != 1) {
		error = -1;
	}
	if (gdTestAssert(c4 == -1) != 1) {
		error = -1;
	}

	color = gdTrueColorAlpha(gdImageRed(im, c1), gdImageGreen(im, c1),
					gdImageBlue(im, c1), 0);
	if (gdTestAssert(color == 0xFF00FF) != 1) {
		error = -1;
	}
	color = gdTrueColorAlpha(gdImageRed(im, c2), gdImageGreen(im, c2),
					gdImageBlue(im, c2), 0);
	if (gdTestAssert(color == 0xFFC800) != 1) {
		error = -1;
	}
	color = gdTrueColorAlpha(gdImageRed(im, c3), gdImageGreen(im, c3),
					gdImageBlue(im, c3), 0);
	if (gdTestAssert(color == 0xFF00FF) != 1) {
		error = -1;
	}
	gdImageDestroy(im);

	return error;
}
Example #11
0
int main()
{
	gdImagePtr src, dst;
	int r, g, b;
	void *p;
	int size = 0;
	int status = 0;
	CuTestImageResult result = {0, 0};

	src = gdImageCreate(100, 100);
	if (src == NULL) {
		gdTestErrorMsg("could not create src\n");
		return 1;
	}
	r = gdImageColorAllocate(src, 0xFF, 0, 0);
	g = gdImageColorAllocate(src, 0, 0xFF, 0);
	b = gdImageColorAllocate(src, 0, 0, 0xFF);
	gdImageFilledRectangle(src, 0, 0, 99, 99, r);
	gdImageRectangle(src, 20, 20, 79, 79, g);
	gdImageEllipse(src, 70, 25, 30, 20, b);

#define OUTPUT_GD2(x) do {												\
		FILE *fp = gdTestTempFp();										\
		gdImageGd2(x, fp, (GD2_CHUNKSIZE_MIN+GD2_CHUNKSIZE_MAX)/2, GD2_FMT_COMPRESSED); \
		fclose(fp);														\
	} while (0)

	OUTPUT_GD2(src);
	p = gdImageGd2Ptr(src, (GD2_CHUNKSIZE_MIN+GD2_CHUNKSIZE_MAX)/2, GD2_FMT_COMPRESSED, &size);
	if (p == NULL) {
		status = 1;
		gdTestErrorMsg("p is null\n");
		goto door0;
	}
	if (size <= 0) {
		status = 1;
		gdTestErrorMsg("size is non-positive\n");
		goto door1;
	}

	dst = gdImageCreateFromGd2Ptr(size, p);
	if (dst == NULL) {
		status = 1;
		gdTestErrorMsg("could not create dst\n");
		goto door1;
	}
	OUTPUT_GD2(dst);
	gdTestImageDiff(src, dst, NULL, &result);
	if (result.pixels_changed > 0) {
		status = 1;
		gdTestErrorMsg("pixels changed: %d\n", result.pixels_changed);
	}
	gdImageDestroy(dst);
door1:
	gdFree(p);
door0:
	gdImageDestroy(src);
	return status;
}
Example #12
0
int main()
{
	gdImagePtr src, dst;
	int b;
	void *p;
	int size = 0;
	int status = 0;
	CuTestImageResult result = {0, 0};

	src = gdImageCreate(100, 100);
	if (src == NULL) {
		printf("could not create src\n");
		return 1;
	}
	gdImageColorAllocate(src, 0xFF, 0xFF, 0xFF); /* allocate white for background color */
	b = gdImageColorAllocate(src, 0, 0, 0);
	gdImageRectangle(src, 20, 20, 79, 79, b);
	gdImageEllipse(src, 70, 25, 30, 20, b);

#define OUTPUT_WBMP(name) do {							\
		FILE *fp = gdTestTempFp();						\
		gdImageWBMP(name, 1, fp);						\
		fclose(fp);										\
	} while (0)

	OUTPUT_WBMP(src);
	p = gdImageWBMPPtr(src, &size, 1);
	if (p == NULL) {
		status = 1;
		printf("p is null\n");
		goto door0;
	}
	if (size <= 0) {
		status = 1;
		printf("size is non-positive\n");
		goto door1;
	}

	dst = gdImageCreateFromWBMPPtr(size, p);
	if (dst == NULL) {
		status = 1;
		printf("could not create dst\n");
		goto door1;
	}
	OUTPUT_WBMP(dst);
	gdTestImageDiff(src, dst, NULL, &result);
	if (result.pixels_changed > 0) {
		status = 1;
		printf("pixels changed: %d\n", result.pixels_changed);
	}
	gdImageDestroy(dst);
door1:
	gdFree(p);
door0:
	gdImageDestroy(src);
	return status;
}
Example #13
0
void ColorBlackWhite::allocate(gdImagePtr image, unsigned int max_iterations)
{
	if(colors != NULL)
		free();

	colors = new int[2];

	colors[0] = gdImageColorAllocate(image, 0, 0, 0);
	colors[1] = gdImageColorAllocate(image, 255, 255, 255);
}
Example #14
0
File: gddemo.c Project: fm4dd/edacs
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);
}
Example #15
0
Boolean GdoInit(unsigned int     w,
                unsigned int     h,
                const char      *file,
                struct ADrawTag *outContext)
{
    GdoContext *context;

    /* Create context */
    context = outContext->internal = malloc(sizeof(GdoContext));
    if(context == NULL)
    {
        return FALSE;
    }

    /* Open the output file */
    context->outFile = fopen(file, "wb");
    if(!context->outFile)
    {
        fprintf(stderr, "GdoInit: Failed to open output file '%s':\n", file);
        perror(NULL);
        return FALSE;
    }

    /* Allocate the image */
    context->img = gdImageCreate(w, h);

    /* Get the colours */
    context->colour[ADRAW_COL_WHITE] = gdImageColorAllocate(context->img, 255, 255, 255); /* Background */
    context->colour[ADRAW_COL_BLACK] = gdImageColorAllocate(context->img, 0, 0, 0);
    context->colour[ADRAW_COL_BLUE]  = gdImageColorAllocate(context->img, 0, 0, 255);

    /* Set pen colour to black */
    context->pen = context->colour[ADRAW_COL_BLACK];

    /* Get the default font */
    context->font = gdFontGetSmall();

    /* Now fill in the function pointers */
    outContext->line           = gdoLine;
    outContext->dottedLine     = gdoDottedLine;
    outContext->textL          = gdoTextL;
    outContext->textC          = gdoTextC;
    outContext->textR          = gdoTextR;
    outContext->textWidth      = gdoTextWidth;
    outContext->textHeight     = gdoTextHeight;
    outContext->filledTriangle = gdoFilledTriangle;
    outContext->arc            = gdoArc;
    outContext->dottedArc      = gdoDottedArc;
    outContext->setPen         = gdoSetPen;
    outContext->setFontSize    = gdoSetFontSize;
    outContext->close          = gdoClose;

    return TRUE;
}
Example #16
0
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;
}
Example #17
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;
}
Example #18
0
int
create_im (char * name,
		   char * string,
		   int * res,
		   int * sub,
		   rgb backg,
		   rgb foreg)
{
	gdImagePtr	im;
	FILE		* background;
	int			act[2];

	int			back;
	int			fore;

	char		* buf;
	int			y = 0;
    size_t      i;

	act[0] = res[0] / 2 - (sub[0] * gdFontGetLarge ()->w) / 2;
	act[1] = res[1] / 2 - (sub[1] * gdFontGetLarge ()->h) / 2;

	buf = (char *) malloc (((int) get_screen_dims ()[1] / gdFontGetLarge ()->w) * sizeof (char));

	im = gdImageCreate (res[0], res[1]);

	back = gdImageColorAllocate (im, backg.r, backg.g, backg.b);
	fore = gdImageColorAllocate (im, foreg.r, foreg.g, foreg.b);

	for (i = 0; i < strlen (string); i++)
	{
		if (string[i] != '\n')
			buf[y++] = string[i];
		else
		{
			buf[y] = '\0';
			y = 0;
			gdImageString (im, gdFontGetLarge (), act[0], act[1], (unsigned char *) buf, fore);
			act[1] += gdFontGetLarge ()->h;
		}
	}

	buf[y] = '\0';
	gdImageString (im, gdFontGetLarge (), act[0], act[1], (unsigned char *) buf, fore);

	background = fopen (name, "wb");
	gdImageJpeg (im, background, -1);
	fclose (background);
	gdImageDestroy (im);
	return 1;
}
Example #19
0
int main()
{
    gdImagePtr im, tile;
    int im_white, im_black, tile_white, tile_black;
    int x,y, error = 0;
    FILE *fp;
    char path[1024];

    fputs("flag 0\n", stdout);
    im = gdImageCreate(150, 150);


    tile = gdImageCreateTrueColor(36, 36);

    tile_white = gdImageColorAllocate(tile,255,255,255);
    tile_black = gdImageColorAllocate(tile,55,0,0);
    im_white = gdImageColorAllocate(im,255,255,255);
    im_black = gdImageColorAllocate(im,0,0,0);

    gdImageFill(tile, 0,0, tile_white);
    gdImageColorTransparent(tile, tile_black);
    gdImageColorTransparent(im, im_black);

    /* create the dots pattern */
    for (x=0; x<36; x+=2) {
        for (y=0; y<36; y+=2) {
            gdImageSetPixel(tile,x,y,tile_black);
        }
    }

    gdImageSetTile(im,tile);
    gdImageRectangle(im, 9,9,139,139, im_black);
    gdImageLine(im, 9,9,139,139, im_black);
    gdImageFill(im, 11,12, gdTiled);


    fputs("flag 1\n", stdout);
    gdImageFill(im, 0, 0, 0xffffff);
    fputs("flag 2\n", stdout);
    gdImageFill(im, 0, 0, 0xffffff);
    fputs("flag 3\n", stdout);

    sprintf(path, "%s/gdimagefill/bug00002_3_exp.png", GDTEST_TOP_DIR);
    if (!gdAssertImageEqualsToFile(path, im)) {
        error = 1;
    }

    /* Destroy it */
    gdImageDestroy(im);
    return error;
}
Example #20
0
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);
}
Example #21
0
/*本函数将code指定的字符写入图片中,将图片大小存储在pic_size中,返回该图片所在的内存地址
写入成功时,返回的内存指针非空
写入失败时,返回的内存指针为空
*/
void * sslvpn_write_string_to_pic(s8 *code, s32 *pic_size)
{
	/* Declare color indexes */  
    s32 black = 0;  
    s32 white = 0;   
    s32 randcolor = 0;
    s32 i = 0;
	
    /* img pointer */
    gdImagePtr im;  

    /* Font ptr */
    gdFontPtr ftptr=gdFontGetGiant();

    /*Picture buffer pointer*/
    void *pic_buf_ptr;

    /* Allocate the image: SSLVPN_VALID_PIC_WIDTH pixels across by SSLVPN_VALID_PIC_HEIGHTS pixels tall */  
    im = gdImageCreate(SSLVPN_VALID_PIC_WIDTH, SSLVPN_VALID_PIC_HEIGHT);   
    
    /* Allocate the color white (red, green and blue all maximum). */  
    /* Since this is the first color in a new image, it will    
     * be the background color. */  
    white = gdImageColorAllocate(im, 255, 255, 255);     
    
    /* Allocate the color black (red, green and blue all minimum). */ 
    black = gdImageColorAllocate(im, 0, 0, 0);

    /* Draw a centered string. */    
    gdImageString(im, ftptr, 
        (im->sx) / 2 - (strlen(code) * (ftptr->w) / 2),      
        (im->sy) / 2 - ftptr->h / 2, (u8*)code, black);
    
    /* Some disturbing points */
    for(i = 0; i < SSLVPN_VALID_DISTURB_POINTS; i++)
    {
        randcolor = gdImageColorAllocate(im, sslvpn_getRandom(255), sslvpn_getRandom(255), sslvpn_getRandom(255));
        gdImageSetPixel(im, sslvpn_getRandom(SSLVPN_VALID_PIC_WIDTH), sslvpn_getRandom(SSLVPN_VALID_PIC_HEIGHT), randcolor);
    }

    /* Output the image to buf and asign the length of buf to pic_size. */  
    pic_buf_ptr = gdImagePngPtr(im, pic_size);

    /* Destroy the image in memory. */  
    gdImageDestroy(im);

    return pic_buf_ptr;
    
}
Example #22
0
int BptDraw(LPBPTREE bpt, const char *img_filename) {
	gdImagePtr im;

	im = gdImageCreateTrueColor(IMG_CX, IMG_CY);

	bgcolor = gdImageColorAllocate(im, 0xFF, 0x00, 0x00);
	fgcolor = gdImageColorAllocate(im, 0xFF, 0xFF, 0xFF);

	_BptDrawWorker(im, bpt, bpt->root, 0, 0, IMG_CX / 2);

	ImgSavePng(img_filename, im);

	gdImageDestroy(im);
	return 1;
}
int main(void) {
	// Create IP connection
	IPConnection ipcon;
	ipcon_create(&ipcon);

	// Create device object
	OLED64x48 oled;
	oled_64x48_create(&oled, UID, &ipcon);

	// Connect to brickd
	if(ipcon_connect(&ipcon, HOST, PORT) < 0) {
		fprintf(stderr, "Could not connect\n");
		return 1;
	}
	// Don't use device before ipcon is connected

	// Clear display
	oled_64x48_clear_display(&oled);

	// Draw rotating line
	gdImagePtr image = gdImageCreate(WIDTH, HEIGHT);
	int black = gdImageColorAllocate(image, 0, 0, 0);
	int white = gdImageColorAllocate(image, 255, 255, 255);
	int origin_x = WIDTH / 2;
	int origin_y = HEIGHT / 2;
	int length = HEIGHT / 2 - 2;
	int angle = 0;

	printf("Press ctrl+c exit\n");

	while (true) {
		double radians = M_PI * angle / 180.0;
		int x = (int)(origin_x + length * cos(radians));
		int y = (int)(origin_y + length * sin(radians));

		gdImageFilledRectangle(image, 0, 0, WIDTH, HEIGHT, black);
		gdImageLine(image, origin_x, origin_y, x, y, white);

		draw_image(&oled, image);
		millisleep(25);

		angle++;
	}

	gdImageDestroy(image);
	ipcon_destroy(&ipcon); // Calls ipcon_disconnect internally
	return 0;
}
Example #24
0
const char *generate_verify_num() {
	/* Declare the image */
	gdImagePtr im;
	/* Declare output files */
	//FILE *gifout;
	/* Declare color indexes */
	int black;
	int white;
	int x, y, z;
	int rd;
	static char s[10];

	/* Allocate the image: 64 pixels across by 64 pixels tall */
	im = gdImageCreate(40, 16);

	/* 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);

	white = gdImageColorAllocate(im, 255, 255, 255);

	srandom(time(0)%getpid());

	rd=random()%(100000);
	sprintf(s, "%05d", rd);
	gdImageString(im, gdFontGetLarge(), 0, 0, s, white);
	for (z=0; z<20; z++) {
		x=random()%(im->sx);
		y=random()%(im->sy);
		gdImageSetPixel(im, x, y, white);
	}
	for (y=0; y<im->sy; y++) {
		for (x=0; x<im->sx; x++) {
			if (gdImageGetPixel(im, x, y))
				outc('o');
			else
				outc(' ');
		}
		outc('\n');
	}

	gdImageDestroy(im);

	oflush();

	return s;
}
Example #25
0
int main(void)
{
	int i;
	FILE * out;

	gdImagePtr im;
	gdImagePtr prev =NULL;
	int black;

	im = gdImageCreate(100, 100);
	if (!im) {
		fprintf(stderr, "can't create image");
		return 1;
	}

	out = fopen("anim.gif", "wb");
	if (!out) {
		fprintf(stderr, "can't create file %s", "anim.gif");
		return 1;
	}

	gdImageColorAllocate(im, 255, 255, 255); /* allocate white as side effect */
	gdImageGifAnimBegin(im, out, 1, -1);

	for(i = 0; i < 20; i++) {
		int r,g,b;
		im = gdImageCreate(100, 100);
		r = rand() % 255;
		g = rand() % 255;
		b = rand() % 255;

		gdImageColorAllocate(im, 255, 255, 255);  /* allocate white as side effect */
		black = gdImageColorAllocate(im,  r, g, b);
		printf("(%i, %i, %i)\n",r, g, b);
		gdImageFilledRectangle(im, rand() % 100, rand() % 100, rand() % 100, rand() % 100, black);
		gdImageGifAnimAdd(im, out, 1, 0, 0, 10, 1, prev);

		if(prev) {
			gdImageDestroy(prev);
		}
		prev = im;
	}

	gdImageGifAnimEnd(out);
	fclose(out);

	return 0;
}
Example #26
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);    
}
int creaBorde( struct MAPA mapa, gdImagePtr im)
{
  int pxmin, pxmax, pymin, pymax;
  int negro;
  double xmin, xmax, ymin, ymed, ymax;
  xmin = proy_mercator_x( mapa.lonmed, mapa.lonmin );
  xmax = proy_mercator_x( mapa.lonmed, mapa.lonmax );
  pxmin = lrintf(xmin * (double)mapa.escalax + (double)mapa.resx / 2.0);
  pxmax = lrintf(xmax * (double)mapa.escalax + (double)mapa.resx / 2.0);
  ymin = proy_mercator_y( mapa.latmin );
  ymed = proy_mercator_y( mapa.latmed );
  ymax = proy_mercator_y( mapa.latmax );

  ymin = ( ymax + ymin ) / 2.0
  pymin = lrintf( - ( ymin ) * (double) mapa.escalay + (double) mapa.resy / 2.0);
  pymax = lrintf( - ( ymax ) * (double) mapa.escalay + (double) mapa.resy / 2.0);

  // pymin = pymin + lrintf(1.0 * (double)pymin);
  // pymax = pymax + lrintf(1.0 * (double)pymin);
  //  y = -(float)( py - resy / 2 ) / (float)escalaY + desplazamiento;

  negro = gdImageColorAllocate( im, 0, 0, 0 );
  printf("(xmin,ymin)=(%f,%f) ymin - ymed = %f\n", xmin, ymin, ymin - ymed );
  printf("(pxmin,pymin)=(%i,%i)\n", pxmin, pymin );
  printf("(xmax,ymax)=(%f,%f) ymin - ymed = %f\n", xmax, ymax, ymed );
  printf("(pxmax,pymax)=(%i,%i)\n", pxmax, pymax );
  gdImageRectangle( im, pxmin, pymin, pxmax, pymax, negro );

  return 0;
}
Example #28
0
void doColorRange(FILE *stream) {
  int n, r1, g1, b1, r2, g2, b2, r, g, b;
  int idx, step, minc, maxc;
  float alpha, beta;

  n = getNumber(stream);
  r1 = getNumber(stream);
  g1 = getNumber(stream);
  b1 = getNumber(stream);
  r2 = getNumber(stream);
  g2 = getNumber(stream);
  b2 = getNumber(stream);
  // fprintf(stderr, "%d (%d, %d, %d) to (%d, %d, %d)\n", n, r1, g1, b1, r2, g2, b2);
  // rd = r2 - r1; gd = g2 - g1; bd = b2 - b1;
  for (step = 0; step <= n; step++) {
    alpha = 1.0 * (n - step) / n;
    beta  = 1.0 * step / n;
    r = round(alpha * r1 + beta * r2);
    g = round(alpha * g1 + beta * g2);
    b = round(alpha * b1 + beta * b2);
    
    idx = gdImageColorAllocate(image, r, g, b);
    // fprintf(stderr, "a=%f, idx=%d (%d, %d, %d)\n", alpha, idx, r, g, b);
    colors[colorptr] = idx;
    colorptr++;
    if (step == 0) {
      minc = idx;
    } else {
      maxc = idx;
    }
  }
  sprintf(cmdresult, "%d-%d", minc, maxc);
}
Example #29
0
int CFunctions::imgColorAllocate ( lua_State* luaVM )
{
	// bool/int imageColorAllocate( userdata im, int red, int green, int blue)
    if ( luaVM )
    {
        if ( lua_type ( luaVM, 1 ) == LUA_TLIGHTUSERDATA &&
            lua_type ( luaVM, 2 ) == LUA_TNUMBER &&
            lua_type ( luaVM, 3 ) == LUA_TNUMBER &&
            lua_type ( luaVM, 4 ) == LUA_TNUMBER )
		{
			gdImagePtr im = mImgManager->GetImage( lua_touserdata( luaVM, 1 ) );
			if( im != NULL )
			{
				int ret = gdImageColorAllocate( im, (int)lua_tonumber(luaVM, 2), (int)lua_tonumber(luaVM, 3), (int)lua_tonumber(luaVM, 4) );
				if( ret != -1 ) lua_pushnumber( luaVM, ret );
				else            lua_pushboolean( luaVM, false );
			}
			else
			{
				lua_pushboolean( luaVM, false );
			}
			return 1;
		}
		else
		{
			pModuleManager->DebugPrintf( luaVM, "Incorrect parameters in: imageColorAllocate" );
			lua_pushboolean( luaVM, false );
		}
		return 1;
    }
    return 0;
}
Example #30
0
/*
    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;
}