Term-Gnuplot

 view release on metacpan or  search on metacpan

gnuterm/term/gd.trm  view on Meta::CPAN

	    web_color_rgbs[i].b;
    if (png_state.n_colors < WEB_N_COLORS)
	png_state.n_colors = WEB_N_COLORS;
    for (i = 0; i < png_state.n_colors; i++) {
	rgb = png_state.rgb_table[i];
	png_state.color_table[i] =
	    gdImageColorAllocate(png_state.image, (rgb >> 16) & 0xff,
				 (rgb >> 8) & 0xff, rgb & 0xff);
    }
    if (png_state.flags & PNG_USE_TRANSPARENT)
	gdImageColorTransparent(png_state.image,
				png_state.color_table[0]);
    else
	gdImageColorTransparent(png_state.image, -1);
    }

/* 
 * _text()  Called immediately after a plot is displayed.  This procedure 
 * should set the device back into text mode if it is also a terminal, so
 * that commands can be seen as they're typed.  Again, this will probably
 * do nothing if the device can't be used as a terminal.
 */
TERM_PUBLIC void
PNG_text()
{
    if (png_state.flags & PNG_USE_CROP) {
	/* PM 23. 8. 2002: crop the image around its bounding box */
	int x, y, x1, y1, x2, y2, flag;
	int bg = png_state.color_table[0]; /* index of the background color */
	gdImagePtr im_crop;
	for (flag=0, x1=0; x1 < gdImageSX(png_state.image)-1; x1++) {
	    for (y=0; y < gdImageSY(png_state.image); y++)
		if (gdImageGetPixel(png_state.image, x1, y) != bg) { flag = 1; break; }
	    if (flag) break;
	}
	for (flag=0, x2=gdImageSX(png_state.image)-1; x2 >= x1; x2--) {
	    for (y=0; y < gdImageSY(png_state.image); y++)
		if (gdImageGetPixel(png_state.image, x2, y) != bg) { flag = 1; break; }
	    if (flag) break;
	}
	for (flag=0, y1=0; y1 < gdImageSY(png_state.image)-1; y1++) {
	    for (x=x1; x <= x2; x++)
		if (gdImageGetPixel(png_state.image, x, y1) != bg) { flag = 1; break; };
	    if (flag) break;
	}
	for (flag=0, y2=gdImageSY(png_state.image)-1; y2 >= y1; y2--) {
	    for (x=x1; x <= x2; x++)
		if (gdImageGetPixel(png_state.image, x, y2) != bg) { flag = 1; break; };
	    if (flag) break;
	}
	x = x2 - x1 + 1; /* width */
	y = y2 - y1 + 1; /* height */
	im_crop = gdImageCreate(x,y);
	gdImagePaletteCopy(im_crop, png_state.image);
	gdImageCopy(im_crop, png_state.image, 0, 0, x1, y1, x, y);
	gdImageDestroy(png_state.image);
	png_state.image = im_crop;
    }
    if (png_state.flags & PNG_USE_INTERLACE)
	gdImageInterlace(png_state.image, 1);
    gdImagePng(png_state.image, gpoutfile);
    gdImageDestroy(png_state.image);
}

/* _move(x,y)  Called at the start of a line.  The cursor should move to the
 * (x,y) position without drawing.
 */
TERM_PUBLIC void
PNG_move(unsigned int x, unsigned int y)
{
    png_state.x = x;
    png_state.y = y;
}

/* _vector(x,y)  Called when a line is to be drawn.  This should display a line
 * from the last (x,y) position given by _move() or _vector() to this new (x,y)
 * position.
 */
TERM_PUBLIC void
PNG_vector(unsigned int x, unsigned int y)
{
    int lw;
    int png_linetype_dotted[5];

    if (png_state.linetype == -1) {
	png_linetype_dotted[0] = png_state.color_table[2];
	png_linetype_dotted[1] = png_state.color_table[2];
	png_linetype_dotted[2] = png_state.color_table[0];
	png_linetype_dotted[3] = png_state.color_table[0];
	png_linetype_dotted[4] = png_state.color_table[0];

	gdImageSetStyle(png_state.image, png_linetype_dotted, 5);
	gdImageLine(png_state.image, png_state.x, Y(png_state.y),
		    x, Y(y), gdStyled);
    } else {
    	if (png_state.linewidth == 1) {
	gdImageLine(png_state.image, png_state.x, Y(png_state.y),
		    x, Y(y), png_state.color);
	} else {
	/* EAM - Implement linewidth by selecting a pre-defined brush */
	/* The tricky bit is re-coloring the brush to the current color */
	lw   = png_state.linewidth;
	if (png_state.color != PNG_brush[lw].last_rgb) {
	    PNG_brush[lw].fgnd = gdImageColorResolve(PNG_brush[lw].im,
	    	gdImageRed(png_state.image,png_state.color),
	    	gdImageGreen(png_state.image,png_state.color),
	    	gdImageBlue(png_state.image,png_state.color) );
	    PNG_brush[lw].last_rgb = png_state.color;
	}
    	gdImageFilledRectangle( PNG_brush[lw].im, 1, 1, lw, lw, PNG_brush[lw].fgnd );
	gdImageSetBrush(png_state.image, PNG_brush[lw].im);
	gdImageLine(png_state.image, png_state.x, Y(png_state.y),
		    x, Y(y), gdBrushed );
	}
    }
    png_state.x = x;
    png_state.y = y;
}

/* _linetype(lt)  Called to set the line type before text is displayed or
 * line(s) plotted.  This procedure should select a pen color or line



( run in 0.430 second using v1.01-cache-2.11-cpan-13bb782fe5a )