⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gd.c

📁 Linux/Unix下的绘图函数库(Graphic Drawing Library)
💻 C
📖 第 1 页 / 共 5 页
字号:
      vert = 1;      d = 2 * dy - dx;      incr1 = 2 * dy;      incr2 = 2 * (dy - dx);      if (x1 > x2)	{	  x = x2;	  y = y2;	  ydirflag = (-1);	  xend = x1;	}      else	{	  x = x1;	  y = y1;	  ydirflag = 1;	  xend = x2;	}      dashedSet (im, x, y, color, &on, &dashStep, wid, vert);      if (((y2 - y1) * ydirflag) > 0)	{	  while (x < xend)	    {	      x++;	      if (d < 0)		{		  d += incr1;		}	      else		{		  y++;		  d += incr2;		}	      dashedSet (im, x, y, color, &on, &dashStep, wid, vert);	    }	}      else	{	  while (x < xend)	    {	      x++;	      if (d < 0)		{		  d += incr1;		}	      else		{		  y--;		  d += incr2;		}	      dashedSet (im, x, y, color, &on, &dashStep, wid, vert);	    }	}    }  else    {      /* 2.0.12: Michael Schwartz: divide rather than multiply;         TBB: but watch out for /0! */      double as = sin (atan2 (dy, dx));      if (as != 0)	{	  wid = thick / as;	}      else	{	  wid = 1;	}      vert = 0;      d = 2 * dx - dy;      incr1 = 2 * dx;      incr2 = 2 * (dx - dy);      if (y1 > y2)	{	  y = y2;	  x = x2;	  yend = y1;	  xdirflag = (-1);	}      else	{	  y = y1;	  x = x1;	  yend = y2;	  xdirflag = 1;	}      dashedSet (im, x, y, color, &on, &dashStep, wid, vert);      if (((x2 - x1) * xdirflag) > 0)	{	  while (y < yend)	    {	      y++;	      if (d < 0)		{		  d += incr1;		}	      else		{		  x++;		  d += incr2;		}	      dashedSet (im, x, y, color, &on, &dashStep, wid, vert);	    }	}      else	{	  while (y < yend)	    {	      y++;	      if (d < 0)		{		  d += incr1;		}	      else		{		  x--;		  d += incr2;		}	      dashedSet (im, x, y, color, &on, &dashStep, wid, vert);	    }	}    }}static voiddashedSet (gdImagePtr im, int x, int y, int color,	   int *onP, int *dashStepP, int wid, int vert){  int dashStep = *dashStepP;  int on = *onP;  int w, wstart;  dashStep++;  if (dashStep == gdDashSize)    {      dashStep = 0;      on = !on;    }  if (on)    {      if (vert)	{	  wstart = y - wid / 2;	  for (w = wstart; w < wstart + wid; w++)	    gdImageSetPixel (im, x, w, color);	}      else	{	  wstart = x - wid / 2;	  for (w = wstart; w < wstart + wid; w++)	    gdImageSetPixel (im, w, y, color);	}    }  *dashStepP = dashStep;  *onP = on;}BGD_DECLARE(int) gdImageBoundsSafe (gdImagePtr im, int x, int y){  return gdImageBoundsSafeMacro (im, x, y);}BGD_DECLARE(void) gdImageChar (gdImagePtr im, gdFontPtr f, int x, int y, int c, int color){  int cx, cy;  int px, py;  int fline;  cx = 0;  cy = 0;#ifdef CHARSET_EBCDIC  c = ASC (c);#endif /*CHARSET_EBCDIC */  if ((c < f->offset) || (c >= (f->offset + f->nchars)))    {      return;    }  fline = (c - f->offset) * f->h * f->w;  for (py = y; (py < (y + f->h)); py++)    {      for (px = x; (px < (x + f->w)); px++)	{	  if (f->data[fline + cy * f->w + cx])	    {	      gdImageSetPixel (im, px, py, color);	    }	  cx++;	}      cx = 0;      cy++;    }}BGD_DECLARE(void) gdImageCharUp (gdImagePtr im, gdFontPtr f, int x, int y, int c, int color){  int cx, cy;  int px, py;  int fline;  cx = 0;  cy = 0;#ifdef CHARSET_EBCDIC  c = ASC (c);#endif /*CHARSET_EBCDIC */  if ((c < f->offset) || (c >= (f->offset + f->nchars)))    {      return;    }  fline = (c - f->offset) * f->h * f->w;  for (py = y; (py > (y - f->w)); py--)    {      for (px = x; (px < (x + f->h)); px++)	{	  if (f->data[fline + cy * f->w + cx])	    {	      gdImageSetPixel (im, px, py, color);	    }	  cy++;	}      cy = 0;      cx++;    }}BGD_DECLARE(void) gdImageString (gdImagePtr im, gdFontPtr f,	       int x, int y, unsigned char *s, int color){  int i;  int l;  l = strlen ((char *) s);  for (i = 0; (i < l); i++)    {      gdImageChar (im, f, x, y, s[i], color);      x += f->w;    }}BGD_DECLARE(void) gdImageStringUp (gdImagePtr im, gdFontPtr f,		 int x, int y, unsigned char *s, int color){  int i;  int l;  l = strlen ((char *) s);  for (i = 0; (i < l); i++)    {      gdImageCharUp (im, f, x, y, s[i], color);      y -= f->w;    }}static int strlen16 (unsigned short *s);BGD_DECLARE(void) gdImageString16 (gdImagePtr im, gdFontPtr f,		 int x, int y, unsigned short *s, int color){  int i;  int l;  l = strlen16 (s);  for (i = 0; (i < l); i++)    {      gdImageChar (im, f, x, y, s[i], color);      x += f->w;    }}BGD_DECLARE(void) gdImageStringUp16 (gdImagePtr im, gdFontPtr f,		   int x, int y, unsigned short *s, int color){  int i;  int l;  l = strlen16 (s);  for (i = 0; (i < l); i++)    {      gdImageCharUp (im, f, x, y, s[i], color);      y -= f->w;    }}static intstrlen16 (unsigned short *s){  int len = 0;  while (*s)    {      s++;      len++;    }  return len;}#ifndef HAVE_LSQRT/* If you don't have a nice square root function for longs, you can use   ** this hack */longlsqrt (long n){  long result = (long) sqrt ((double) n);  return result;}#endif/* s and e are integers modulo 360 (degrees), with 0 degrees   being the rightmost extreme and degrees changing clockwise.   cx and cy are the center in pixels; w and h are the horizontal    and vertical diameter in pixels. Nice interface, but slow.   See gd_arc_f_buggy.c for a better version that doesn't    seem to be bug-free yet. */BGD_DECLARE(void) gdImageArc (gdImagePtr im, int cx, int cy, int w, int h, int s, int e,	    int color){  gdImageFilledArc (im, cx, cy, w, h, s, e, color, gdNoFill);}BGD_DECLARE(void) gdImageFilledArc (gdImagePtr im, int cx, int cy, int w, int h, int s, int e,		  int color, int style){  gdPoint pts[3];  int i;  int lx = 0, ly = 0;  int fx = 0, fy = 0;  while (e < s)    {      e += 360;    }  for (i = s; (i <= e); i++)    {      int x, y;      x = ((long) gdCosT[i % 360] * (long) w / (2 * 1024)) + cx;      y = ((long) gdSinT[i % 360] * (long) h / (2 * 1024)) + cy;      if (i != s)	{	  if (!(style & gdChord))	    {	      if (style & gdNoFill)		{		  gdImageLine (im, lx, ly, x, y, color);		}	      else		{		  /* This is expensive! */		  pts[0].x = lx;		  pts[0].y = ly;		  pts[1].x = x;		  pts[1].y = y;		  pts[2].x = cx;		  pts[2].y = cy;		  gdImageFilledPolygon (im, pts, 3, color);		}	    }	}      else	{	  fx = x;	  fy = y;	}      lx = x;      ly = y;    }  if (style & gdChord)    {      if (style & gdNoFill)	{	  if (style & gdEdged)	    {	      gdImageLine (im, cx, cy, lx, ly, color);	      gdImageLine (im, cx, cy, fx, fy, color);	    }	  gdImageLine (im, fx, fy, lx, ly, color);	}      else	{	  pts[0].x = fx;	  pts[0].y = fy;	  pts[1].x = lx;	  pts[1].y = ly;	  pts[2].x = cx;	  pts[2].y = cy;	  gdImageFilledPolygon (im, pts, 3, color);	}    }  else    {      if (style & gdNoFill)	{	  if (style & gdEdged)	    {	      gdImageLine (im, cx, cy, lx, ly, color);	      gdImageLine (im, cx, cy, fx, fy, color);	    }	}    }}BGD_DECLARE(void) gdImageFilledEllipse (gdImagePtr im, int cx, int cy, int w, int h, int color){  gdImageFilledArc (im, cx, cy, w, h, 0, 360, color, gdPie);}BGD_DECLARE(void) gdImageFillToBorder (gdImagePtr im, int x, int y, int border, int color){  int lastBorder;  /* Seek left */  int leftLimit, rightLimit;  int i;  leftLimit = (-1);  if (border < 0)    {      /* Refuse to fill to a non-solid border */      return;    }  for (i = x; (i >= 0); i--)    {      if (gdImageGetPixel (im, i, y) == border)	{	  break;	}      gdImageSetPixel (im, i, y, color);      leftLimit = i;    }  if (leftLimit == (-1))    {      return;    }  /* Seek right */  rightLimit = x;  for (i = (x + 1); (i < im->sx); i++)    {      if (gdImageGetPixel (im, i, y) == border)	{	  break;	}      gdImageSetPixel (im, i, y, color);      rightLimit = i;    }  /* Look at lines above and below and start paints */  /* Above */  if (y > 0)    {      lastBorder = 1;      for (i = leftLimit; (i <= rightLimit); i++)	{	  int c;	  c = gdImageGetPixel (im, i, y - 1);	  if (lastBorder)	    {	      if ((c != border) && (c != color))		{		  gdImageFillToBorder (im, i, y - 1, border, color);		  lastBorder = 0;		}	    }	  else if ((c == border) || (c == color))	    {	      lastBorder = 1;	    }	}    }  /* Below */  if (y < ((im->sy) - 1))    {      lastBorder = 1;      for (i = leftLimit; (i <= rightLimit); i++)	{	  int c;	  c = gdImageGetPixel (im, i, y + 1);	  if (lastBorder)	    {	      if ((c != border) && (c != color))		{		  gdImageFillToBorder (im, i, y + 1, border, color);		  lastBorder = 0;		}	    }	  else if ((c == border) || (c == color))	    {	      lastBorder = 1;	    }	}    }}BGD_DECLARE(void) gdImageFill (gdImagePtr im, int x, int y, int color){  int lastBorder;  int old;  int leftLimit, rightLimit;  int i;  old = gdImageGetPixel (im, x, y);  if (color == gdTiled)    {      /* Tile fill -- got to watch out! */      int p, tileColor;      int srcx, srcy;      if (!im->tile)	{	  return;	}      /* Refuse to flood-fill with a transparent pattern --         I can't do it without allocating another image */      if (gdImageGetTransparent (im->tile) != (-1))	{	  return;	}      srcx = x % gdImageSX (im->tile);      srcy = y % gdImageSY (im->tile);      p = gdImageGetPixel (im->tile, srcx, srcy);      if (im->trueColor)	{	  tileColor = p;	}      else	{	  if (im->tile->trueColor)	    {	      tileColor = gdImageColorResolveAlpha (im,						    gdTrueColorGetRed (p),						    gdTrueColorGetGreen (p),						    gdTrueColorGetBlue (p),						    gdTrueColorGetAlpha (p));	    }	  else	    {	      tileColor = im->tileColorMap[p];	    }	}      if (old == tileColor)	{	  /* Nothing to be done */	  return;	}    }  else    {      if (old == color)	{	  /* Nothing to be done */	  return;	}    }  /* Seek left */  leftLimit = (-1);  for (i = x; (i >= 0); i--)    {      if (gdImageGetPixel (im, i, y) != old)	{	  break;	}      gdImageSetPixel (im, i, y, color);      leftLimit = i;    }  if (leftLimit == (-1))    {      return;    }  /* Seek right */  rightLimit = x;  for (i = (x + 1); (i < im->sx); i++)    {      if (gdImageGetPixel (im, i, y) != old)	{	  break;	}      gdImageSetPixel (im, i, y, color);      rightLimit = i;    }  /* Look at lines above and below and start paints */  /* Above */  if (y > 0)    {      lastBorder = 1;      for (i = leftLimit; (i <= rightLimit); i++)	{	  int c;	  c = gdImageGetPixel (im, i, y - 1);	  if (lastBorder)	    {	      if (c == old)		{		  gdImageFill (im, i, y - 1, color);		  lastBorder = 0;		}	    }	  else if (c != old)	    {	      lastBorder = 1;	    }	}    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -