Exemple #1
0
void titlePNG(char* title)
{
  char wordString[33];
  if (g_cutoffValue == 0)
    sprintf(wordString, "Filter: %s  Cutoff: none", g_filter ? "on" : "off");
  else
    sprintf(wordString, "Filter: %s  Cutoff: %g", g_filter ? "on" : "off", g_cutoffValue);

  gdImageString(g_image, gdFontMediumBold, 306 - 7 * strlen(title) / 2, 21, (unsigned char*) title, g_black);
  gdImageString(g_image, gdFontMediumBold, 306 - 7 * strlen(wordString) / 2, 51, (unsigned char*) wordString, g_black);
}
Exemple #2
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;
}
Exemple #3
0
static void drawbattcap(const char *battcaps, const char *minbchgs)
{
    gdImagePtr	    im;
    char	   batttxt[16];
    int 	   battpos;
    double	   battcap;
    int 	   minbchgpos;
    double	   minbchg;

    battcap = strtod(battcaps, NULL);
    minbchg = strtod(minbchgs, NULL);

    im = InitImage();

    DrawText(im, 0, 20);

    minbchgpos = (int)(300 - (minbchg * 3));
    gdImageFilledRectangle(im, 50, minbchgpos, 150, 300, red);

    battpos = (int)(300 - (battcap * 3));
    gdImageFilledRectangle(im, 75, battpos, 125, 300, black);

    (void) snprintf(batttxt, sizeof(batttxt), "%.1f %%", battcap);
    gdImageString(im, gdFontLarge, 70, 320, (unsigned char *)batttxt, black);

    TermImage(im);
}
Exemple #4
0
/* -------------------------------------------------------------------- */
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;
}
Exemple #5
0
static void drawruntime (const char *upsrunts, const char *lowbatts)
{
    gdImagePtr	    im;
    char	   utiltxt[16];
    int 	   uoutpos, lowbattpos;
    double	   upsrunt;
    double	   lowbatt;
    int step, maxt;

    upsrunt = strtod(upsrunts, NULL);
    lowbatt = strtod(lowbatts, NULL);

    im = InitImage();

    step = (int)(upsrunt + 4) / 5;
    if (step <= 0)
       step = 1;		   /* make sure we have a positive step */
    DrawText(im, 0, step);

    maxt = step * 5;
    uoutpos = 300 - (int)(upsrunt * 300 ) / maxt;
    lowbattpos = 300 - (int)(lowbatt * 300) / maxt;

    gdImageFilledRectangle(im, 50, lowbattpos, 150, 300, red);

    gdImageFilledRectangle(im, 75, uoutpos, 125, 300, black);

    (void) snprintf(utiltxt, sizeof(utiltxt), "%.1f mins", upsrunt);
    gdImageString(im, gdFontLarge, 65, 320, (unsigned char *)utiltxt, black); 
 
    TermImage(im);
}
Exemple #6
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;
}
Exemple #7
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;
}
Exemple #8
0
void piechart_caption(FILE *outf, choice rep, choice chartby, char **lngstr) {
  extern choice *rep2reqs, *rep2reqs7;
  extern unsigned int *method2sort;

  static char *caption = NULL;
  static size_t len = 0;

  choice requests = rep2reqs[G(rep)];
  choice requests7 = rep2reqs7[G(rep)];

  ENSURE_LEN(caption, len, strlen(lngstr[chartby_]) +
	     strlen(lngstr[method2sort[requests]]) +
	     strlen(lngstr[method2sort[requests7]]) +
	     strlen(lngstr[method2sort[chartby]]) + 3);
  /* More than we need, but that's OK. */
  strcpy(caption, lngstr[chartby_]);
  strcat(caption, " ");
  if (chartby == REQUESTS)
    strcat(caption, lngstr[method2sort[requests]]);
  else if (chartby == REQUESTS7)
    strcat(caption, lngstr[method2sort[requests7]]);
  else
    strcat(caption, lngstr[method2sort[chartby]]);
  strcat(caption, ".");
  if (normalchart) {
#ifdef EBCDIC
    (void)strtoascii(caption);
#endif
    gdImageString(im, font, CAPTIONLEFT, CAPTIONTOP, (unsigned char *)caption,
		  black);
  }
  else
    fprintf(outf, "<p><em>%s</em></p>\n", caption);
}
Exemple #9
0
void _BptDrawWorker(gdImagePtr im, LPBPTREE bpt, LPBTNODE node, int level, int index, int xpos) {
	unsigned int i;
	LPBTLEAF leaf;
	LPBTNODE child;
	int x1, x2, y1, y2, newxpos;
	char buf[32];

	if (node->nitems & BT_LEAF) {
		leaf = (LPBTLEAF)node;

		x1 = xpos - LEAF_CX / 2;
		x2 = xpos + LEAF_CX / 2;

		y1 = level * 45 + 15;
		y2 = y1 + LEAF_CY;

		gdImageFilledRectangle(im, x1, y1, x2, y2, bgcolor);
		for (i = 0; i != BTNITEMS(leaf); i++) {
			sprintf(buf, "%f, %d", leaf->items[i].key, leaf->items[i].val);
			gdImageString(im, gdFontGetTiny(), x1 + 2, y1 + i * 12, (unsigned char *)buf, fgcolor);
		}
	} else {
		x1 = xpos - (node->nitems * 16) / 2;
		x2 = xpos + (node->nitems * 16) / 2;

		y1 = level * 45 + 15;
		y2 = y1 + NODE_CY / 2;
		y1 -= NODE_CY / 2;

		gdImageFilledRectangle(im, x1, y1, x2, y2, bgcolor);
		for (i = 0; i != node->nitems; i++) {
			sprintf(buf, "%f|", node->keys[i]);
			gdImageString(im, gdFontGetTiny(), x1 + 16 * i + 1, y1 + 2, (unsigned char *)buf, fgcolor);
		}

		level++;
		for (i = 0; i != node->nitems + 1; i++) {
			child = (LPBTNODE)(bpt->baseaddr + node->choffs[i]);
			if (child->nitems & BT_LEAF)
				newxpos = xpos + (int)(((float)i - (float)node->nitems / 2.f) * NODE_CX);
			else
				newxpos = xpos + (int)(((float)i - (float)node->nitems / 2.f) * NODE_CX * ((float)35 / (float)(level * 2))); 
			gdImageLine(im, x1 + i * 16, y2, newxpos, level * 45 + 15, fgcolor);
			_BptDrawWorker(im, bpt, child, level, i, newxpos);
		}
	}
}
void GdImageRenderer::drawTimeAxisLabels() const
{
    const int marker_height = 10;

    // Time interval between axis markers (seconds)
    const int axis_label_interval_secs = getAxisLabelScale();

    // Time of first axis marker (seconds)
    const int first_axis_label_secs = MathUtil::roundUpToNearest(start_time_, axis_label_interval_secs);

    // Distance between waveform start time and first axis marker (seconds)
    const double axis_label_offset_secs = first_axis_label_secs - start_time_;

    // Distance between waveform start time and first axis marker (samples)
    const int axis_label_offset_samples = secondsToSamples(axis_label_offset_secs);

    // Distance between waveform start time and first axis marker (pixels)
    const int axis_label_offset_pixels = axis_label_offset_samples / samples_per_pixel_;

    assert(axis_label_offset_pixels >= 0);

    gdFontPtr font = gdFontGetSmall();

    int secs = first_axis_label_secs;

    for (;;) {
        const int x = axis_label_offset_pixels +
            (secs - first_axis_label_secs) * sample_rate_ / samples_per_pixel_;

        assert(x >= 0);

        if (x >= image_width_) {
            break;
        }

        gdImageLine(image_, x, 0, x, marker_height, border_color_);
        gdImageLine(image_, x, image_height_ - 1, x, image_height_ - 1 - marker_height, border_color_);

        char label[50];
        const int label_length = TimeUtil::secondsToString(label, ARRAY_LENGTH(label), secs);

        const int label_width = font->w * label_length;
        const int label_x = x - (label_width / 2) + 1;
        const int label_y = image_height_ - 1 - marker_height - 1 - font->h;

        if (label_x >= 0) {
            gdImageString(
                image_,
                font,
                label_x,
                label_y,
                reinterpret_cast<unsigned char*>(label),
                axis_label_color_
            );
        }

        secs += axis_label_interval_secs;
    }
}
Exemple #11
0
void _putsxy(int x, int y, const unsigned char *str)
{
    struct viewport_api avp;
    int black = gdImageColorAllocate(framebuffer, 0, 0, 0);
    
    api.get_current_vp(&avp);
    
    gdImageString(framebuffer, getFont(), x + avp.x, y + avp.y - avp.fontheight, (unsigned char*)str, black);
}
int renderBitmapGlyphsGD(imageObj *img, double x, double y, labelStyleObj *style, char *text)
{
    int size = MS_NINT(style->size);
    gdFontPtr fontPtr;
    gdImagePtr ip;
    int numlines=0,t;
    char **lines;
    if(!(ip = MS_IMAGE_GET_GDIMAGEPTR(img))) return MS_FAILURE;
    if(size<0 || size>4 || (fontPtr = msGetBitmapFont(size))==NULL) {
        msSetError(MS_RENDERERERR,"invalid bitmap font size", "renderBitmapGlyphsGD()");
        return MS_FAILURE;
    }

    SETPEN(ip, style->color);
    SETPEN(ip, style->outlinecolor);

    if(msCountChars(text,'\n')) {
        if((lines = msStringSplit((const char*)text, '\n', &(numlines))) == NULL)
            return(-1);
    } else {
        lines = &text;
        numlines = 1;
    }

    y -= fontPtr->h;
    for(t=0; t<numlines; t++) {
        if(style->outlinewidth > 0) {
            gdImageString(ip, fontPtr, x, y-1,   (unsigned char *) lines[t], style->outlinecolor->pen);
            gdImageString(ip, fontPtr, x, y+1,   (unsigned char *) lines[t], style->outlinecolor->pen);
            gdImageString(ip, fontPtr, x+1, y,   (unsigned char *) lines[t], style->outlinecolor->pen);
            gdImageString(ip, fontPtr, x-1, y,   (unsigned char *) lines[t], style->outlinecolor->pen);
            gdImageString(ip, fontPtr, x+1, y-1, (unsigned char *) lines[t], style->outlinecolor->pen);
            gdImageString(ip, fontPtr, x+1, y+1, (unsigned char *) lines[t], style->outlinecolor->pen);
            gdImageString(ip, fontPtr, x-1, y-1, (unsigned char *) lines[t], style->outlinecolor->pen);
            gdImageString(ip, fontPtr, x-1, y+1, (unsigned char *) lines[t], style->outlinecolor->pen);
        }
        if(style->color->pen != -1) {
            gdImageString(ip, fontPtr, x, y, (unsigned char *) lines[t], style->color->pen);
        }

        y += fontPtr->h; /* shift down */
    }


    if(lines != &text)
        msFreeCharArray(lines, numlines);
    return MS_SUCCESS;
}
Exemple #13
0
void vertCenterPNG(char* str, int i)
{
  int x, y;

  i -= (g_top - 1);

  x = 92 - 7 * strlen(str);
  y = 92 + roundInt((i - 0.5) * g_dotSpacing - 6.5);

  gdImageString(g_image, gdFontMediumBold, x, y, (unsigned char*) str, g_black);
}
Exemple #14
0
static void print_string(gdImagePtr im, int x, int y, const char *str)
{
    gdFontPtr font = gdFontGetGiant();

    x -= (10 + strlen(str)*font->w);
    gdImageFilledRectangle(im, x-1, y, 
                           x+strlen(str)*font->w, 
                           y+font->h, 0x0);
    gdImageString(im, font, x, y, (unsigned char *)str, 0x00FFFFFF);

}
Exemple #15
0
void Gd::drawString(int x, int y, const char* str, int color, FontStyle style)
{
  gdFontPtr font = style == FontTiny    ? gdFontGetTiny()
                 : style == FontSmall   ? gdFontGetSmall()
                 : style == FontMedium  ? gdFontGetMediumBold()
                 : style == FontLarge   ? gdFontGetLarge()
                 : style == FontGiant   ? gdFontGetGiant()
                 : gdFontGetMediumBold();

  gdImageString(_imagePtr, font, x, y, const_cast<unsigned char*>(reinterpret_cast<const unsigned char*>(str)), color);
}
Exemple #16
0
void horzCenterPNG(char* str, int j)
{
  int x, y;

  j -= (g_left - 1);

  y = 92 - 13;
  x = 92 + roundInt((j - 0.5) * g_dotSpacing) - 7 * strlen(str) / 2;

  gdImageString(g_image, gdFontMediumBold, x, y, (unsigned char*) str, g_black);
}
Exemple #17
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;
}
Exemple #18
0
static void DrawText(gdImagePtr im, int min, int step)
{
    int next;
    char text[10];

    next = min;
    (void) snprintf(text, sizeof(text), "%d", next);
    gdImageString(im, gdFontLarge, 0, 295, (unsigned char *)text, black);

    next += step;
    (void) snprintf(text, sizeof(text), "%d", next);
    gdImageString(im, gdFontLarge, 0, 235, (unsigned char *)text, black);

    next += step;
    (void) snprintf(text, sizeof(text), "%d", next);
    gdImageString(im, gdFontLarge, 0, 175, (unsigned char *)text, black);

    next += step;
    (void) snprintf(text, sizeof(text), "%d", next);
    gdImageString(im, gdFontLarge, 0, 115, (unsigned char *)text, black);

    next += step;
    (void) snprintf(text, sizeof(text), "%d", next);
    gdImageString(im, gdFontLarge, 0, 55, (unsigned char *)text, black);

    next += step;
    (void) snprintf(text, sizeof(text), "%d", next);
    gdImageString(im, gdFontLarge, 0, 0, (unsigned char *)text, black);
}
Exemple #19
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;
}
Exemple #20
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;
    
}
Exemple #21
0
    void string(const std::string& text, const Point& point, const Color& color, Size size, int align)
    {
        // copy text into gd-friendly (unsigned char) buffer

        vector<unsigned char> buffer;
        copy(text.begin(), text.end(), back_inserter(buffer));
        buffer.push_back('\0');

        // choose font

        gdFontPtr font;
        switch (size)
        {
        case Tiny:
            font = gdFontGetTiny();
            break;
        case Small:
            font = gdFontGetSmall();
            break;
        case MediumBold:
            font = gdFontGetMediumBold();
            break;
        case Large:
            font = gdFontGetLarge();
            break;
        case Giant:
            font = gdFontGetGiant();
            break;
        default:
            throw runtime_error("[ImageImpl::string()] This isn't happening.");
        }

        // calculate position

        Point position = point;
        int length = (int)text.size() * font->w;
        int height = font->h;

        if (align & CenterX) position.x -= length/2;
        else if (align & Right) position.x -= length;

        if (align & CenterY) position.y -= height/2;
        else if (align & Bottom) position.y -= height;

        // draw the string

        gdImageString(im_, font, position.x, position.y, &buffer[0], color2gd(color));
    }
