Exemplo n.º 1
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);
	}
}
Exemplo n.º 2
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);
	}
}
Exemplo n.º 3
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);
	}
}
Exemplo n.º 4
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;
}
Exemplo n.º 5
0
static void drawLines (MULTICHART_ID id)
{
    register int    i, j;
    int             x1, x2, y1, y2;

    gdImageSetThickness (id->im, 2);

    for (i = 0; i < id->numpoints - 1; i ++)
    {
        for (j = 0; j < id->numdatasets; j ++)
        {
            if (id->dataset[j].valueset[i] <= ARCHIVE_VALUE_NULL ||
                id->dataset[j].valueset[i+1] <= ARCHIVE_VALUE_NULL)
            {
                continue;
            }

            x1 = id->imtx + (int)((double)i * id->pointpixels);
            x2 = id->imtx + (int)((double)(i+1) * id->pointpixels);
            y1 = id->imby - (int)(id->ypixelconstant * (id->dataset[j].valueset[i] - id->min));
            y2 = id->imby - (int)(id->ypixelconstant * (id->dataset[j].valueset[i+1] - id->min));
            gdImageLine (id->im,
                         x1,
                         y1,
                         x2,
                         y2,
                         id->dataset[j].lineColor);
        }
    }
}
Exemplo n.º 6
0
result_t Image::setThickness(int32_t thickness)
{
    if (!m_image)
        return CHECK_ERROR(CALL_E_INVALID_CALL);

    gdImageSetThickness(m_image, thickness);
    return 0;
}
Exemplo n.º 7
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);
	}
}
Exemplo n.º 8
0
/* prints the arrow into the image poined to by the pointer with given
   color*/
