Пример #1
0
static void vrml_begin_node(GVJ_t *job)
{
    FILE *out = job->output_file;
    obj_state_t *obj = job->obj;
    node_t *n = obj->u.n;
    double z = obj->z;
    int width, height;
    int transparent;

    fprintf(out, "# node %s\n", n->name);
    if (z < MinZ)
	MinZ = z;
    if (shapeOf(n) != SH_POINT) {
	PNGfile = nodefile(job->output_filename, n);

	width  = (ND_lw_i(n) + ND_rw_i(n)) * Scale + 2 * NODE_PAD;
	height = (ND_ht_i(n)             ) * Scale + 2 * NODE_PAD;
	im = gdImageCreate(width, height);

	/* make background transparent */
	transparent = gdImageColorResolveAlpha(im,
                                           gdRedMax - 1, gdGreenMax,
                                           gdBlueMax, gdAlphaTransparent);
	gdImageColorTransparent(im, transparent);
    }
}
Пример #2
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;
}
Пример #3
0
int
main (int argc, char *argv[])
{
#ifdef HAVE_LIBFREETYPE
  	FILE *out;
	int transparent, green, black;
	gdImagePtr im;

	im = gdImageCreateTrueColor(100,100);

        black =  gdImageColorResolveAlpha(im, 0, 0, 0, gdAlphaOpaque);
        green =  gdImageColorResolveAlpha(im, 0, gdGreenMax, 0, gdAlphaOpaque);
        transparent = gdImageColorResolveAlpha(im,
                        gdRedMax-1, gdGreenMax, gdBlueMax, gdAlphaTransparent);
        gdImageColorTransparent(im, transparent);

	/* Blending must be off to lay a transparent basecolor.
                Nothing to blend with anyway. */
        gdImageAlphaBlending(im, FALSE);
        gdImageFill (im, im->sx/2, im->sy/2, transparent);
        /* Blend everything else together,
                especially fonts over non-transparent backgrounds */
        gdImageAlphaBlending(im, TRUE);

	gdImageFilledRectangle (im, 30, 30, 70, 70, green);
	gdImageStringFT (im, NULL, black, "Times", 18, 0, 50, 50, "Hello");

	gdImageSaveAlpha (im, TRUE);
#ifdef HAVE_LIBPNG
	out = fopen ("testtr.png", "wb");
	gdImagePng (im, out);
	fclose (out);
#else
	fprintf(stderr, "Compiled without libpng support\n");
#endif /* HAVE_LIBPNG */
	gdImageDestroy (im);

	return 0;
#else
	fprintf(stderr, "Compiled without freetype support\n");
	return 0;
#endif /* HAVE_LIBFREETYPE */
}
Пример #4
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;
}
Пример #5
0
static void init2_gd(gdImagePtr im)
{
    SP = 0;

    white = gdImageColorResolveAlpha(im,
                                     gdRedMax, gdGreenMax, gdBlueMax,
                                     gdAlphaOpaque);
    black = gdImageColorResolveAlpha(im, 0, 0, 0, gdAlphaOpaque);
    transparent = gdImageColorResolveAlpha(im,
                                           gdRedMax - 1, gdGreenMax,
                                           gdBlueMax, gdAlphaTransparent);
    gdImageColorTransparent(im, transparent);

    cstk[0].pencolor = black;	/* set pen 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;
}
Пример #6
0
result_t Image::colorResolveAlpha(int32_t red, int32_t green, int32_t blue,
                                  double alpha, int32_t &retVal)
{
    if (!m_image)
        return CHECK_ERROR(CALL_E_INVALID_CALL);

    if (red < 0 || red > 255 || green < 0 || green > 255 || blue < 0
            || blue > 255 || alpha < 0 || alpha > 1)
        return CHECK_ERROR(CALL_E_INVALIDARG);

    retVal = gdImageColorResolveAlpha(m_image, red, green, blue, doubleToInt(alpha * 127));
    return 0;
}
Пример #7
0
static int color_index(gdImagePtr im, gvcolor_t color)
{
    int alpha;

    /* convert alpha (normally an "opacity" value) to gd's "transparency" */
    alpha = (255 - color.u.rgba[3]) * gdAlphaMax / 255;

    if(alpha == gdAlphaMax)
        return (gdImageGetTransparent(im));
    else
        return (gdImageColorResolveAlpha(im,
		    color.u.rgba[0],
		    color.u.rgba[1],
		    color.u.rgba[2],
		    alpha));
}
Пример #8
0
static int gd_resolve_color(char *name)
{
    gvcolor_t color;

    if (!(strcmp(name, "transparent"))) {
        /* special case for "transparent" color */
        return transparent;
    } else {
        colorxlate(name, &color, RGBA_BYTE);
        /* seems gd alpha is "transparency" rather than the usual "opacity" */
        return gdImageColorResolveAlpha(im,
                                        color.u.rgba[0],
                                        color.u.rgba[1],
                                        color.u.rgba[2],
                                        (255 -
                                         color.u.rgba[3]) * gdAlphaMax /
                                        255);
    }
}
Пример #9
0
int main()
{
	gdImagePtr im;
	int error = 0;
	int c, c1, c2, c3, c4, color, i;

	im = gdImageCreateTrueColor(5, 5);
	c = gdImageColorResolve(im, 255, 0, 255);
	c2 = gdImageColorResolveAlpha(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 = gdImageColorResolve(im, 255, 0, 255);
	c2 = gdImageColorResolve(im, 255, 200, 0);
	c3 = gdImageColorResolveAlpha(im, 255, 0, 255, 100);
	c4 = gdImageColorResolveAlpha(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 == 3) != 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;
	}
	color = gdTrueColorAlpha(gdImageRed(im, c4), gdImageGreen(im, c4),
					gdImageBlue(im, c4), 0);
	if (gdTestAssert(color == 0xFF22FF) != 1) {
		error = -1;
	}
	gdImageDestroy(im);

	return error;
}
Пример #10
0
BGD_DECLARE(gdImagePtr) gdImageCreateFromXpm (char *filename)
{
  XpmInfo info;
  XpmImage image;
  int i, j, k, number;
  char buf[5];
  gdImagePtr im = 0;
  int *pointer;
  int red = 0, green = 0, blue = 0, alpha = 0;
  int *colors;
  int ret;

  ret = XpmReadFileToXpmImage (filename, &image, &info);
  if (ret != XpmSuccess)
    return 0;

  if (!(im = gdImageCreate (image.width, image.height)))
    return 0;

  number = image.ncolors;
	if (overflow2(sizeof (int), number)) {
		return 0;
	}
  colors = (int *) gdMalloc (sizeof (int) * number);
  if (colors == NULL)
    return (0);
  for (i = 0; i < number; i++)
    {
      alpha = 0;
      switch (strlen (image.colorTable[i].c_color))
	{
	case 4:
	  if (!strcasecmp(image.colorTable[i].c_color,"none")) {
	    red = 0;
	    green = 0;
            blue = 0;
            alpha = 127;
	  } else {
    	    buf[1] = '\0';
	    buf[0] = image.colorTable[i].c_color[1];
	    red = strtol (buf, NULL, 16);

	    buf[0] = image.colorTable[i].c_color[3];
	    green = strtol (buf, NULL, 16);

	    buf[0] = image.colorTable[i].c_color[5];
	    blue = strtol (buf, NULL, 16);
          } 
	  break;
	case 7:
	  buf[2] = '\0';
	  buf[0] = image.colorTable[i].c_color[1];
	  buf[1] = image.colorTable[i].c_color[2];
	  red = strtol (buf, NULL, 16);

	  buf[0] = image.colorTable[i].c_color[3];
	  buf[1] = image.colorTable[i].c_color[4];
	  green = strtol (buf, NULL, 16);

	  buf[0] = image.colorTable[i].c_color[5];
	  buf[1] = image.colorTable[i].c_color[6];
	  blue = strtol (buf, NULL, 16);
	  break;
	case 10:
	  buf[3] = '\0';
	  buf[0] = image.colorTable[i].c_color[1];
	  buf[1] = image.colorTable[i].c_color[2];
	  buf[2] = image.colorTable[i].c_color[3];
	  red = strtol (buf, NULL, 16);
	  red /= 64;

	  buf[0] = image.colorTable[i].c_color[4];
	  buf[1] = image.colorTable[i].c_color[5];
	  buf[2] = image.colorTable[i].c_color[6];
	  green = strtol (buf, NULL, 16);
	  green /= 64;

	  buf[0] = image.colorTable[i].c_color[7];
	  buf[1] = image.colorTable[i].c_color[8];
	  buf[2] = image.colorTable[i].c_color[9];
	  blue = strtol (buf, NULL, 16);
	  blue /= 64;
	  break;
	case 13:
	  buf[4] = '\0';
	  buf[0] = image.colorTable[i].c_color[1];
	  buf[1] = image.colorTable[i].c_color[2];
	  buf[2] = image.colorTable[i].c_color[3];
	  buf[3] = image.colorTable[i].c_color[4];
	  red = strtol (buf, NULL, 16);
	  red /= 256;

	  buf[0] = image.colorTable[i].c_color[5];
	  buf[1] = image.colorTable[i].c_color[6];
	  buf[2] = image.colorTable[i].c_color[7];
	  buf[3] = image.colorTable[i].c_color[8];
	  green = strtol (buf, NULL, 16);
	  green /= 256;

	  buf[0] = image.colorTable[i].c_color[9];
	  buf[1] = image.colorTable[i].c_color[10];
	  buf[2] = image.colorTable[i].c_color[11];
	  buf[3] = image.colorTable[i].c_color[12];
	  blue = strtol (buf, NULL, 16);
	  blue /= 256;
	  break;
	}


      colors[i] = gdImageColorResolveAlpha(im, red, green, blue, alpha);
      if (colors[i] == -1)
	fprintf (stderr, "ARRRGH\n");
    }

  pointer = (int *) image.data;
  for (i = 0; i < image.height; i++)
    {
      for (j = 0; j < image.width; j++)
	{
	  k = *pointer++;
	  gdImageSetPixel (im, j, i, colors[k]);
	}
    }
  gdFree (colors);
  return (im);
}
Пример #11
0
int
main (int argc, char *argv[])
{
	gdImagePtr im;
	int blue;
	int blueAlpha;
	int white;
	int brect[8];
	int x, y, sx, sy;
	char *err;
	FILE *out;
#ifdef JISX0208
	char *s = "Hello. ‚±‚ñ‚É‚¿‚Í Qyjpqg,";	/* String to draw. */
#else
	char *s = "Hello. �ん��� Qyjpqg,";	/* String to draw. */
#endif

	double sz = 40.;

#if 0
	double angle = 0.;
#else
	double angle = DEG2RAD (90);
#endif
	char *f;
	if (argc == 2) {
		f = argv[1];
	} else {
		/* 2.02: usage message. Defaulting to Times wasn't working well for the
		   many people with no /usr/share/fonts/truetype. */
		fprintf(stderr, "Usage: gdtestft fontfilename\n"
			 "If fontfilename is not a full or relative path, GDFONTPATH is searched for\n"
		         "it. If GDFONTPATH is not set, /usr/share/fonts/truetype is searched.\n");
		return 1;
	}
	/* obtain brect so that we can size the image */
	err =
	    gdImageStringFT ((gdImagePtr) NULL, &brect[0], 0, f, sz, angle, 0, 0, s);
	if (err) {
		fprintf(stderr, "%s\n", err);
		return 1;
	}

	/* create an image just big enough for the string (x3) */
	sx = MAXX (brect) - MINX (brect) + 6;
	sy = MAXY (brect) - MINY (brect) + 6;
#if 0
	/* Would be palette color 8-bit (which of course is still allowed,
	   but not impressive when used with a JPEG background and antialiasing
	   and alpha channel and so on!) */
	im = gdImageCreate (sx * 3, sy);
#else
	/* gd 2.0: true color images can use freetype too,
	   and they can do antialiasing against arbitrary
	   complex backgrounds. */
	im = gdImageCreateTrueColor (sx * 3, sy);
#endif
	/* Background color. gd 2.0: fill the image with it; truecolor
	   images have a black background otherwise. */
	white = gdImageColorResolve (im, 255, 255, 255);
	/* Load a pretty background and resample it to cover the entire image */
	{
		FILE *in = fopen ("eleanor.jpg", "rb");
		gdImagePtr imb = NULL;
		if (in) {
#ifdef HAVE_LIBJPEG
			imb = gdImageCreateFromJpeg (in);
#else
			fprintf(stderr, "No JPEG library support.\n");
#endif
			fclose(in);

			if (!imb) {
				fprintf(stderr, "gdImageCreateFromJpeg failed\n");
				return 1;
			}
			if (!im->trueColor) {
				/* If destination is not truecolor, convert the JPEG to a
				   reasonably high-quality palette version. This is not as good
				   as creating a truecolor output file, of course. Leave many
				   colors for text smoothing. */
#if 1
				gdImageTrueColorToPalette (imb, 0, 128);
#endif
			}
			/* Resample background image to cover new image exactly */
			gdImageCopyResampled (im, imb, 0, 0, 0, 0, sx * 3, sy,
			                      gdImageSX (imb), gdImageSY (imb));
		} else {
			/* Can't get background, so paint a simple one */
			/* Truecolor images start out black, so paint it white */
			gdImageFilledRectangle (im, 0, 0, sx * 3, sy, white);
		}
	}
	/* TBB 2.0.2: only black was working, and I didn't know it because
	   the test program used black. Funny, huh? Let's do a more interesting
	   color this time.  */
	blue = gdImageColorResolve (im, 128, 192, 255);
	/* Almost-transparent blue (alpha blending), with antialiasing */
	blueAlpha = gdImageColorResolveAlpha (im, 128, 192, 255, gdAlphaMax / 2);
	/* render the string, offset origin to center string */
	x = 0 - MINX (brect) + 3;
	y = 0 - MINY (brect) + 3;

	/* With antialiasing (positive color value) */
	err = gdImageStringFT (im, NULL, blue, f, sz, angle, x, y, s);
	if (err) {
		fprintf(stderr, "%s\n", err);
		return 1;
	}
	/* Without antialiasing (negative color value) */
	err = gdImageStringFT (im, NULL, -blue, f, sz, angle, sx + x, y, s);
	if (err) {
		fprintf(stderr, "%s\n", err);
		return 1;
	}
	/* With antialiasing, and 50% alpha blending (truecolor only) */
	err = gdImageStringFT (im, NULL, blueAlpha, f, sz, angle, sx * 2 + x, y, s);
	if (err) {
		fprintf(stderr, "%s\n", err);
		return 1;
	}
	/* TBB: Write img to test/fttest.jpg or test/fttest.png */
	if (im->trueColor) {
#ifdef HAVE_LIBJPEG
		out = fopen ("test/fttest.jpg", "wb");
		if (!out) {
			fprintf(stderr, "Can't create test/fttest.jpg\n");
			exit (1);
		}
		/* Fairly high JPEG quality setting */
		gdImageJpeg (im, out, 90);
		fclose (out);
		fprintf(stderr, "Test image written to test/fttest.jpg\n");
#else
		fprintf(stderr, "Test image not written; No JPEG library support.\n");
#endif
	} else {
#ifdef HAVE_LIBPNG
		out = fopen ("test/fttest.png", "wb");
		if (!out) {
			fprintf(stderr, "Can't create test/fttest.png\n");
			exit (1);
		}
		/* 2.0.10: correct ifdef, thanks to Gabriele Verzeletti */
		gdImagePng (im, out);
		fclose (out);
		fprintf(stderr, "Test image written to test/fttest.png\n");
#else
		fprintf(stderr, "Test image not written; No PNG library support.\n");
#endif
	}
	/* Destroy it */
	gdImageDestroy (im);

	return 0;
}