Exemple #22
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;
}
Exemple #23
0
/*
 * Input Voltage */
static void drawutility (const char *utilitys, const char *translos,
    const char *transhis) 
{
    gdImagePtr	    im;
    char	   utiltxt[16];
    int 	   utilpos, translopos, transhipos;
    double	   utility, translo, transhi;
    int 	   minv, deltav;

    utility = strtod(utilitys, NULL);
    translo = strtod(translos, NULL);
    transhi = strtod(transhis, NULL);

    im = InitImage();

    if (utility > 180) {	      /* Europe 230V */
       minv = 200;
       deltav = 75;
    } else if (utility > 110) {       /* US 110-120 V */
       minv = 90;
       deltav = 50;
    } else if (utility > 95) {	      /* Japan 100V */
       minv = 80;
       deltav = 50;
    } else {			      /* No voltage */
       minv = 0;
       deltav = 50;
    }

    DrawText(im, minv, deltav/5);
    utilpos = (int)(300 - (((utility - minv) / deltav) * 300) );
    translopos = (int)(300 - (((translo - minv) / deltav) * 300) );
    transhipos = (int)(300 - (((transhi - minv) / deltav) * 300) );

    gdImageFilledRectangle(im, 50, 0, 150, transhipos, red);
    gdImageFilledRectangle(im, 50, translopos, 150, 300, red);

    gdImageFilledRectangle (im, 75, utilpos, 125, 300, black);

    (void) snprintf (utiltxt, sizeof(utiltxt), "%.1f VAC", utility);
    gdImageString (im, gdFontLarge, 65, 320, (unsigned char *)utiltxt, black); 

    TermImage(im);
}
Exemple #24
0
Fichier : GD.c Projet : drudru/cel
void GDstringwithFontXYColor(void)
{
    Proto  proto;
    Proto  tmp;
    Proto  blob;
    Proto  strObj;
    gdImagePtr imgPtr;
    gdFontPtr  fntPtr;
    char * p;
    int    x1,y1;
    int    font;
    int    index;
    char * buff;
    
    proto = (Proto) stackAt(Cpu, 2);

    objectGetSlot(proto, stringToAtom("_gdp"), &blob);
    p = (char *) objectPointerValue(blob);
    memcpy(&imgPtr, p, sizeof(imgPtr));
    
    tmp = (Proto) stackAt(Cpu, 4);
    strObj = tmp;

    tmp = (Proto) stackAt(Cpu, 5);
    font= objectIntegerValue(tmp);
    fntPtr = getFontPtr(font);

    tmp = (Proto) stackAt(Cpu, 6);
    x1 = objectIntegerValue(tmp);

    tmp = (Proto) stackAt(Cpu, 7);
    y1 = objectIntegerValue(tmp);

    tmp = (Proto) stackAt(Cpu, 8);
    index = objectIntegerValue(tmp);

    buff = string2CString(strObj);
    gdImageString(imgPtr, fntPtr, x1, y1, buff, index);
    celfree(buff);
    
    VMReturn(Cpu, (unsigned int) proto, 8);
}
Exemple #25
0
void gdoTextR(struct ADrawTag *ctx,
              unsigned int     x,
              unsigned int     y,
              const char      *string)
{
    GdoContext *context = getGdoCtx(ctx);

    gdImageFilledRectangle(getGdoImg(ctx),
                           x,
                           y - (gdoTextHeight(ctx) - 1),
                           x + gdoTextWidth(ctx, string),
                           y - 3,
                           context->colour[ADRAW_COL_WHITE]);

    gdImageString(getGdoImg(ctx),
                  getGdoCtx(ctx)->font,
                  x,
                  y - gdoTextHeight(ctx),
                  (char *)string,
                  getGdoPen(ctx));
}
Exemple #26
0
void doString(FILE *stream) {
  float x, y;
  int a, c;
  gdPoint size, point;

  x = getFloat(stream);
  y = getFloat(stream);
  c = getColor(getNumber(stream));
  a = getNumber(stream);
  getLine(stream);

  if (currentFontIdx == 0) {
    gdImageStringFT(image, NULL, c, currentFontFT, 10.0, 0.0, viewx(x), viewy(y), buffer);
  } else {
    size = stringSize(buffer, currentFontIdx);
    point.x = viewx(x);
    point.y = viewy(y);
    point = stringAnchor(point, size, a, 0);
    gdImageString(image, currentFont, point.x, point.y, buffer, c);
  }
}
Exemple #27
0
static void noimage (void)
{
    gdImagePtr	    im;

    im = gdImageCreate (150, 350);

    allocate_colors(im);

    gdImageColorTransparent (im, grey);

    gdImageFilledRectangle (im, 0, 0, 150, 300, grey);

    gdImageString (im, gdFontLarge, 0, 0, (unsigned char *)"Data not available", black);

    imgheader();
#ifdef SYS_IMGFMT_PNG
    gdImagePng (im, stdout);
#else
    gdImageGif (im, stdout);
#endif
    gdImageDestroy (im);
}
Exemple #28
0
/*
 * Output Voltage
 */