void ocin_vis_arrow::print(gdImagePtr im, float scale_val) {

  int thick = ((int)((float)thickness *scale_val)) + 1;

  int scaled_a_size = (int) ((float)(a_size - 4) *scale_val) + 4;

  // create points for arrow head based on scale factor
  if (dir == S) {
    points[1].x = x2 - scaled_a_size;
    points[1].y = y2 - scaled_a_size;
    points[2].x = x2 + scaled_a_size;
    points[2].y = y2 - scaled_a_size;
  } else if (dir == E) {
    points[1].x = x2 - scaled_a_size;
    points[1].y = y2 + scaled_a_size;
    points[2].x = x2 - scaled_a_size;
    points[2].y = y2 - scaled_a_size;
  } else if (dir == N) {
    points[1].x = x2 - scaled_a_size;
    points[1].y = y2 + scaled_a_size;
    points[2].x = x2 + scaled_a_size;
    points[2].y = y2 + scaled_a_size;
  } else if (dir == W) {
    points[1].x = x2 + scaled_a_size;
    points[1].y = y2 + scaled_a_size;
    points[2].x = x2 + scaled_a_size;
    points[2].y = y2 - scaled_a_size;
  }
  // setup the arrow head points
  points[0].x = x2;             // first point is end of the line
  points[0].y = y2;

  // select the color for the arrow head
  int cnt = 255 - ((int)(250.0*scale_val));
  cnt = cnt &0xfffffffe;	// make sure we have an even number
				// (?)
  int color;
  color = gdImageColorResolve(im, cnt, cnt, cnt);

  // if (cnt < 0) {
  //   color = gdImageColorResolve(im, 0, 255+cnt, (cnt*-1));
  // } else {
  //   color = gdImageColorResolve(im, cnt, 255-cnt, 0);
  // }


  
  // draw the arrowhead first (why not)
  gdImageFilledPolygon(im, points, 3, color);

  // then the line
  gdImageSetThickness(im, thick);
  gdImageLine(im, x1, y1, x2, y2, color);
  
 
  
}
Exemplo n.º 9
0
gdImagePtr  graph_dibujar_grid( int w, int h, int cw, int ch, int f, int b ){
    int i, j;

    gdImagePtr  gd = gdImageCreateTrueColor( h + 6, w + 6 );
    int  fondo  = gdImageColorAllocate( gd, b >> 16, ( b & 0xFF00 ) >> 8 , b & 0xFF );
    int  frente = gdImageColorAllocate( gd, f >> 16, ( f & 0xFF00 ) >> 8 , f & 0xFF );
    gdImageFilledRectangle( gd, 0, 0, w + 5, h + 5, fondo );
    gdImageSetThickness( gd, 1 ); // La linea de cuatro pixel que pienso dibujar por el borde
    // Dibujo un rectangulo alrededor de todo el tablero.
    // gdImageRectangle( gd, 0, 0, w + 3 , h + 3 , frente );
    gdImageRectangle( gd, 1, 1, w + 4 , h + 4 , frente );
    gdImageRectangle( gd, 2, 2, w + 3 , h + 3 , frente );
    gdImageRectangle( gd, 3, 3, w + 2 , h + 2 , frente );
    gdImageSetThickness( gd, 2 ); // La linea de dos pixel que pienso dibujar

    for( i = 1; i < cw - 1; i ++ ){
        gdImageLine( gd, 3 + cw * i, 3 + 0, 3 + cw * i, 3 + h, frente );
    }
    for( i = 1; i < ch - 1; i ++ ){
        gdImageLine( gd, 3 + 0, 3 + ch * i, 3 + w, 3 + ch * i, frente );
    }
    return  gd;

}
Exemplo n.º 10
0
static int set_penstyle(GVJ_t * job, gdImagePtr im, gdImagePtr brush)
{
    obj_state_t *obj = job->obj;
    int i, pen, pencolor, transparent, width, dashstyle[40];

    pen = pencolor = color_index(im, obj->pencolor);
    transparent = gdImageGetTransparent(im);
    if (obj->pen == PEN_DASHED) {
        for (i = 0; i < 20; i++)
            dashstyle[i] = pencolor;
        for (; i < 40; i++)
            dashstyle[i] = transparent;
        gdImageSetStyle(im, dashstyle, 20);
        pen = gdStyled;
    } else if (obj->pen == PEN_DOTTED) {
        for (i = 0; i < 2; i++)
            dashstyle[i] = pencolor;
        for (; i < 24; i++)
            dashstyle[i] = transparent;
        gdImageSetStyle(im, dashstyle, 24);
        pen = gdStyled;
    }
    width = obj->penwidth * job->scale.x;
    if (width < PENWIDTH_NORMAL)
        width = PENWIDTH_NORMAL;  /* gd can't do thin lines */
    gdImageSetThickness(im, width);
    /* use brush instead of Thickness to improve end butts */
    if (width != PENWIDTH_NORMAL) {
        brush = gdImageCreate(width, width);
        gdImagePaletteCopy(brush, im);
        gdImageFilledRectangle(brush, 0, 0, width - 1, width - 1, pencolor);
        gdImageSetBrush(im, brush);
        if (pen == gdStyled)
            pen = gdStyledBrushed;
        else
            pen = gdBrushed;
    }
    return pen;
}
Exemplo n.º 11
0
int
main (void)
{
#ifdef HAVE_LIBPNG
  /* Input and output files */
  FILE *in;
  FILE *out;

  /* Input and output images */
  gdImagePtr im_in = 0, im_out = 0;

  /* Brush image */
  gdImagePtr brush;

  /* Color indexes */
  int white;
  int blue;
  int red;
  int green;

  /* Points for polygon */
  gdPoint points[3];
  int i;

  /* Create output image, in true color. */
  im_out = gdImageCreateTrueColor (256 + 384, 384);
  /* 2.0.2: first color allocated would automatically be background in a 
     palette based image. Since this is a truecolor image, with an 
     automatic background of black, we must fill it explicitly. */
  white = gdImageColorAllocate (im_out, 255, 255, 255);
  gdImageFilledRectangle (im_out, 0, 0, gdImageSX (im_out),
			  gdImageSY (im_out), white);

  /* Set transparent color. */
  gdImageColorTransparent (im_out, white);

  /* Try to load demoin.png and paste part of it into the
     output image. */
  in = fopen ("demoin.png", "rb");
  if (!in)
    {
      fprintf (stderr, "Can't load source image; this demo\n");
      fprintf (stderr, "is much more impressive if demoin.png\n");
      fprintf (stderr, "is available.\n");
      im_in = 0;
    }
  else
    {
      int a;
      im_in = gdImageCreateFromPng (in);
      fclose (in);
      /* Now copy, and magnify as we do so */
      gdImageCopyResampled (im_out, im_in, 32, 32, 0, 0, 192, 192, 255, 255);
      /* Now display variously rotated space shuttles in a circle of our own */
      for (a = 0; (a < 360); a += 45)
	{
	  int cx = cos (a * .0174532925) * 128;
	  int cy = -sin (a * .0174532925) * 128;
	  gdImageCopyRotated (im_out, im_in,
			      256 + 192 + cx, 192 + cy,
			      0, 0, gdImageSX (im_in), gdImageSY (im_in), a);
	}
    }
  red = gdImageColorAllocate (im_out, 255, 0, 0);
  green = gdImageColorAllocate (im_out, 0, 255, 0);
  blue = gdImageColorAllocate (im_out, 0, 0, 255);
  /* Fat Rectangle */
  gdImageSetThickness (im_out, 4);
  gdImageLine (im_out, 16, 16, 240, 16, green);
  gdImageLine (im_out, 240, 16, 240, 240, green);
  gdImageLine (im_out, 240, 240, 16, 240, green);
  gdImageLine (im_out, 16, 240, 16, 16, green);
  gdImageSetThickness (im_out, 1);
  /* Circle */
  gdImageArc (im_out, 128, 128, 60, 20, 0, 720, blue);
  /* Arc */
  gdImageArc (im_out, 128, 128, 40, 40, 90, 270, blue);
  /* Flood fill: doesn't do much on a continuously
     variable tone jpeg original. */
  gdImageFill (im_out, 8, 8, blue);
  /* Polygon */
  points[0].x = 64;
  points[0].y = 0;
  points[1].x = 0;
  points[1].y = 128;
  points[2].x = 128;
  points[2].y = 128;
  gdImageFilledPolygon (im_out, points, 3, green);
  /* 2.0.12: Antialiased Polygon */
  gdImageSetAntiAliased (im_out, green);
  for (i = 0; (i < 3); i++)
    {
      points[i].x += 128;
    }
  gdImageFilledPolygon (im_out, points, 3, gdAntiAliased);
  /* Brush. A fairly wild example also involving a line style! */
  if (im_in)
    {
      int style[8];
      brush = gdImageCreateTrueColor (16, 16);
      gdImageCopyResized (brush, im_in,
			  0, 0, 0, 0,
			  gdImageSX (brush), gdImageSY (brush),
			  gdImageSX (im_in), gdImageSY (im_in));
      gdImageSetBrush (im_out, brush);
      /* With a style, so they won't overprint each other.
         Normally, they would, yielding a fat-brush effect. */
      style[0] = 0;
      style[1] = 0;
      style[2] = 0;
      style[3] = 0;
      style[4] = 0;
      style[5] = 0;
      style[6] = 0;
      style[7] = 1;
      gdImageSetStyle (im_out, style, 8);
      /* Draw the styled, brushed line */
      gdImageLine (im_out, 0, 255, 255, 0, gdStyledBrushed);
    }
  /* Text (non-truetype; see gdtestft for a freetype demo) */
  gdImageString (im_out, gdFontGiant, 32, 32, (unsigned char *) "hi", red);
  gdImageStringUp (im_out, gdFontSmall, 64, 64, (unsigned char *) "hi", red);
  /* Random antialiased lines; coordinates all over the image, 
    but the output will respect a small clipping rectangle */
  gdImageSetClip(im_out, 0, gdImageSY(im_out) - 100,
    100, gdImageSY(im_out)); 
  /* Fixed seed for reproducibility of results */
  srand(100);
  for (i = 0; (i < 100); i++) {
    int x1 = rand() % gdImageSX(im_out);
    int y1 = rand() % gdImageSY(im_out);
    int x2 = rand() % gdImageSX(im_out);
    int y2 = rand() % gdImageSY(im_out);
    gdImageSetAntiAliased(im_out, white);
    gdImageLine (im_out, x1, y1, x2, y2, gdAntiAliased);
  }
  /* Make output image interlaced (progressive, in the case of JPEG) */
  gdImageInterlace (im_out, 1);
  out = fopen ("demoout.png", "wb");
  /* Write PNG */
  gdImagePng (im_out, out);
  fclose (out);
  /* 2.0.12: also write a paletteized version */
  out = fopen ("demooutp.png", "wb");
  gdImageTrueColorToPalette (im_out, 0, 256);
  gdImagePng (im_out, out);
  fclose (out);
  gdImageDestroy (im_out);
  if (im_in)
    {
      gdImageDestroy (im_in);
    }
#else
  fprintf (stderr, "No PNG library support.\n");
#endif /* HAVE_LIBPNG */
  return 0;
}
Exemplo n.º 12
0
void doSetThickness(FILE *stream) {
  int t;

  t = getNumber(stream);
  gdImageSetThickness(image, t);
}
Exemplo n.º 13
0
void
plD_state_png(PLStream *pls, PLINT op)
{
png_Dev *dev=(png_Dev *)pls->dev;
PLFLT tmp_colour_pos;
#if GD2_VERS >= 2
long temp_col;
#endif


    switch (op) {

#if GD2_VERS >= 2
    case PLSTATE_WIDTH:
        gdImageSetThickness(dev->im_out, pls->width);
	break;
#endif

    case PLSTATE_COLOR0:
#if GD2_VERS >= 2

	if ( (pls->icol0 == PL_RGB_COLOR)||     /*  Should never happen since PL_RGB_COLOR is depreciated, but here for backwards compatibility */
             (gdImageTrueColor(dev->im_out)) )  /*  We will do this if we are in "TrueColour" mode */
           {
	    if ( (dev->totcol < NCOLOURS)||         /* See if there are slots left, if so we will allocate a new colour */
                 (gdImageTrueColor(dev->im_out)) )  /* In TrueColour mode we allocate each colour as we come to it */
	       {
	        /* Next allocate a new colour to a temporary slot since what we do with it will varay depending on if its a pallter index or truecolour */
                temp_col=gdImageColorAllocate(dev->im_out,pls->curcolor.r,
                                             pls->curcolor.g, pls->curcolor.b);

                if (gdImageTrueColor(dev->im_out))
                    dev->colour = temp_col;     /* If it's truecolour, then we will directly set dev->colour to our "new" colour */
                else
                    {
                     dev->colour = dev->totcol;  /* or else, we will just set it to the last colour */
                     dev->totcol++;              /* Bump the total colours for next time round */
                    }
	       }

           }
         else  /* just a normal colour allocate, so don't worry about the above stuff, just grab the index */
           {
            dev->colour = pls->icol0;
           }

#else
	dev->colour = pls->icol0;
	if (dev->colour == PL_RGB_COLOR)
           {
	    if (dev->totcol < NCOLOURS)
	       {
                gdImageColorAllocate(dev->im_out,pls->curcolor.r, pls->curcolor.g,  pls->curcolor.b);
		dev->colour = dev->totcol;
	       }

           }
#endif
	break;

    case PLSTATE_COLOR1:

#if GD2_VERS >= 2
       if (!gdImageTrueColor(dev->im_out))
          {
#endif
           /*
            * Start by checking to see if we have to compensate for cases where
            * we don't have the full dynamic range of cmap1 at our disposal
            */
           if (dev->ncol1<pls->ncol1)
              {
               tmp_colour_pos=dev->ncol1*((PLFLT)pls->icol1/(pls->ncol1>0 ? pls->ncol1 : 1));
               dev->colour = pls->ncol0 + (int)tmp_colour_pos;
              }
           else
              dev->colour = pls->ncol0 + pls->icol1;
#if GD2_VERS >= 2
           }
        else    /* it is a truecolour image */
           {
             dev->colour = gdTrueColor(pls->curcolor.r, pls->curcolor.g, pls->curcolor.b);
           }
#endif
	break;


    case PLSTATE_CMAP0:
    case PLSTATE_CMAP1:

#if GD2_VERS >= 2
       if ((dev->im_out != NULL) && !gdImageTrueColor(dev->im_out))
          {
#endif

    /*
     *  Code to redefine the entire palette
     */


	if (pls->color)
	    setcmap(pls);

#if GD2_VERS >= 2
}
#endif

	break;
    }
}
Exemplo n.º 14
0
void Gd::setThickness(int thickness)
{
  gdImageSetThickness(_imagePtr, thickness);
}
Exemplo n.º 15
0
static    gdImagePtr  graph_dibujar_posicion( Tipojuego* tj, int flags, Posicion* pos, Movida* mov ){
    int tablero_flags = ( flags & GETPNG_ROTADO );
    int i;
    gdImagePtr gdt = graph_get_tablero_png( tj, tj->tablero_actual, tablero_flags );
    if( !gdt ){
        LOGPRINT( 2, "No es posible obtener la imagen del tablero para %s", tj->nombre );
        return  0;
    }
    gdImagePtr gd = gdImageCreateTrueColor( gdImageSX( gdt ), gdImageSY( gdt ) );
    gdImageCopy( gd, gdt, 0, 0, 0, 0, gdImageSX( gdt ), gdImageSY( gdt ) );

    Tablero* tt = tipojuego_get_tablero( tj, tj->tablero_actual ); 

    // Primero las marcas en el tablero, correspondientes al ultimo movimiento
    if( GETPNG_HIGHLIGHTED( flags ) && mov ){
        int  marca ;
        int  rojo, verde, azul;
        int  posx, posy;
        rojo  = ( flags & GETPNG_HIGHLIGHT_RED ? 255 : 0 );
        verde = ( flags & GETPNG_HIGHLIGHT_GREEN ? 255 : 0 );
        azul  = ( flags & GETPNG_HIGHLIGHT_BLUE ? 255 : 0 );
        marca = gdImageColorAllocate( gd, rojo, verde, azul );
        gdImageSetThickness( gd, HIGHLIGHT_SIZE );
        int i;
        for( i = 0; i < mov->acciones->entradas; i ++ ){
            Accion* acc = mov->acciones->data[i];
            if( acc->destino ){
                if( flags & GETPNG_ROTADO ){
                    posx = ( tt->graphdef->w / tt->dimmax[0] ) * ( tt->dimmax[0] - acc->destino->posicion[0] - 1 ) +
                            tt->graphdef->ox ;
                    posy = ( tt->graphdef->h / tt->dimmax[1] ) * ( acc->destino->posicion[1] ) + 
                            tt->graphdef->oy;
                } else {
                    posx = ( tt->graphdef->w / tt->dimmax[0] ) * acc->destino->posicion[0] +
                            tt->graphdef->ox ;
                    posy = ( tt->graphdef->h / tt->dimmax[1] ) * ( acc->destino->posicion[1] + 1 ) - 
                            tt->graphdef->oy;
                    posy = tt->graphdef->h - posy ;
                }
            }
            gdImageRectangle( gd, posx + HIGHLIGHT_SIZE / 2.0, posy + HIGHLIGHT_SIZE / 2.0, 
                                  posx + ( tt->graphdef->w / tt->dimmax[0] ) - HIGHLIGHT_SIZE / 2.0, 
                                  posy + ( tt->graphdef->h / tt->dimmax[1] ) - HIGHLIGHT_SIZE / 2.0,
                                marca );
            
        }
    }

    // Ahora las piezas
    for( i = 0; i < pos->piezas_count; i ++ ){
        Pieza* p = & pos->piezas[i];
        int  posx, posy;
        if( !CASILLERO_VALIDO( p->casillero ) ) continue;
        gdImagePtr gdp = graph_tpieza_get_gd( p->tpieza, p->color );
        if( !gdp ){
          gdImageDestroy( gd );
          return 0;
        }
        // Aca tengo que entontrar la posicion relativa de la pieza
        // y colocar el dibujo. No es otra cosa que la posicion
        // relativa del casillero por el tamaño (tablero->g->w / tablero->dimmax[0])
        // mas el offset del tablero
        if( flags & GETPNG_ROTADO ){
            posx = ( tt->graphdef->w / tt->dimmax[0] ) * ( tt->dimmax[0] - p->casillero->posicion[0] - 1 ) +
                     tt->graphdef->ox ;
            posy = ( tt->graphdef->h / tt->dimmax[1] ) * ( p->casillero->posicion[1] ) + 
                    tt->graphdef->oy;
        } else {
            posx = ( tt->graphdef->w / tt->dimmax[0] ) * p->casillero->posicion[0] +
                     tt->graphdef->ox ;
            posy = ( tt->graphdef->h / tt->dimmax[1] ) * ( p->casillero->posicion[1] + 1 ) - 
                    tt->graphdef->oy;
            posy = tt->graphdef->h - posy  ;
        }
        gdImageCopy( gd, gdp, posx, posy, 0, 0, gdImageSX( gdp ), gdImageSY( gdp ) );
    }
    return gd;
}
Exemplo n.º 16
0
static void drawGrid (MULTICHART_ID id)
{
    register int    i;
    int             xlabelwidth = 0, ylabelwidth = 0;
    double          units, step;
    double          minR, stepR;
    int             dataPoints, xnumhash, xhashindexlen;
    double          hashwidth, xhashwidth;
    int             numhash, x, y;
    char            text[64][32], ylabelfmt[24];
    char            textR[64][32], ylabelfmtR[24];

    //  ... calculate the maximum number of hash marks and the units per hash
    //  ... for the x-axis
    //  build labels and calculate the maximum x-label width
    for (i = 0; i < id->numpoints; i ++)
    {
        if (strlen (id->pointnames[i]) > xlabelwidth)
            xlabelwidth = strlen (id->pointnames[i]);
    }

    xhashwidth = (xlabelwidth*gdFontSmall->h)/2;
    dataPoints = id->numpoints - 1;


    if (strlen (id->DualUnit) > 0)
    {
        // ((gdFontSmall->h/2) * strlen (id->DualUnit)))/2) - 2
        id->imbx -= (gdFontMediumBold->h);
        if ((strcmp(id->DualUnit,"inches") == 0) || 
            (strcmp(id->DualUnit,"knots") == 0) || 
            (strcmp(id->DualUnit,"m/s") == 0))
            id->imbx -= 7;
    }


    // see if a suggestion was given
    if (id->xnumhashes != 0)
    {
        xnumhash = id->xnumhashes;
    }
    else
    {
        xnumhash =  (id->imbx - id->imtx)/xhashwidth;

        // try to normalize the number of hashmarks
        // try with the endpoint removed
        for (i = 1; i < dataPoints/2; i ++)
        {
            if (dataPoints % i != 0)
                continue;

            if (dataPoints/i <= xnumhash)
            {
                xnumhash = dataPoints/i;
                break;
            }
        }
    }

    xhashwidth = (double)(id->imbx - id->imtx)/(double)xnumhash;
    id->pointpixels = (double)(id->imbx - id->imtx)/(double)dataPoints;
    xhashindexlen = dataPoints/xnumhash;


    //  ... calculate the maximum number of hash marks and the units per hash
    //  ... for the y-axis
    hashwidth = (gdFontSmall->h * 3)/2;
    numhash = (id->imby - id->imty)/hashwidth;
    if (numhash > 64)
        numhash = 64;

    units = (id->max - id->min)/id->ystepSize;
    step = id->ystepSize;
    i = 0;
    while ((int)units > numhash && i < MAX_STEP_MULTIPLIER)
    {
        step = id->ystepSize * stepSizeMultipliers[i];
        units = (id->max - id->min)/step;
        i ++;
    }

    id->ystepSize = step;
    numhash = (int)units;
    if ((id->min + (id->ystepSize * numhash)) < id->max)
    {
        numhash ++;
    }

    hashwidth = (double)(id->imby - id->imty)/(double)numhash;
    id->max = id->min + (id->ystepSize * numhash);
    id->ypixelconstant = (double)(id->imby - id->imty)/(double)(id->max - id->min);
    numhash ++;
    if (numhash > 64)
        numhash = 64;

    //  build labels and calculate the maximum y-label width
    sprintf (ylabelfmt, "%%.%1.1df", id->ydecPlaces);
    for (i = 0; i < numhash; i ++)
    {
        sprintf (text[i], ylabelfmt, id->min + (i * id->ystepSize));

        // now fill the right hand array with alternate scale @Rcm
        if (strlen(id->DualUnit) > 0)
        {
            textR[i][0] = ' ';
            if (strcmp(id->DualUnit,"C") == 0)
            {
                minR = wvutilsConvertFToC (id->min);
                stepR = ((id->ystepSize) * (5.0/9.0));
                sprintf (textR[i], "%.1f", minR + (i * stepR));
            }
            else if (strcmp(id->DualUnit,"F") == 0)
            {
                minR = wvutilsConvertCToF (id->min);
                stepR = ((id->ystepSize) * (9.0/5.0));
                sprintf (textR[i], "%.1f", minR + (i * stepR));
            }
            else if (strcmp(id->DualUnit,"mm") == 0)
            {
                minR = wvutilsConvertINToMM (id->min);
                stepR = wvutilsConvertINToMM (id->ystepSize);
                if (wvutilsConvertINToMM (id->max) >= 100)
                    sprintf (textR[i], "%.0f", minR + (i * stepR));
                else
                    sprintf (textR[i], "%.1f", minR + (i * stepR));
            }
            else if (strcmp(id->DualUnit,"inches") == 0)
            {
                minR = wvutilsConvertMMToIN (id->min);
                stepR = wvutilsConvertMMToIN (id->ystepSize);
                if (wvutilsConvertMMToIN (id->max) >= 100)
                    sprintf (textR[i], "%.0f", minR + (i * stepR));
                else
                    sprintf (textR[i], "%.1f", minR + (i * stepR));
            }
            else if (strcmp(id->DualUnit,"km/h") == 0)
            {
                minR = wvutilsConvertMilesToKilometers (id->min);
                stepR = wvutilsConvertMilesToKilometers (id->ystepSize);
                sprintf (textR[i], "%.0f", minR + (i * stepR));
            }
            else if (strcmp(id->DualUnit,"mph") == 0)
            {
                minR = wvutilsConvertKilometersToMiles (id->min);
                stepR = wvutilsConvertKilometersToMiles (id->ystepSize);
                sprintf (textR[i], "%.0f", minR + (i * stepR));
            }
            else if (strcmp(id->title,"m/s") == 0)
            {
                if (id->isMetric)
                {
                    minR = wvutilsConvertMPSToKPH (id->min);
                    stepR = wvutilsConvertMPSToKPH (id->ystepSize);
                    sprintf (textR[i], "%.0f", minR + (i * stepR));
                }
                else
                {
                    minR = wvutilsConvertMPSToMPH (id->min);
                    stepR = wvutilsConvertMPSToMPH (id->ystepSize);
                    sprintf (textR[i], "%.0f", minR + (i * stepR));
                }
            }
            else if (strcmp(id->title,"knots") == 0)
            {
                if (id->isMetric)
                {
                    minR = wvutilsConvertKnotsToKPH (id->min);
                    stepR = wvutilsConvertKnotsToKPH (id->ystepSize);
                    sprintf (textR[i], "%.0f", minR + (i * stepR));
                }
                else
                {
                    minR = wvutilsConvertKnotsToMPH (id->min);
                    stepR = wvutilsConvertKnotsToMPH (id->ystepSize);
                    sprintf (textR[i], "%.0f", minR + (i * stepR));
                }
            }
            else //all else: eg '%' or watts/m^2 (hum/ rad)
            {    // same value both sides
                minR = id->min * 25.4;
                stepR = id->ystepSize * 25.4;
                sprintf (textR[i], "%s", text[i]);
            }
            if (strlen (text[i]) > ylabelwidth)
                ylabelwidth = strlen (text[i])+2;
        }
        else
        {

            if (strlen (text[i]) > ylabelwidth)
                ylabelwidth = strlen (text[i]);
        }
    }

    //  ... now we know the chart area, draw it
    gdImageFilledRectangle (id->im,
                            id->imtx - GLC_CONTENTS_OFFSET,
                            id->imty - GLC_CONTENTS_OFFSET,
                            id->imbx + GLC_CONTENTS_OFFSET,
                            id->imby + GLC_CONTENTS_OFFSET,
                            id->chartcolor);

    gdImageRectangle (id->im,
                      id->imtx,
                      id->imty,
                      id->imbx,
                      id->imby,
                      id->gridcolor);

    //  ... draw the y-axis
    gdImageSetThickness (id->im, 1);
    for (i = 0; i < numhash; i ++)
    {
        y = id->imby - (i * hashwidth);

        gdImageLine (id->im,
                     id->imtx,
                     y,
                     id->imbx,
                     y,
                     id->gridcolor);

        y -= gdFontSmall->h/2;
        gdImageString (id->im,
                       gdFontSmall,
                       (id->imtx - 5) - (strlen(text[i]) * gdFontSmall->h/2),
                       y,
                       (UCHAR *)text[i],
                       id->textcolor);

        if (strlen(id->DualUnit) > 0 )
        {
            // right side
            x = id->imbx + (GLC_CONTENTS_OFFSET - 2);

            gdImageString (id->im,
                           gdFontSmall,
                           x + gdFontSmall->h/2,
                           y,
                           (UCHAR *)textR[i],
                           id->textcolor);
        }
    }

    //  ... draw the x-axis
    gdImageSetThickness (id->im, 1);

    for (i = 0; i <= xnumhash; i ++)            // one more for right-most
    {
        int         dataPoint = i * xhashindexlen;

        x = id->imtx + (i * xhashwidth);

        gdImageLine (id->im,
                     x,
                     id->imty,
                     x,
                     id->imby,
                     id->gridcolor);

        if (strlen(id->pointnames[dataPoint]) < 2)
            x -= gdFontSmall->h/4;

        gdImageString (id->im,
                       gdFontSmall,
                       x - ((gdFontSmall->h/2) *
                            (strlen(id->pointnames[dataPoint])/2)),
                       (id->height - (3 * gdFontMediumBold->h)) + 4,
                       (UCHAR *)id->pointnames[dataPoint],
                       id->textcolor);
    }


    //  ... finally, draw date
    gdImageString (id->im,
                   gdFontSmall,
                   ((id->width - ((gdFontSmall->h/2) * strlen (id->datetime)))/2) - 2,
                   id->height - (gdFontMediumBold->h + 2),
                   (UCHAR *)id->datetime,
                   id->textcolor);
}
Exemplo n.º 17
0
int renderVectorSymbolGD(imageObj *img, double x, double y, symbolObj *symbol, symbolStyleObj *style)
{
    int bRotated = MS_FALSE;
    int j,k;
    gdImagePtr ip;
    gdPoint mPoints[MS_MAXVECTORPOINTS];
    gdPoint oldpnt,newpnt;
    int fc,oc;
    if(!(ip = MS_IMAGE_GET_GDIMAGEPTR(img))) return MS_FAILURE;


    SETPEN(ip, style->color);
    SETPEN(ip, style->outlinecolor);
    fc = style->color ? style->color->pen : -1;
    oc = style->outlinecolor ? style->outlinecolor->pen : -1;

    if(oc==-1 && fc ==-1) {
        return MS_SUCCESS;
    }

    if (style->rotation != 0.0) {
        bRotated = MS_TRUE;
        symbol = rotateVectorSymbolPoints(symbol, style->rotation);
        if(!symbol) {
            return MS_FAILURE;
        }
    }

    /* We avoid MS_NINT in this context because the potentially variable
           handling of 0.5 rounding is often a problem for symbols which are
           often an odd size (ie. 7pixels) and so if "p" is integral the
           value is always on a 0.5 boundary - bug 1716 */
    x -= style->scale*.5*symbol->sizex;
    y -= style->scale*.5*symbol->sizey;

    if(symbol->filled) { /* if filled */

        k = 0; /* point counter */
        for(j=0; j < symbol->numpoints; j++) {
            if((symbol->points[j].x == -99) && (symbol->points[j].y == -99)) { /* new polygon (PENUP) */
                if(k>2) {
                    if(fc >= 0)
                        gdImageFilledPolygon(ip, mPoints, k, fc);
                    if(oc >= 0)
                        gdImagePolygon(ip, mPoints, k, oc);
                }
                k = 0; /* reset point counter */
            } else {
                mPoints[k].x = MS_NINT(style->scale*symbol->points[j].x + x);
                mPoints[k].y = MS_NINT(style->scale*symbol->points[j].y + y);
                k++;
            }
        }

        if(fc >= 0)
            gdImageFilledPolygon(ip, mPoints, k, fc);
        if(oc >= 0)
            gdImagePolygon(ip, mPoints, k, oc);

    } else  { /* NOT filled */

        if(oc >= 0) fc = oc; /* try the outline color (reference maps sometimes do this when combining a box and a custom vector marker */

        oldpnt.x = MS_NINT(style->scale*symbol->points[0].x + x); /* convert first point in marker */
        oldpnt.y = MS_NINT(style->scale*symbol->points[0].y + y);

        gdImageSetThickness(ip, style->outlinewidth);

        for(j=1; j < symbol->numpoints; j++) { /* step through the marker */
            if((symbol->points[j].x != -99) || (symbol->points[j].y != -99)) {
                if((symbol->points[j-1].x == -99) && (symbol->points[j-1].y == -99)) { /* Last point was PENUP, now a new beginning */
                    oldpnt.x = MS_NINT(style->scale*symbol->points[j].x + x);
                    oldpnt.y = MS_NINT(style->scale*symbol->points[j].y + y);
                } else {
                    newpnt.x = MS_NINT(style->scale*symbol->points[j].x + x);
                    newpnt.y = MS_NINT(style->scale*symbol->points[j].y + y);
                    gdImageLine(ip, oldpnt.x, oldpnt.y, newpnt.x, newpnt.y, fc);
                    oldpnt = newpnt;
                }
            }
        } /* end for loop */

        gdImageSetThickness(ip, 1); /* restore thinkness */
    } /* end if-then-else */

    if(bRotated) {
        msFreeSymbol(symbol); /* clean up */
        msFree(symbol);
    }
    return MS_SUCCESS;
}
Exemplo n.º 18
0
static void
gd_bezier(point * A, int n, int arrow_at_start, int arrow_at_end, int filled)
{
    pointf p, p0, p1, V[4];
    int i, j, step;
    int style[20];
    int pen, width;
    gdImagePtr brush = NULL;
    gdPoint F[4];

    if (!im)
        return;

    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] = transparent;
            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] = transparent;
            gdImageSetStyle(im, style, 12);
            pen = gdStyled;
        } else {
            pen = cstk[SP].pencolor;
        }
        width = cstk[SP].penwidth * CompScale;
        if (width < WIDTH_NORMAL)
            width = WIDTH_NORMAL;  /* gd can't do thin lines */
        gdImageSetThickness(im, width);
        if (width > WIDTH_NORMAL) {
            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;
        }
        p.x = A[0].x;
        p.y = A[0].y;
        p = gdpt(p);
        F[0].x = ROUND(p.x);
        F[0].y = ROUND(p.y);
        p.x = A[n-1].x;
        p.y = A[n-1].y;
        p = gdpt(p);
        F[3].x = ROUND(p.x);
        F[3].y = ROUND(p.y);
        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);
                if (filled) {
                    F[1].x = ROUND(p0.x);
                    F[1].y = ROUND(p0.y);
                    F[2].x = ROUND(p1.x);
                    F[2].y = ROUND(p1.y);
                    gdImageFilledPolygon(im, F, 4, cstk[SP].fillcolor);
                }
                p0 = p1;
            }
        }
        if (brush)
            gdImageDestroy(brush);
    }
}