Пример #1
0
int main()
{
	gdImagePtr im, im2;
	int error = 0;

	im = gdImageCreateTrueColor(5, 5);
	if (!im) {
		printf("can't create the src truecolor image\n");
		return 1;
	}

	gdImageFilledRectangle(im, 0, 0, 49, 49, 0x00FFFFFF);
	gdImageColorTransparent(im, 0xFFFFFF);
	gdImageFilledRectangle(im, 1, 1, 4, 4, 0xFF00FF);

	im2 = gdImageCreateTrueColor(20, 20);
	if (!im2) {
		printf("can't create the dst truecolor image\n");
		gdImageDestroy(im);
		return 1;
	}

	gdImageCopy(im2, im, 2, 2 , 0, 0, gdImageSX(im), gdImageSY(im));

	if (!gdAssertImageEqualsToFile("gdimagecopy/bug00081_exp.png", im2)) {
		error = 1;
		printf("Reference image and destination differ\n");
	}

	gdImageDestroy(im);
	gdImageDestroy(im2);
	return error;
}
Пример #2
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);
}
Пример #3
0
void plotDotPNG(int i, int j, double d)
{
  int x1, y1, x2, y2;
  double adjust;

  if (i < g_top || j < g_left || i >= g_top + g_size || j >= g_left + g_size)
    return;
  if (d <= 0)
    return;

  i -= (g_top - 1);
  j -= (g_left - 1);
  adjust = (1 - sqrt(d)) * (g_dotSize - 2) / 2;

  x1 = roundInt((j - 0.5) * g_dotSpacing) - g_dotSize / 2 + 92;
  y1 = roundInt((i - 0.5) * g_dotSpacing) - g_dotSize / 2 + 92;
  x2 = roundInt((j - 0.5) * g_dotSpacing) + g_dotSize / 2 + 92;
  y2 = roundInt((i - 0.5) * g_dotSpacing) + g_dotSize / 2 + 92;

  x1 += adjust;
  y1 += adjust;
  x2 -= adjust;
  y2 -= adjust;

  if (i == g_selectedI && j == g_selectedJ)
    gdImageFilledRectangle(g_image, x1, y1, x2, y2, g_gray);
  else
    gdImageFilledRectangle(g_image, x1, y1, x2, y2, g_colors[getColor(d)]);
}
Пример #4
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);
}
Пример #5
0
BGD_DECLARE(int) gdImagePixelate(gdImagePtr im, int block_size, const unsigned int mode)
{
	int x, y;

	if (block_size <= 0) {
		return 0;
	} else if (block_size == 1) {
		return 1;
	}
	switch (mode) {
	case GD_PIXELATE_UPPERLEFT:
		for (y = 0; y < im->sy; y += block_size) {
			for (x = 0; x < im->sx; x += block_size) {
				if (gdImageBoundsSafe(im, x, y)) {
					int c = gdImageGetPixel(im, x, y);
					gdImageFilledRectangle(im, x, y, x + block_size - 1, y + block_size - 1, c);
				}
			}
		}
		break;
	case GD_PIXELATE_AVERAGE:
		for (y = 0; y < im->sy; y += block_size) {
			for (x = 0; x < im->sx; x += block_size) {
				int a, r, g, b, c;
				int total;
				int cx, cy;

				a = r = g = b = c = total = 0;
				/* sampling */
				for (cy = 0; cy < block_size; cy++) {
					for (cx = 0; cx < block_size; cx++) {
						if (!gdImageBoundsSafe(im, x + cx, y + cy)) {
							continue;
						}
						c = gdImageGetPixel(im, x + cx, y + cy);
						a += gdImageAlpha(im, c);
						r += gdImageRed(im, c);
						g += gdImageGreen(im, c);
						b += gdImageBlue(im, c);
						total++;
					}
				}
				/* drawing */
				if (total > 0) {
					c = gdImageColorResolveAlpha(im, r / total, g / total, b / total, a / total);
					gdImageFilledRectangle(im, x, y, x + block_size - 1, y + block_size - 1, c);
				}
			}
		}
		break;
	default:
		return 0;
	}
	return 1;
}
Пример #6
0
static gdImagePtr InitImage(void)
{
    gdImagePtr im;

    im = gdImageCreate(150, 350);
    allocate_colors(im);
    gdImageColorTransparent (im, grey);
    gdImageFilledRectangle (im, 0, 0, 150, 350, grey);
    gdImageFilledRectangle (im, 50, 0, 150, 300, green);

    return im;
}
Пример #7
0
void doGene(FILE *stream) {
  int i, start, end, rstart, rend, y, strand, nsmall, nlarge, color;
  int *small, *large;

  start  = getNumber(stream);
  end    = getNumber(stream);
  y      = getNumber(stream);
  strand = getNumber(stream);	/* 0, 1, or -1 */
  color  = getNumber(stream);
  
  rstart = viewx(start);
  rend   = viewx(end);
  y      = viewy(y);

  // fprintf(stderr, "%d->%d, %d->%d\n", start, rstart, end, rend);

  gdImageLine(image, rstart, y, rend, y, color);
  if (strand == 1) {
    for (i = rstart+2; i < rend-2; i = i+5) {
      gdImageSetPixel(image, i, y-1, color);
      gdImageSetPixel(image, i-1, y-2, color);
      gdImageSetPixel(image, i, y+1, color);
      gdImageSetPixel(image, i-1, y+2, color);
    }
  } else if (strand == -1) {
    for (i = rstart+2; i < rend-2; i = i+5) {
      gdImageSetPixel(image, i, y-1, color);
      gdImageSetPixel(image, i+1, y-2, color);
      gdImageSetPixel(image, i, y+1, color);
      gdImageSetPixel(image, i+1, y+2, color);
    }
  }
  
  nsmall = getNumber(stream);
  for (i = 0; i < nsmall; i++) {
    start = getNumber(stream);
    end   = getNumber(stream);
    gdImageFilledRectangle(image, viewx(start), y-4, viewx(end), y+4, color);
  }

  nlarge = getNumber(stream);
  for (i = 0; i < nlarge; i++) {
    start = getNumber(stream);
    end   = getNumber(stream);
    // fprintf(stderr, "%d->%d, %d->%d\n", start, viewx(start), end, viewx(end));
    gdImageFilledRectangle(image, viewx(start), y-6, viewx(end), y+6, color);
  }
}
Пример #8
0
int main() {
    int method, i;

    for(method = GD_BELL; method <= GD_TRIANGLE; method++) {   /* GD_WEIGHTED4 is unsupported. */
        gdImagePtr im[2];

        // printf("Method = %d\n", method);
        im[0] = gdImageCreateTrueColor(X, Y);
        im[1] = gdImageCreatePalette(X, Y);

        for (i = 0; i < 2; i++) {
            gdImagePtr result;

            // printf("    %s\n", i == 0 ? "truecolor" : "palette");

            gdImageFilledRectangle(im[i], 0, 0, X-1, Y-1,
                                   gdImageColorExactAlpha(im[i], 255, 255, 255, 0));

            gdImageSetInterpolationMethod(im[i], method);
            gdTestAssert(im[i]->interpolation_id == method); /* No getter yet. */

            result = gdImageScale(im[i], NX, NY);
            gdTestAssert(result != NULL);
            gdTestAssert(result != im[i]);
            gdTestAssert(result->sx == NX && result->sy == NY);

            gdImageDestroy(result);
            gdImageDestroy(im[i]);
        }/* for */
    }/* for*/


    return gdNumFailures();
}/* main*/
void JBDungeonPainterGD::m_rectangle( int x1, int y1, int x2, int y2, long color, bool filled ) {
  if( filled ) {
    gdImageFilledRectangle( m_image, x1, y1, x2, y2, color );
  } else {
    gdImageRectangle( m_image, x1, y1, x2, y2, color );
  }
}
Пример #10
0
 void rectangle(const Point& point1, const Point& point2, const Color& color, bool filled)
 {
     if (filled)
         gdImageFilledRectangle(im_, SCALEX(point1.x), SCALEY(point1.y), SCALEX(point2.x), SCALEY(point2.y), color2gd(color));
     else    
         gdImageRectangle(im_, SCALEX(point1.x), SCALEY(point1.y), SCALEX(point2.x), SCALEY(point2.y), color2gd(color));
 }