static void drawupsout (const char *upsouts) 
{
    gdImagePtr	    im;
    char	   utiltxt[16];
    int 	   uoutpos;
    double	   upsout;
    int 	   minv, deltav;

    upsout = strtod(upsouts, NULL);

    im = InitImage();

    if (upsout > 180) {
       minv = 200;
       deltav = 75;
    } else if (upsout > 110) {
       minv = 90;
       deltav = 50;
    } else if (upsout > 95) {
       minv = 80;
       deltav = 50;
    } else {
       minv = 0;
       deltav = 50;
    }
    
    DrawText(im, minv, deltav/5);
    uoutpos = (int)(300 - (((upsout - minv) / deltav) * 300) );

    gdImageFilledRectangle(im, 75, uoutpos, 125, 300, black);

    (void) snprintf(utiltxt, sizeof(utiltxt), "%.1f VAC", upsout);
    gdImageString(im, gdFontLarge, 65, 320, (unsigned char *)utiltxt, black); 

    TermImage(im);
}
Exemple #29
0
static void drawupsload(const char *upsloads) 
{
    gdImagePtr	    im;
    char	   loadtxt[16];
    int 	   loadpos;
    double	   upsload;

    upsload = strtod(upsloads, NULL);

    im = InitImage();

    DrawText(im, 0, 25);

    gdImageFilledRectangle (im, 50, 0, 150, 60, red);
    gdImageFilledRectangle (im, 50, 60, 150, 300, green); 

    loadpos = (int)(300 - ((upsload / 125) * 300));
    gdImageFilledRectangle(im, 75, loadpos, 125, 300, black);

    (void) snprintf(loadtxt, sizeof(loadtxt), "%.1f %%", upsload);
    gdImageString(im, gdFontLarge, 70, 320, (unsigned char *)loadtxt, black);

    TermImage(im);
}
Exemple #30
0
/*********************************************************************//*!
 * @brief Query the current state of the application and see what else
 * we need to get from it
 *
 * Depending on the current state of the application, other additional
 * parameters may be queried.
 *
 * @return SUCCESS or an appropriate error code otherwise
 *//*********************************************************************/
