Exemplo n.º 1
1
int main()
{
	gdImagePtr src, dst;
	int w, 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;
	}
	w = gdImageColorAllocate(src, 0xFF, 0xFF, 0xFF);
	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;										\
														\
		fp = fopen("wbmp_im2im_" #name ".wbmp", "wb");	\
		if (fp) {										\
			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;
}
Exemplo n.º 2
0
Arquivo: charts.c Projeto: fm4dd/edacs
/* -------------------------------------------------------------------- */
int user_permonth(  char *fname,          /* PNG file name to use */
                   char *title,           /* title for graph      */
                    int fmonth,           /* begin month number   */
                 unsigned long long data1[18]) {      /* data1 (users)        */
   int i,x1,y1,x2,s_mth;
   unsigned long long maxval=0;
   char * msg_xlegend = "Months";
   char * msg_ylegend = "Users";

   /* short month names MUST BE 3 CHARS in size... pad if needed*/
   static char *s_month[12] ={ "Jan", "Feb", "Mar", "Apr",
                               "May", "Jun", "Jul", "Aug",
                               "Sep", "Oct", "Nov", "Dec" };


   /* initalize the graph image */
   init_yeargraph(title);

   /* draw index lines */
   y1=110/(INDEX_LINES+1);
   for (i=1;i<=INDEX_LINES;i++)
     gdImageLine(imgbuf_year,20,(i*y1)+22,380,(i*y1)+22,dkgrey);

   /* draw the x-axis legend */
   s_mth = fmonth;
   /* 18 is how many x-axis values we will display */
   for (i=0;i<18;i++) {
      /* 23 is the start pixel from left, 20 is the distance between each value */
      gdImageString(imgbuf_year, gdFontSmall, 23+(i*20),
                    /* 134 is the start pixel from top, black the font color */
                    134, (unsigned char*) s_month[s_mth-1], black);
      if(strcmp(s_month[s_mth-1], "Dec") == 0) {
        gdImageLine(imgbuf_year, 23+(i*20)+18, 21, 23+(i*20)+18, 132, dkgrey);
      }
      s_mth++;
      if (s_mth > 12) s_mth = 1;
      if (data1[i] > maxval) maxval = data1[i];           /* get max val    */
   }

   sprintf(maxvaltxt, "%llu", maxval);
   gdImageStringUp(imgbuf_year,gdFontSmall,6,19+(strlen(maxvaltxt)*6),(unsigned char*) maxvaltxt,black);

   /* print color coded legends */
   /* X Legend */
   i = (strlen(msg_xlegend)*6);
   gdImageString(imgbuf_year,gdFontMediumBold,388-i,144,(unsigned char*) msg_xlegend,black);

   /* Y Legend */
   i = (strlen(msg_ylegend)*6);
   gdImageStringUp(imgbuf_year,gdFontMediumBold,6,132,(unsigned char*) msg_ylegend,black);

   /* draw the data bars here */
   s_mth = fmonth;
   for (i=0; i<18; i++) {
     if(data1[17-i] > 0) {
      if (s_mth > 12) s_mth = 1;
      percent = ((float)data1[17-i] / (float)maxval);
      if (percent <= 0.0) continue;
      x1 = 25 + (i*20);
      x2 = x1 + 11;
      y1 = 132 - (percent * 110);
      gdImageFilledRectangle(imgbuf_year, x1, y1, x2, 132, dkblue);
      gdImageRectangle(imgbuf_year, x1, y1, x2, 132, black);
    }
   }

   sprintf(maxvaltxt, "%llu", maxval);

   /* save png image */
   if ((pngout = fopen(fname, "wb")) != NULL) {
      gdImagePng(imgbuf_year, pngout);
      fclose(pngout);
   }
   /* deallocate memory */
   gdImageDestroy(imgbuf_year);
   return (0);
} /* end user_permonth() */
Exemplo n.º 3
0
Arquivo: charts.c Projeto: fm4dd/edacs
/* -------------------------------------------------------------------- */
int con_perday(  char *fname,           /* PNG file name to use */
                 char *title,           /* title for graph      */
                 unsigned long long data1[31]) {    /* data1 (connections)  */
   int i,x1,y1,x2;
   unsigned long long maxval=0;
   char * msg_xlegend = "Day";
   char * msg_ylegend = "Connections";
   char daydate[3]    = "";
   static int sleft   = 29;

   /* initalize the graph image */
   init_monthgraph(title);

   /* draw index lines */
   y1=110/(INDEX_LINES+1);
   for (i=1;i<=INDEX_LINES;i++)
     gdImageLine(imgbuf_mon,20,(i*y1)+22,650,(i*y1)+22,dkgrey);

   /* draw the x-axis legend, is how many x-axis values we will display */
   for (i=0;i<31;i++) {
      snprintf(daydate, sizeof(daydate), "%02d", i+1);
      /* sleft is start pixel from left, 20 is the distance between each value */
      gdImageString(imgbuf_mon, gdFontSmall, (sleft+1)+(i*20),
                    /* 134 is the start pixel from top, black the font color */
                    134, (unsigned char *) daydate, black);
      if (data1[i] > maxval) maxval = data1[i];           /* get max val    */
   }

   sprintf(maxvaltxt, "%llu", maxval);
   gdImageStringUp(imgbuf_mon,gdFontSmall,6,19+(strlen(maxvaltxt)*6),(unsigned char*) maxvaltxt,black);

   /* print color coded legends */
   /* X Legend */
   i = (strlen(msg_xlegend)*6);
   gdImageString(imgbuf_mon,gdFontMediumBold,658-i,144,(unsigned char*) msg_xlegend,black);

   /* Y Legend */
   i = (strlen(msg_ylegend)*6);
   gdImageStringUp(imgbuf_mon,gdFontMediumBold,6,132,(unsigned char*) msg_ylegend,black);

   /* draw the data bars here */
   for (i=0; i<31; i++) {
     if(data1[i] > 0) {
      percent = ((float)data1[i] / (float)maxval);
      if (percent <= 0.0) continue;
      x1 = sleft + (i*20);
      x2 = x1 + 11;
      y1 = 132 - (percent * 110);
      gdImageFilledRectangle(imgbuf_mon, x1, y1, x2, 132, dkblue);
      gdImageRectangle(imgbuf_mon, x1, y1, x2, 132, black);
    }
   }

   sprintf(maxvaltxt, "%llu", maxval);

   /* save png image */
   if ((pngout = fopen(fname, "wb")) != NULL) {
      gdImagePng(imgbuf_mon, pngout);
      fclose(pngout);
   }
   /* deallocate memory */
   gdImageDestroy(imgbuf_mon);
   return (0);
}
Exemplo n.º 4
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) {
		printf("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;														\
																		\
		fp = fopen("gd2_im2im_" #x ".gd2", "wb");						\
		if (fp) {														\
			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;
		printf("p is null\n");
		goto door0;
	}
	if (size <= 0) {
		status = 1;
		printf("size is non-positive\n");
		goto door1;
	}

	dst = gdImageCreateFromGd2Ptr(size, p);
	if (dst == NULL) {
		status = 1;
		printf("could not create dst\n");
		goto door1;
	}
	OUTPUT_GD2(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;
}
Exemplo n.º 5
0
int main(int argc, char **argv)
{

	int ret, verbose = 0; unsigned int i;
	char *affix = NULL;
	char *prefix = NULL;
	int opt = 0;
	int len = 0;
	int fd1, fd2;
	char *png_filename = NULL;
	unsigned int entries = DEFAULT_ENTRIES;
	unsigned int table_size = DEFAULT_HASHTABLE_SIZE;
	struct drand48_data r_d;
	hi_handle_t *hi_handle;
	uint32_t (*hashf)(const uint8_t *, uint32_t);
	const char *hashfname;

	hashf = NULL;

	srand48_r((long int)time(NULL), &r_d);

	while ((opt = getopt(argc, argv, "hqn:l:p:t:a:g:f:v")) != -1) {
		switch (opt) {
		case 'q':
			{
			int max_fd, std_fd, j;
			if ((max_fd = (int) sysconf(_SC_OPEN_MAX)) < 0) {
				max_fd = 256;
			}
			for (j = max_fd - 1; j >= 0; --j) {
				close(j);
			}
			std_fd = open("/dev/null", O_RDWR);
			fd1 = dup(std_fd);
			fd2 = dup(std_fd);
			}
			break;
		case 'f':
			if (!(strcasecmp(optarg, "elf"))) {
				hashf = lhi_hash_elf;
				hashfname = "lhi_hash_elf";
			} else if (!(strcasecmp(optarg, "torek"))) {
				hashf = lhi_hash_torek;
				hashfname = "lhi_hash_torek";
			} else if (!(strcasecmp(optarg, "dumb1"))) {
				hashf = lhi_hash_dumb1;
				hashfname = "lhi_hash_dumb1";
			} else if (!(strcasecmp(optarg, "phong"))) {
				hashf = lhi_hash_phong;
				hashfname = "lhi_hash_phong";
			} else {
				fprintf(stderr, "Hashing function not supported: %s\n",
						optarg);
				usage(EXIT_FAILURE, argv[0]);
			}
			break;
		case 'h':
			usage(EXIT_SUCCESS, argv[0]);
			break;
		case 'n':
			entries = atoi(optarg);
			break;
		case 'l':
			len = atoi(optarg);
			break;
		case 'p':
			prefix = strdup(optarg);
			break;
		case 't':
			table_size = atoi(optarg);
			break;
		case 'v':
			verbose++;
			break;
		case 'a':
			affix = strdup(optarg);
			break;
		case 'g':
#ifdef HAVE_LIBGD
			png_filename = strdup(optarg);
# else
			fprintf(stderr, "sorry - you build without gd library support\n");
			usage(EXIT_FAILURE, argv[0]);
#endif
			break;
		case '?':
			fprintf(stderr, "No such option: `%c'\n\n", optopt);
			usage(EXIT_FAILURE, argv[0]);
			break;
		}
	}

	fputs("# String Distribution Hash Test\n", stderr);

	/* initialize secure[tm] rand() seed */
	//init_seed();

	/* initialize hash table */
	ret = hi_init_str(&hi_handle, table_size);

	if (hashf != NULL) {
		lhi_sethashfunc(hi_handle, hashf);
		fprintf(stderr, "# take %s as hash function\n", hashfname);
	}

	/* fill hash table */
	for(i = 0; i < entries; i++) {

		char *key = NULL, *tmp_key;
		size_t key_len = 0;

		/* compound key */
		if (len == 0) {
			len = (rand() % (MAX_STRING_LEN - MIN_STRING_LEN + 1)) + MIN_STRING_LEN;
		}
		if (random_string(len, &tmp_key, &r_d) < 0)
			exit(EXIT_FAILURE);

		if (prefix)
			key_len += strlen(prefix);
		key_len += strlen(tmp_key);
		if (affix)
			key_len += strlen(affix);


		key = malloc(key_len + 1);
		if (key == NULL) {
			fprintf(stderr, "malloc %s\n", strerror(errno));
			exit(1);
		}

		if (prefix != NULL) {
			sprintf(&key[0], "%s%s", prefix, tmp_key);
		} else {
			sprintf(key, "%s", tmp_key);
		}

		free(tmp_key);
		tmp_key = NULL;

		if (affix)
			strcat(key, affix);

		if (verbose >= 1)
			fprintf(stdout, "key: %s\n", key);

		ret = hi_insert_str(hi_handle, (void *) key, NULL);
		if (ret < 0)
			fprintf(stderr, "# WARNING: Can't insert key (maybe a duplicated key: %s)!\n", key);
	}

	/* print statistic */
	ret = hi_size(hi_handle);
	fprintf(stderr, "# hash table entries: %d\n", ret);

	if (png_filename) { /* grapical output */

#ifdef HAVE_LIBGD
# define RECT_SIZE 5
# define RECT_BODER_SIZE 1

		int j;
		uint32_t x, y;
		gdImagePtr im;
		FILE *pngout;
		int black, white, red, max_list_len = 0;


		/* calculate maximum listsize */
		for(i = 0; i < table_size; i++) {
			int tmp_bucket_size = hi_bucket_size(hi_handle, i);
			max_list_len = max(max_list_len, tmp_bucket_size);
		}


		/* create a image with max_list_len X table_size */
		im = gdImageCreate((max_list_len * (RECT_SIZE + RECT_BODER_SIZE * 2)) + 2,
				(table_size * ((RECT_SIZE + RECT_BODER_SIZE * 2)) + 2));

		black = gdImageColorAllocate(im, 255, 231, 186);
		white = gdImageColorAllocate(im, 255, 165, 79);
		red   = gdImageColorAllocate(im, 205, 102, 29);

		x = 1;
		y = 1;

		for (i = 0; i < table_size; i++) {
			int bucket_size =  hi_bucket_size(hi_handle, i);
			for (j = 0; j < bucket_size; j++) {
				gdImageFilledRectangle(im, x + 1, y + 1, x + RECT_SIZE, y + RECT_SIZE, white);
				gdImageRectangle(im, x, y, x + RECT_SIZE + (RECT_BODER_SIZE << 1), y + RECT_SIZE + (RECT_BODER_SIZE << 1), red);
				x += RECT_SIZE + (RECT_BODER_SIZE << 1);
			}
			x = 1;
			y += RECT_SIZE + (RECT_BODER_SIZE << 1);
		}

		pngout = fopen(png_filename, "wb");
		gdImagePng(im, pngout);
		fclose(pngout);
		gdImageDestroy(im);

# undef RECT_SIZE
# undef RECT_BODER_SIZE
#endif /* HAVE_LIBGD */

	}

	if (verbose >= 1) {  /* terminal output */
		for(i = 0; i < table_size; i++) {
			fprintf(stderr, "bucket no: %d bucket size: %d\n",
					i, hi_bucket_size(hi_handle, i));
		}

	}

	/* delete table */
	hi_fini(hi_handle);

	return 0;
}
Exemplo n.º 6
0
int msasShowAdminLogon(int confd,ltMsgHead *ltMsgPk,lt_shmHead *lt_MMHead){
	
	
	ltDbHeadPtr dbPtr;
	
	unsigned int sid;
	char sIp[24];
  int  i;
	char strsid[12];

	int  adminipcount;
	int  ipok;
	
  char sqlBuf[1024];
	ltDbCursor *tempCursor;
	LT_DBROW tempRow;
	
	sid=0;
	memset(sIp,0,sizeof(sIp));


	ltMsgGetSomeNVar(ltMsgPk,1,"clientip",    LT_TYPE_STRING, 19, sIp);



	
	dbPtr=lt_dbinit();
  lt_db_htmlpage(dbPtr,"utf-8");
  

  adminipcount=0;
  ipok=0;
 

  
  sprintf(sqlBuf,"select count(*) from msasAdminArea ");
			
	tempCursor=ltDbOpenCursor(G_DbCon,sqlBuf);
	if(tempCursor!=NULL){
				tempRow= ltDbFetchRow(tempCursor);
				if(tempRow!=NULL){
					adminipcount=atol(tempRow[0]);
				}
				ltDbCloseCursor(tempCursor);
	}
	

  if(adminipcount==0){
  	ipok=1;
  }else{
      unsigned int s_ip,e_ip,my_ip;
      my_ip=ntohl(inet_addr(sIp));
      
      sprintf(sqlBuf,"select ipstart,ipend from msasAdminArea ");
			
			tempCursor=ltDbOpenCursor(G_DbCon,sqlBuf);
			if(tempCursor!=NULL){
						tempRow= ltDbFetchRow(tempCursor);
						while(tempRow!=NULL){
							s_ip=ntohl(inet_addr(tempRow[0]));
							e_ip=ntohl(inet_addr(tempRow[1]));
							if( (my_ip >=s_ip) && (my_ip <=e_ip) ){ 
							   ipok=1;
							   break;
							}
						}
						ltDbCloseCursor(tempCursor);
			}
  }
	 

  if(ipok==0){
  	

		 ltMsgPk->msgpktype=1;
 		 lt_TcpResponse(confd,ltMsgPk,2,"lthead",LT_TYPE_STRING,"Content-type: text/html; charset=utf-8\n","lthtml",LT_TYPE_STRING,"<html><body bgcolor=\"#cccccc\">Ip Area error!</body></html>");		
		 ltMsgFree(ltMsgPk);
		 return 0;
  	
  }
  
  for(i=0;i<MAX_ADMIN_SESSION;i++){
  	if(strcmp(_ltPubInfo->admSession[i].lright,"0000000000000000000000000000000000000000000")==0){
  		if( (time(0)-_ltPubInfo->admSession[i].lasttime) > MAX_ADMIN_TRYTIMEOUT  ){
          _ltPubInfo->admSession[i].lSip=0;
  			  _ltPubInfo->admSession[i].lasttime=0;
  				_ltPubInfo->admSession[i].trytimes=0;
  		    _ltPubInfo->admSession[i].lSid=0;
  		    sprintf(_ltPubInfo->admSession[i].lright,"%s","0000000000000000000000000000000000000000000");		   
  	 }
  	}else{
  		if( (time(0)-_ltPubInfo->admSession[i].lasttime) > MAX_ADMIN_TIMEOUT  ){
          _ltPubInfo->admSession[i].lSip=0;
  			  _ltPubInfo->admSession[i].lasttime=0;
  				_ltPubInfo->admSession[i].trytimes=0;
  		    _ltPubInfo->admSession[i].lSid=0;
  		    sprintf(_ltPubInfo->admSession[i].lright,"%s","0000000000000000000000000000000000000000000");		   
  		}
    }
  }
   
  for(i=0;i<MAX_ADMIN_SESSION;i++){	
  	if(_ltPubInfo->admSession[i].lSip==ntohl(inet_addr(sIp))   ){
          _ltPubInfo->admSession[i].lSip=0;
  			  _ltPubInfo->admSession[i].lasttime=0;
  				_ltPubInfo->admSession[i].trytimes=0;
  		    _ltPubInfo->admSession[i].lSid=0;
  		    sprintf(_ltPubInfo->admSession[i].lright,"%s","0000000000000000000000000000000000000000000");		   
  	}
  }
	      
	{
	    
				gdImagePtr im;
				int   white,red;
				char caTempDir[128];
        char caTempFile[128];
        void *pJpg;
				int  lSize;
				
				
				sid=time(0)%10000;
				sprintf(strsid,"%04d",sid);
				
				im = gdImageCreate(40,16);
				red= gdImageColorAllocate(im, 0, 0, 0);
				white= gdImageColorAllocate(im, 255, 255, 255);
				
				gdImageRectangle(im, 0, 0, 40, 16, red);
				gdImageString(im, gdFontMediumBold, 5, 2, strsid, white);
				
				sprintf(caTempDir,"%s/%lu/",_TMPDIR,ltStrGetId());
		    if(ltFileIsExist(caTempDir)!=1) {
		        if(mkdir(caTempDir,S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)!=0) {

		            return 0;
		        }
		    }
		    sprintf(caTempFile,"%scheck.jpg",caTempDir);
		    pJpg = gdImageJpegPtr( im,&lSize,-1);
		    gdImageDestroy(im);

		    saveJPG(pJpg,lSize, caTempFile);

		    lt_db_setcookie(dbPtr,"strsid", strsid);
		        
		    lt_dbput_rootvars(dbPtr,1,"file1",caTempFile+strlen(_TMPDIR)+1);
 
        ltMsgPk->msgpktype=1;
				lt_dbput_html(confd,ltMsgPk,dbPtr->doc,"/app/msa/msas/htmlplt/index.htm",dbPtr->head,0);
   }
	
 
	
	 ltMsgFree(ltMsgPk);
	 lt_dbfree(dbPtr);
	 return 0;

}
Exemplo n.º 7
0
/* draw the gif file, based on the tentry desciption                    */
void draw_gif ( FILE * gif )
{
	#define c_blank 245,245,245	/* base colors */
	#define c_light 194,194,194
	#define c_dark 100,100,100
	#define c_black 0,0,0
	#define c_white 255,255,0
	#define c_blue 0,0,255
	#define c_red 255,0,0
	#define c_green 0,255,0

    gdImagePtr graph;
	int i_light,i_dark,i_blank, i_black, i_white, i_blue, i_red, i_green;

    graph = gdImageCreate(xsize, ysize);

    /* the first color allocated will be the background color. */
    i_blank = gdImageColorAllocate(graph,c_blank);
    i_light = gdImageColorAllocate(graph,c_light);
    i_dark = gdImageColorAllocate(graph,c_dark);

    gdImageInterlace(graph, 1); 

    i_black = gdImageColorAllocate(graph,c_black);
    i_white = gdImageColorAllocate(graph,c_white);
    i_red = gdImageColorAllocate(graph,c_red);
    i_green = gdImageColorAllocate(graph,c_green);
    i_blue = gdImageColorAllocate(graph,c_blue);

    /* draw the image border */
    gdImageLine(graph,0,0,xsize-1,0,i_light);
    gdImageLine(graph,1,1,xsize-2,1,i_light);
    gdImageLine(graph,0,0,0,ysize-1,i_light);
    gdImageLine(graph,1,1,1,ysize-2,i_light);
    gdImageLine(graph,xsize-1,0,xsize-1,ysize-1,i_dark);
    gdImageLine(graph,0,ysize-1,xsize-1,ysize-1,i_dark);
    gdImageLine(graph,xsize-2,1,xsize-2,ysize-2,i_dark);
    gdImageLine(graph,1,ysize-2,xsize-2,ysize-2,i_dark);

	{									/* date the graph */
		struct tm *newtime;
		time_t aclock;
		time( &aclock );				/* Get time in seconds */
		newtime = localtime( &aclock ); /* Convert time to struct */
										/* tm form */

		gdImageString(graph, gdFontSmall,gdFontSmall->w,3,asctime( newtime ),i_dark);
	};
	

	/*i_col = find_color(graph, colortable[pcurrententry->color]);
      gdImageFilledRectangle(graph,	
				pcurrententry->coords[0],
				pcurrententry->coords[1],
				pcurrententry->coords[2],
				pcurrententry->coords[3],i_col2);
	 }
	gdImageString(graph, gdFontSmall,
		pcurrententry->coords[0],
		pcurrententry->coords[1],
		pcurrententry->str,
		i_col );
	gdImageStringUp(graph, gdFontSmall,
		pcurrententry->coords[0],
		pcurrententry->coords[1],
		pcurrententry->str,
		i_col );


   gdImagePtr brush_2pix;
    brush_2pix = gdImageCreate(2,2);
	gdImageColorAllocate(
			brush_2pix,
			r(colortable[colorratetable[pcurrententry->rate]]),
			g(colortable[colorratetable[pcurrententry->rate]]),
			b(colortable[colorratetable[pcurrententry->rate]]) );
	gdImageSetBrush(graph, brush_2pix);
	i_col = gdBrushed;
	gdImageLine(graph,	x, y, x2, y2,i_col);
    gdImageDestroy(brush_2pix);*/

	/* draw axes and graphs */
	{
		int w = gdFontSmall->w, h = gdFontSmall->h, i, j, incrx, incry, maxio;
		char str[20];
		#define AXESX (distcount + 1)
		#define AXESY 6

		maxio = 0;
		for ( i = 0; i < distcount; i ++ ) {
			if (maxio < dist[i][0]) maxio = dist[i][0];
			if (maxio < dist[i][1]) maxio = dist[i][1];
		}
		
		incry = (ysize-(h*2)-(w*7))/(AXESY-1); incrx = (xsize-(w*9))/(AXESX-1);
		j = 100;
		for ( i = h*2; i <= ((h*2) + (incry * (AXESY-1))) ; i+= incry ) {
			gdImageLine(graph,w*7,i,w*7 + (incrx*(AXESX-1)),i,i_black); /* horizontal */
			sprintf ( str, "%3u%%", j ); j-= 100/(AXESY-1);
			gdImageString(graph, gdFontSmall,w,i-h/2,str,i_black );
			}
		j = 0;
		for ( i = w*7; i <= ((w*7) + (incrx * (AXESX-1))) ; i+= incrx ) {
			gdImageLine(graph,i,h*2,i,h*2 + (incry*(AXESY-1)),i_black); /* vertical */
			sprintf ( str, "%3u%%", j ); j+= (100/(AXESX-1));
			gdImageStringUp(graph, gdFontSmall, i - w/2, ysize - h, str, i_black );
		}


		for ( i = 0; i < distcount; i ++ ) {
			int x1, x2, y1, y2, mrgx;
			mrgx = incrx/5;

			x1 = (w*7) + (i*incrx) + mrgx;
			x2 = x1 + (incrx/3);
			y2 = h*2 + (incry*(AXESY-1)) - 2;
			y1 = y2 - (((ysize-(h*2)-(w*7) - 2) * dist[i][0]) / rounds);
			/* printf ( "x1 %u, y1 %u, x2 %u, y2 %u.\n", x1, y1, x2, y2 );*/
			gdImageFilledRectangle(graph, x1, y1, x2, y2,i_green);
			gdImageRectangle(graph, x1, y1, x2, y2,i_dark);

			x2 = (w*7) + ((i+1)*incrx) - mrgx;
			x1 = x2 - (incrx/3);
			y2 = h*2 + (incry*(AXESY-1)) - 2;
			y1 = y2 - (((ysize-(h*2)-(w*7) - 2) * dist[i][1]) / rounds);
			/* printf ( "x1 %u, y1 %u, x2 %u, y2 %u.\n", x1, y1, x2, y2 );*/
			gdImageFilledRectangle(graph, x1, y1, x2, y2,i_blue);
			gdImageRectangle(graph, x1, y1, x2, y2,i_dark);
		}
	}
	
    gdImageGif(graph, gif);    

    gdImageDestroy(graph);
}		
Exemplo n.º 8
0
/* draw the gif file */
void draw_distrib_gif ( FILE * score, FILE * gif )
{
	#define c_blank 245,245,245	/* base colors */
	#define c_light 194,194,194
	#define c_dark 100,100,100
	#define c_black 0,0,0
	#define c_white 255,255,0
	#define c_blue 0,0,255
	#define c_red 255,0,0
	#define c_green 0,255,0

    gdImagePtr graph;
	int i_light,i_dark,i_blank, i_black, i_white, i_blue, i_red, i_green;
	int color[4000][2];

    graph = gdImageCreate(xsize, ysize);

    /* the first color allocated will be the background color. */

    i_blank = gdImageColorAllocate(graph,c_blank);
    i_light = gdImageColorAllocate(graph,c_light);
    i_dark = gdImageColorAllocate(graph,c_dark);

    gdImageInterlace(graph, 1); 

    i_black = gdImageColorAllocate(graph,c_black);
    i_white = gdImageColorAllocate(graph,c_white);
    i_red = gdImageColorAllocate(graph,c_red);
    i_green = gdImageColorAllocate(graph,c_green);
    i_blue = gdImageColorAllocate(graph,c_blue);


	{ 
		int i;
		for (i = 0; i <= distcount; i++ ) {
			color[distcount - i - 1][0] = gdImageColorAllocate(graph, (255*i)/distcount, 255, (255*i)/distcount);
		}
		for (i = 0; i <= distcount; i++ ) {
			color[distcount - i - 1][1] = gdImageColorAllocate(graph, (255*i)/distcount, (255*i)/distcount, 255);
		}
	}


    /* draw the image border */
    gdImageLine(graph,0,0,xsize-1,0,i_light);
    gdImageLine(graph,1,1,xsize-2,1,i_light);
    gdImageLine(graph,0,0,0,ysize-1,i_light);
    gdImageLine(graph,1,1,1,ysize-2,i_light);
    gdImageLine(graph,xsize-1,0,xsize-1,ysize-1,i_dark);
    gdImageLine(graph,0,ysize-1,xsize-1,ysize-1,i_dark);
    gdImageLine(graph,xsize-2,1,xsize-2,ysize-2,i_dark);
    gdImageLine(graph,1,ysize-2,xsize-2,ysize-2,i_dark);

	{									/* date the graph */
		struct tm *newtime;
		time_t aclock;
		time( &aclock );				/* Get time in seconds */
		newtime = localtime( &aclock ); /* Convert time to struct */
										/* tm form */

		gdImageString(graph, gdFontSmall,gdFontSmall->w,3,asctime( newtime ),i_dark);
	};
	

	/*i_col = find_color(graph, colortable[pcurrententry->color]);
      gdImageFilledRectangle(graph,	
				pcurrententry->coords[0],
				pcurrententry->coords[1],
				pcurrententry->coords[2],
				pcurrententry->coords[3],i_col2);
	 }
	gdImageString(graph, gdFontSmall,
		pcurrententry->coords[0],
		pcurrententry->coords[1],
		pcurrententry->str,
		i_col );
	gdImageStringUp(graph, gdFontSmall,
		pcurrententry->coords[0],
		pcurrententry->coords[1],
		pcurrententry->str,
		i_col );


   gdImagePtr brush_2pix;
    brush_2pix = gdImageCreate(2,2);
	gdImageColorAllocate(
			brush_2pix,
			r(colortable[colorratetable[pcurrententry->rate]]),
			g(colortable[colorratetable[pcurrententry->rate]]),
			b(colortable[colorratetable[pcurrententry->rate]]) );
	gdImageSetBrush(graph, brush_2pix);
	i_col = gdBrushed;
	gdImageLine(graph,	x, y, x2, y2,i_col);
    gdImageDestroy(brush_2pix);*/

	/* draw axes and graphs */
	{
		int w = gdFontSmall->w, h = gdFontSmall->h, i, j, k, incrx, incry;
		char str[4000];
		int nbaxesx = (rate + 1);
		int nbaxesy = 6;
		int textx = 7;
		int texty = 15;

		incry = (ysize-(h*2)-(w*texty))/(nbaxesy-1); 
		incrx = (xsize-(w*(textx+2)))/(nbaxesx-1);
		j = 100;
		for ( i = h*2; i <= ((h*2) + (incry * (nbaxesy-1))) ; i+= incry ) {
			gdImageLine(graph,w*textx,i,w*textx + (incrx*(nbaxesx-1)),i,i_black); /* horizontal */
			sprintf ( str, "%3u%%", j ); j-= 100/(nbaxesy-1);
			gdImageString(graph, gdFontSmall,w,i-h/2,str,i_black );
			}
		j = 0;
		for ( i = w*7; i <= ((w*7) + (incrx * (nbaxesx-1))) ; i+= incrx ) {
			/*gdImageLine(graph,i,h*2,i,h*2 + (incry*(AXESY-1)),i_black);*/ /* vertical */
			/*sprintf ( str, "%3u%%", j ); j+= (100/(AXESX-1));
			gdImageStringUp(graph, gdFontSmall, i - w/2, ysize - h, str, i_black );*/
		}


		for ( i = 0; i < rate; i ++ ) {
			char *name,*ptr;
			int tin=0, tout=0;
			int x1, x2, y1, y2, mrgx;

			if ( fscanf ( score, "%s", str ) == EOF ) break;
			/*printf ( "%s\n", str );*/
			name = str;

			if ((ptr = strtok( str, ":")) == NULL) continue;
			/*printf ( "%s:", name );*/

			for ( j = 0; j < distcount; j++ ) {

				dist[j][0] = dist[j][0] = 0;
				
				if ((ptr = strtok( NULL, "/,")) == NULL) continue;
				dist[j][0] = atoi(ptr); tin += dist[j][0];
				
				if ((ptr = strtok( NULL, "/,")) == NULL) continue;
				dist[j][1] = atoi(ptr); tout += dist[j][1];

				/*printf ( "%u/%u,",dist[j][0],dist[j][1]  );*/
			}

			/*printf ( "\n" );*/

			/* draw label and graphs */
			mrgx = incrx/5;
			x1 = (w*textx) + (i*incrx) + (incrx/2) - (h/2);
			y1 = ysize-h;
			gdImageStringUp( graph, gdFontSmall, x1, y1, str, i_black );
			for (k = 0; k < 2; k ++ ) {
				y1 = ysize-((texty-4) * w);
				if ( k == 0 ) {
					x1 = (w*textx) + (i*incrx) + mrgx;
					x2 = x1 + (incrx/3);
					gdImageStringUp( graph, gdFontSmall, x1, y1, "in", i_black );
				} else {
					x2 = (w*textx) + ((i+1)*incrx) - mrgx;
					x1 = x2 - (incrx/3);
					gdImageStringUp( graph, gdFontSmall, x1, y1, "out", i_black );
				}

				y2 = h*2 + (incry*(nbaxesy-1));
				for ( j = distcount-1; j >=0 ; j-- ) {
					y1 = y2 - (((ysize-(h*2)-(w*texty) - 2) * dist[j][k]) / tin);
					if (j == 0) { /* 'correct' cumulative error */
						y1 = h*2;
					}
					gdImageFilledRectangle(graph, x1, y1, x2, y2,color[j][k]);
					gdImageRectangle(graph, x1, y1, x2, y2,i_black);
					y2 = y1;
				}
			}

			/*

			int x1, x2, y1, y2, mrgx;
			mrgx = incrx/5;

			x1 = (w*7) + (i*incrx) + mrgx;
			x2 = x1 + (incrx/3);
			y2 = h*2 + (incry*(AXESY-1)) - 2;
			y1 = y2 - (((ysize-(h*2)-(w*7) - 2) * dist[i][0]) / rounds);
			gdImageFilledRectangle(graph, x1, y1, x2, y2,i_green);
			gdImageRectangle(graph, x1, y1, x2, y2,i_dark);

			x2 = (w*7) + ((i+1)*incrx) - mrgx;
			x1 = x2 - (incrx/3);
			y2 = h*2 + (incry*(AXESY-1)) - 2;
			y1 = y2 - (((ysize-(h*2)-(w*7) - 2) * dist[i][1]) / rounds);
			gdImageFilledRectangle(graph, x1, y1, x2, y2,i_blue);
			gdImageRectangle(graph, x1, y1, x2, y2,i_dark);
			*/
		}
	}
	

    gdImageGif(graph, gif);    

    gdImageDestroy(graph);
}
Exemplo n.º 9
0
void GdImageRenderer::drawBorder() const
{
    gdImageRectangle(image_, 0, 0, image_width_ - 1, image_height_ - 1, border_color_);
}
Exemplo n.º 10
0
void borderPNG()
{
  gdImageRectangle(g_image, 92, 92, 576, 576, g_black);
}