Пример #11
0
int main()
{
	gdImagePtr im;
	FILE *fp;
	int cor_rad = 60;
	im = gdImageCreateTrueColor(400, 400);
	gdImageFilledRectangle(im, 0, 0, 399, 399, 0x00FFFFFF);

	gdImageFilledArc (im, cor_rad, 399 - cor_rad, cor_rad *2, cor_rad *2, 90, 180, 0x0, gdPie);

	fp = fopen("b.png", "wb");
	if (!fp) {
		fprintf(stderr, "Can't save png image.\n");
		gdImageDestroy(im);
		return 1;
	}
#ifdef HAVE_LIBPNG
	gdImagePng(im, fp);
#else
	printf("No PNG support. Cannot save image.\n");
#endif
	fclose(fp);

	gdImageDestroy(im);
	return 0;
}
Пример #12
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;
}
Пример #13
0
gdImagePtr rs_gdImageThickLineBrush(int line_weight, RS_Color& color)
{
    if (line_weight % 2 == 1)
        line_weight += 1;

    int sx = line_weight;
    int sy = line_weight;

    gdImagePtr brush = gdImageCreateTrueColor(sx, sy);
    int transparent = gdImageColorAllocateAlpha(brush, 0, 0, 0, 127);

    gdImageAlphaBlending(brush, 0);
    gdImageFilledRectangle(brush, 0, 0, sx, sy, transparent);

    //compute fractional alpha value for antialiasing effect
    //each pixel should be hit by line_weight / 2 number of circles
    //so the alpha is computed as 255 / line_weight * 2
    RS_Color falpha = color;
    falpha.alpha() = falpha.alpha() / line_weight * 2 + 1;
    falpha.alpha() = (falpha.alpha() < 255)? falpha.alpha() : 255;

    //outer transparent circle -- for antialiased effect
    rs_gdImageCircleForBrush(brush, sx/2, sy/2, line_weight / 2,  falpha);

    gdImageAlphaBlending(brush, 1);

    //inner non-transparent circle
    rs_gdImageCircleForBrush(brush, sx/2, sy/2, (line_weight - 2) / 2, color);

    return brush;
}
Пример #14
0
static void crop(Cmd *cmd) {
  char *buff = cmd->data;
  int len = cmd->size;
  Gd *gd = cmd->gd;
  int index = 0;
  long width, height;
  int srcW, srcH, srcX, srcY, destX, destY, playX, playY;
  gdImagePtr destination = NULL;
  
  ei_decode_version(buff, &index, NULL);
  ei_decode_tuple_header(buff, &index, NULL);
  ei_decode_long(buff, &index, &width);
  ei_decode_long(buff, &index, &height);
  
  if (NULL == gd->image) {
    driver_failure_atom(gd->port, "null_image");
    return;
  }
  
  srcW = gdImageSX(gd->image);
  srcH = gdImageSY(gd->image);
  
  destination = gdImageCreateTrueColor(width, height);
  if (NULL == destination) {
    driver_failure_posix(gd->port, ENOMEM);
    return;
  }
  gdImageFilledRectangle(destination, 0, 0, width, height, gdImageColorAllocate(destination, 255, 255, 255));
  destX = (width - srcW) / 2;
  destY = (height - srcH) / 2;
  gdImageCopy(destination, gd->image, destX, destY, 0, 0, srcW, srcH);
  gdImageDestroy(gd->image);
  gd->image = destination;
  send_atom(gd->port, "ok");
}
Пример #15
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();
}
Пример #16
0
int main()
{
 	gdImagePtr im, im2;
 	int error = 0;
	char path[2048];
	const char *file_exp = "bug00132_exp.png";
	char *ret = NULL;

	im = gdImageCreateTrueColor(50, 30);

	if (!im) {
		printf("can't get truecolor image\n");
		return 1;
	}

	gdImageAlphaBlending(im, 0);
	gdImageFilledRectangle(im, 0, 0, 200, 200, gdTrueColorAlpha(0, 0, 0, 127));

	sprintf(path, "%s/freetype/DejaVuSans.ttf", GDTEST_TOP_DIR);

	ret = gdImageStringFT(im, NULL,  - 0xFFFFFF, path, 14.0, 0.0, 10, 20, "&thetasym; &theta;");
	if (ret) {
		error = 1;
		printf(ret);
	} else {
		sprintf(path, "%s/freetype/%s", GDTEST_TOP_DIR, file_exp);
		if (!gdAssertImageEqualsToFile(path, im)) {
			error = 1;
			printf("Reference image and destination differ\n");
		}
	}
	gdImageDestroy(im);
	return error;
}
Пример #17
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);
}
Пример #18
0
static void init_gd()
{
	SP = 0;
	/* must create default background color first... */
	/* we have to force the background to be filled for some reason */
	white = gdImageColorResolve(im, gdRedMax,gdGreenMax,gdBlueMax);
	gdImageFilledRectangle(im, 0, 0, im->sx-1, im->sy-1, white);

	black = gdImageColorResolve(im, 0, 0, 0);

	/* in truecolor images we don't need to allocate a color
		for transparent */
	if (! im->trueColor) {
		/* transparent uses an rgb value very close to white
	   	so that formats like GIF that don't support
	   	transparency show a white background */
		transparent = gdImageColorResolveAlpha(im, gdRedMax,gdGreenMax,gdBlueMax-1, gdAlphaTransparent);
		gdImageColorTransparent(im, transparent);
	}

	cstk[0].pencolor = black;		/* set pen black*/
	cstk[0].fillcolor = black;		/* set fill black*/
	cstk[0].fontfam = "times";		/* font family name */
	cstk[0].fontopt = REGULAR;		/* modifier: REGULAR, BOLD or ITALIC */
	cstk[0].pen = P_SOLID;		/* pen pattern style, default is solid */
	cstk[0].fill = P_NONE;
	cstk[0].penwidth = WIDTH_NORMAL;
}
Пример #19
0
static  void
gd_bezier(point* A, int n, int arrow_at_start, int arrow_at_end)
{
	pointf		p0, p1, V[4];
	int		i, j, step;
	int		style[20]; 
	int		pen, width;
	gdImagePtr	brush = NULL;

	if (cstk[SP].pen != P_NONE) {
		if (cstk[SP].pen == P_DASHED) {
			for (i = 0; i < 10; i++)
				style[i] = cstk[SP].pencolor;
			for (; i < 20; i++)
				style[i] = gdTransparent;
			gdImageSetStyle(im, style, 20);
			pen = gdStyled;
		} else if (cstk[SP].pen == P_DOTTED) {
			for (i = 0; i < 2; i++)
				style[i] = cstk[SP].pencolor;
			for (; i < 12; i++)
				style[i] = gdTransparent;
			gdImageSetStyle(im, style, 12);
			pen = gdStyled;
		} else {
			pen = cstk[SP].pencolor;
		}
#if 0
                if (cstk[SP].penwidth != WIDTH_NORMAL) {
			width=cstk[SP].penwidth;
                        brush = gdImageCreate(width,width);
                        gdImagePaletteCopy(brush, im);
                        gdImageFilledRectangle(brush,
                           0,0,width-1, width-1, cstk[SP].pencolor);
                        gdImageSetBrush(im, brush);
			if (pen == gdStyled) pen = gdStyledBrushed;      
			else pen = gdBrushed;      
		}
#else
		width = cstk[SP].penwidth;
		gdImageSetThickness(im, width);
#endif
		V[3].x = A[0].x; V[3].y = A[0].y;
		for (i = 0; i+3 < n; i += 3) {
			V[0] = V[3];
			for (j = 1; j <= 3; j++) {
				V[j].x  = A[i+j].x; V[j].y = A[i+j].y;
			}
			p0 = gdpt(V[0]); 
			for (step = 1; step <= BEZIERSUBDIVISION; step++) {
				p1 = gdpt(Bezier(V, 3, (double)step/BEZIERSUBDIVISION, NULL, NULL));
				gdImageLine(im, ROUND(p0.x), ROUND(p0.y),
					ROUND(p1.x), ROUND(p1.y), pen);
				p0 = p1;
			}
		}
		if (brush)
			gdImageDestroy(brush);
	}
}
Пример #20
0
int main()
{
 	gdImagePtr im;
	const char *exp = "bug00077_exp.png";
	const int files_cnt = 4;
	FILE *fp;
	int i = 0;
	int error = 0;

	char path[1024];


	im = gdImageCreateTrueColor(11, 11);
	gdImageFilledRectangle(im, 0, 0, 10, 10, 0xFFFFFF);
	gdImageSetThickness(im, 1);

	gdImageLine(im, 0, 10, 0, 0, 0x0);
	gdImageLine(im, 5, 10, 5, 0, 0x0);
	gdImageLine(im, 10, 5, 0, 5, 0x0);
	gdImageLine(im, 10, 10, 0, 10, 0x0);

	sprintf(path, "%s/gdimageline/%s", GDTEST_TOP_DIR, exp);

	if (!gdAssertImageEqualsToFile(path, im)) {
		error = 1;
	}

	gdImageDestroy(im);

	return error;
}
Пример #21
0
int main()
{
	gdImagePtr im;
	int x, y, c;
	FILE *out;
	char path[1024];
	int r=0;


	im = gdImageCreateTrueColor(256, 256);
	gdImageAlphaBlending( im, gdEffectReplace );
	for (x=0; x<256; x++) {
		for (y=0; y<256; y++) {
			c = (y/2 << 24) + (x << 16) + (x << 8) + x;
			gdImageSetPixel(im, x, y, c );
		}
	}
	gdImageAlphaBlending( im, gdEffectOverlay );
	gdImageFilledRectangle(im, 0, 0, 255, 255, 0xff7f00);

	if (gdTrueColorGetGreen(gdImageGetPixel(im, 0, 128)) != 0x00) {
		r = 1;
	}
	if (gdTrueColorGetGreen(gdImageGetPixel(im, 128, 128)) != 0x80) {
		r = 1;
	}
	if (gdTrueColorGetGreen(gdImageGetPixel(im, 255, 128)) != 0xff) {
		r = 1;
	}
	gdImageDestroy(im);
	return r;
}
Пример #22
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;
}
Пример #23
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);
		}
	}
}
Пример #24
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;
}
Пример #25
0
void _fillrect(int x, int y, int width, int height)
{
    /* Don't draw this as backdrop is used */
#if 0
    int black = gdImageColorAllocate(framebuffer, 0, 0, 0);
    gdImageFilledRectangle(framebuffer, x, y, x+width, y+height, black);
#endif
}
Пример #26
0
static  void
gd_polyline(point* A, int n)
{
	pointf		p, p1;
	int		i;
	int		style[20];
	int		pen, width;
	gdImagePtr	brush = NULL;

	if (cstk[SP].pen != P_NONE) {
		if (cstk[SP].pen == P_DASHED) {
			for (i = 0; i < 10; i++)
				style[i] = cstk[SP].pencolor;
			for (; i < 20; i++)
				style[i] = gdTransparent;
			gdImageSetStyle(im, style, 20);
			pen = gdStyled;
		} else if (cstk[SP].pen == P_DOTTED) {
			for (i = 0; i < 2; i++)
				style[i] = cstk[SP].pencolor;
			for (; i < 12; i++)
				style[i] = gdTransparent;
			gdImageSetStyle(im, style, 12);
			pen = gdStyled;
		} else {
			pen = cstk[SP].pencolor;
		}
#if 0
                if (cstk[SP].penwidth != WIDTH_NORMAL) {
			width = cstk[SP].penwidth;
                        brush = gdImageCreate(width,width);
                        gdImagePaletteCopy(brush, im);
                        gdImageFilledRectangle(brush,
                           0,0,width-1,width-1,cstk[SP].pencolor);
                        gdImageSetBrush(im, brush);
			if (pen == gdStyled) pen = gdStyledBrushed;      
			else pen = gdBrushed;      
		}
#else
		width = cstk[SP].penwidth;
		gdImageSetThickness(im, width);
#endif
		p.x = A[0].x;
		p.y = A[0].y;
		p = gdpt(p);
		for (i = 1; i < n; i++) {
			p1.x = A[i].x;
			p1.y = A[i].y;
			p1 = gdpt(p1);
			gdImageLine(im, ROUND(p.x), ROUND(p.y),
				ROUND(p1.x), ROUND(p1.y), pen);
			p.x = p1.x;
			p.y = p1.y;
		}
		if (brush)
			gdImageDestroy(brush);
	}
}
Пример #27
0
static  void
gd_ellipse(point p, int rx, int ry, int filled)
{
	pointf		mp;
	int		i;
	int		style[40];  /* need 2* size for arcs, I don't know why */
	int		pen, width;
	gdImagePtr	brush = NULL;

	if (cstk[SP].pen != P_NONE) {
		if (cstk[SP].pen == P_DASHED) {
			for (i = 0; i < 20; i++)
				style[i] = cstk[SP].pencolor;
			for (; i < 40; i++)
				style[i] = gdTransparent;
			gdImageSetStyle(im, style, 40);
			pen = gdStyled;
		} else if (cstk[SP].pen == P_DOTTED) {
			for (i = 0; i < 2; i++)
				style[i] = cstk[SP].pencolor;
			for (; i < 24; i++)
				style[i] = gdTransparent;
			gdImageSetStyle(im, style, 24);
			pen = gdStyled;
		} else {
			pen = cstk[SP].pencolor;
		}
#if 1
		/* use brush instead of Thickness to improve outline appearance */
		gdImageSetThickness(im, WIDTH_NORMAL);
                if (cstk[SP].penwidth != WIDTH_NORMAL) {
			width = cstk[SP].penwidth;
                        brush = gdImageCreate(width,width);
                        gdImagePaletteCopy(brush, im);
                        gdImageFilledRectangle(brush,
                           0,0,width-1, width-1, cstk[SP].pencolor);
                        gdImageSetBrush(im, brush);
			if (pen == gdStyled) pen = gdStyledBrushed;      
			else pen = gdBrushed;      
		}
#else
		width = cstk[SP].penwidth;
		gdImageSetThickness(im, width);
#endif
		if (Rot) {int t; t = rx; rx = ry; ry = t;}
		mp.x = p.x; mp.y = p.y;
		mp = gdpt(mp);
		if (filled) {
			gdImageFilledEllipse(im, ROUND(mp.x), ROUND(mp.y),
				ROUND(Zoom*(rx + rx)), ROUND(Zoom*(ry + ry)),
				cstk[SP].fillcolor);
		}
		gdImageArc(im, ROUND(mp.x), ROUND(mp.y),
			ROUND(Zoom*(rx + rx)), ROUND(Zoom*(ry + ry)), 0, 360, pen);
		if (brush)
			gdImageDestroy(brush);
	}
}
Пример #28
0
static  void
gd_polygon(point *A, int n, int filled)
{
	pointf		p;
	int		i;
	gdPoint		*points;
	int		style[20];
	int		pen, width;
	gdImagePtr	brush = NULL;

	if (cstk[SP].pen != P_NONE) {
		if (cstk[SP].pen == P_DASHED) {
			for (i = 0; i < 10; i++)
				style[i] = cstk[SP].pencolor;
			for (; i < 20; i++)
				style[i] = gdTransparent;
			gdImageSetStyle(im, style, 20);
			pen = gdStyled;
		} else if (cstk[SP].pen == P_DOTTED) {
			for (i = 0; i < 2; i++)
				style[i] = cstk[SP].pencolor;
			for (; i < 12; i++)
				style[i] = gdTransparent;
			gdImageSetStyle(im, style, 12);
			pen = gdStyled;
		} else {
			pen = cstk[SP].pencolor;
		}
#if 1
		/* use brush instead of Thickness to improve end butts */
		gdImageSetThickness(im, WIDTH_NORMAL);
                if (cstk[SP].penwidth != WIDTH_NORMAL) {
			width=cstk[SP].penwidth * Zoom;
                        brush = gdImageCreate(width,width);
                        gdImagePaletteCopy(brush, im);
                        gdImageFilledRectangle(brush,
                           0,0,width-1, width-1, cstk[SP].pencolor);
                        gdImageSetBrush(im, brush);
			if (pen == gdStyled) pen = gdStyledBrushed;      
			else pen = gdBrushed;      
		}
#else
		width = cstk[SP].penwidth;
		gdImageSetThickness(im, width);
#endif
		points = N_GNEW(n,gdPoint);
		for (i = 0; i < n; i++) {
			p.x = A[i].x; p.y = A[i].y;
			p = gdpt(p);
			points[i].x = ROUND(p.x); points[i].y = ROUND(p.y);
		}
		if (filled) gdImageFilledPolygon(im, points, n, cstk[SP].fillcolor);
		gdImagePolygon(im, points, n, pen);
		free(points);
		if (brush)
			gdImageDestroy(brush);
	}
}
Пример #29
0
result_t Image::filledRectangle(int32_t x1, int32_t y1, int32_t x2, int32_t y2,
                                int32_t color)
{
    if (!m_image)
        return CHECK_ERROR(CALL_E_INVALID_CALL);

    gdImageFilledRectangle(m_image, x1, y1, x2, y2, color);
    return 0;
}
Пример #30
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);
}