static OSC_ERR QueryApp()
{
	OSC_ERR err;

	/* First, get the current state of the algorithm. */
	err = OscIpcGetParam(cgi.ipcChan, &cgi.appState, GET_APP_STATE, sizeof(struct APPLICATION_STATE));
	if (err != SUCCESS)
	{
		/* This request is defined in all states, and thus must succeed. */
		OscLog(ERROR, "CGI: Error querying application! (%d)\n", err);
		return err;
	}

	switch(cgi.appState.enAppMode)
	{
	case APP_OFF:
		/* Algorithm is off, nothing else to do. */
		break;
	case APP_CAPTURE_ON:
		if (cgi.appState.bNewImageReady)
		{
			FILE* F;
			uint16 r,c;
			uint8* pData;
			uint32 dataSiz, i;
			uint16 oType;

			/* If there is a new image ready, request it from the application. */
			/* We get TWICE the size of an image because metadata might be available */
			err = OscIpcGetParam(cgi.ipcChan, cgi.imgBuf, GET_NEW_IMG, NUM_COLORS*nc*nr*2);
			if (err != SUCCESS)
			{
				OscLog(DEBUG, "CGI: Getting new image failed! (%d)\n", err);
				return err;
			}
//we have to take care of the different ways gdlib treats gray and color data
#if NUM_COLORS == 1
			//create gd image and ...
			gdImagePtr im_out =  gdImageCreate(nc, nr);
			//initialize with sensor image
			for(r = 0; r < nr; r++)
			{
				//in case the original image should not be modified replace the following loop by the memcpy statement
				//memcpy(im_out->pixels[r], cgi.imgBuf+r*nc, nc*sizeof(uint8));
				for(c = 0; c < nc; c++)
				{
					im_out->pixels[r][c] = (*(cgi.imgBuf+r*nc+c) & 0xfe);//mask out first bit -> only even gray values
				}
			}
			//allocate color palette (255 is red -> we did not change the sensor image!! should rather use a LUT)
			for(c = 0; c < 256; c++)
			{
				if((c%2) && c > 255-2*MAX_NUM_COLORS){
					i = (255-c)/2;
					gdImageColorAllocate (im_out, colorLUT[i][0], colorLUT[i][1], colorLUT[i][2]);
				} else {
					gdImageColorAllocate (im_out, c, c, c);
				}
			}
#else
			//create gd image and ...
			gdImagePtr im_out =  gdImageCreateTrueColor(nc, nr);
			//initialize with sensor image
			for(r = 0; r < nr; r++)
			{
				for(c = 0; c < nc; c++)
				{
					uint8* p = (cgi.imgBuf+r*3*nc+3*c);
					im_out->tpixels[r][c] = gdTrueColor(p[2], p[1], p[0]);
				}
			}


#endif
			//there might be additional data to be written to image
			pData = (uint8*) (cgi.imgBuf+NUM_COLORS*nc*nr);
			memcpy(&dataSiz, pData, sizeof(uint32));
			//OscLog(DEBUG, "received %d number of bytes\n", dataSiz);
			pData += sizeof(uint32);//skip dataSiz
			if(dataSiz)
			{
				i = 0;
				while(i < dataSiz)
				{
					memcpy(&oType, pData+i, sizeof(uint16));
					i += sizeof(uint16);
					switch(oType) {
						case OBJ_LINE:
						{
							struct IMG_LINE imgLine;
							memcpy(&imgLine, pData+i, sizLine);
							i += sizLine;
							//OscLog(DEBUG, "received line (%d,%d)-(%d,%d), color(%d)\n", imgLine.x1, imgLine.y1, imgLine.x2, imgLine.y2, (int) imgLine.color);
							gdImageLine(im_out, imgLine.x1, imgLine.y1, imgLine.x2, imgLine.y2, colorLoolUp(imgLine.color));
							break;
						}
						case OBJ_RECT:
						{
							struct IMG_RECT imgRect;
							memcpy(&imgRect, pData+i, sizRect);
							i += sizRect;
							//OscLog(DEBUG, "received rect (%d,%d)-(%d,%d), %s, color(%d)\n", imgRect.left, imgRect.bottom, imgRect.right, imgRect.top, imgRect.recFill ? "fill" : "not fill", (int) imgRect.color);
							if(imgRect.recFill) {
								gdImageFilledRectangle(im_out, imgRect.left, imgRect.bottom, imgRect.right, imgRect.top, colorLoolUp(imgRect.color));
							} else {
								gdImageRectangle(im_out, imgRect.left, imgRect.bottom, imgRect.right, imgRect.top, colorLoolUp(imgRect.color));
							}
							break;
						}
						case OBJ_STRING:
						{
							gdFontPtr font = gdFontSmall;
							struct IMG_STRING imgString;
							memcpy(&imgString, pData+i, sizString);
							i += sizString;
							//OscLog(DEBUG, "received string (%d,%d), font %d, %s, color(%d)\n", imgString.xPos, imgString.yPos, imgString.font, pData+i, imgString.color);
							switch(imgString.font)
							{
								case GIANT:
									font = gdFontGiant;
									break;
								case LARGE:
									font = gdFontLarge;
									break;
								case MEDIUMBOLD:
									font = gdFontMediumBold;
									break;
								case SMALL:
									font = gdFontSmall;
									break;
								case TINY:
									font = gdFontTiny;
									break;
								default:
									break;//set in definition of font
							}
							gdImageString(im_out, font, imgString.xPos, imgString.yPos, pData+i, colorLoolUp(imgString.color));
							i += imgString.len;
						}
					}
				}
			}

			F = fopen(IMG_FN, "wb");
			//gdImageGif(im_out, F);
			gdImageJpeg(im_out, F, 80);
			fclose(F);
			gdImageDestroy(im_out);

			return SUCCESS;
		}
		break;
	default:
		OscLog(ERROR, "%s: Invalid application mode (%d)!\n", __func__, cgi.appState.enAppMode);
		break;
	}
	return SUCCESS;
}