Back to index

wims  3.65+svn20090927
Classes | Defines | Typedefs | Functions
gd.h File Reference
#include <stdio.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  gdImageStruct
struct  gdFont
struct  gdPoint

Defines

#define gdMaxColors   256
#define gdDashSize   4
#define gdStyled   (-2)
#define gdBrushed   (-3)
#define gdStyledBrushed   (-4)
#define gdTiled   (-5)
#define gdTransparent   (-6)
#define gdImageSX(im)   ((im)->sx)
#define gdImageSY(im)   ((im)->sy)
#define gdImageColorsTotal(im)   ((im)->colorsTotal)
#define gdImageRed(im, c)   ((im)->red[(c)])
#define gdImageGreen(im, c)   ((im)->green[(c)])
#define gdImageBlue(im, c)   ((im)->blue[(c)])
#define gdImageGetTransparent(im)   ((im)->transparent)
#define gdImageGetInterlaced(im)   ((im)->interlace)

Typedefs

typedef struct gdImageStruct gdImage
typedef gdImagegdImagePtr
typedef gdFontgdFontPtr
typedef struct gdPointgdPointPtr

Functions

gdImagePtr gdImageCreate (int sx, int sy)
gdImagePtr gdImageCreateFromGif (FILE *fd)
gdImagePtr gdImageCreateFromGd (FILE *in)
gdImagePtr gdImageCreateFromXbm (FILE *fd)
void gdImageDestroy (gdImagePtr im)
void gdImageSetPixel (gdImagePtr im, int x, int y, int color)
int gdImageGetPixel (gdImagePtr im, int x, int y)
void gdImageLine (gdImagePtr im, int x1, int y1, int x2, int y2, int color)
void gdImageDashedLine (gdImagePtr im, int x1, int y1, int x2, int y2, int color)
void gdImageRectangle (gdImagePtr im, int x1, int y1, int x2, int y2, int color)
void gdImageFilledRectangle (gdImagePtr im, int x1, int y1, int x2, int y2, int color)
int gdImageBoundsSafe (gdImagePtr im, int x, int y)
void gdImageChar (gdImagePtr im, gdFontPtr f, int x, int y, int c, int color)
void gdImageCharUp (gdImagePtr im, gdFontPtr f, int x, int y, char c, int color)
void gdImageString (gdImagePtr im, gdFontPtr f, int x, int y, char *s, int color)
void gdImageStringUp (gdImagePtr im, gdFontPtr f, int x, int y, char *s, int color)
void gdImagePolygon (gdImagePtr im, gdPointPtr p, int n, int c)
void gdImageFilledPolygon (gdImagePtr im, gdPointPtr p, int n, int c)
int gdImageColorAllocate (gdImagePtr im, int r, int g, int b)
int gdImageColorClosest (gdImagePtr im, int r, int g, int b)
int gdImageColorExact (gdImagePtr im, int r, int g, int b)
void gdImageColorDeallocate (gdImagePtr im, int color)
void gdImageColorTransparent (gdImagePtr im, int color)
void gdImageGif (gdImagePtr im, FILE *out)
void gdImageGd (gdImagePtr im, FILE *out)
void gdImageArc (gdImagePtr im, int cx, int cy, int w, int h, int s, int e, int color)
void gdImageFillToBorder (gdImagePtr im, int x, int y, int border, int color)
void gdImageFill (gdImagePtr im, int x, int y, int color)
void gdImageCopy (gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int w, int h)
void gdImageCopyResized (gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH)
void gdImageSetBrush (gdImagePtr im, gdImagePtr brush)
void gdImageSetTile (gdImagePtr im, gdImagePtr tile)
void gdImageSetStyle (gdImagePtr im, int *style, int noOfPixels)
void gdImageInterlace (gdImagePtr im, int interlaceArg)

Class Documentation

struct gdImageStruct

Definition at line 26 of file gd.h.

Collaboration diagram for gdImageStruct:
Class Members
int blue
struct gdImageStruct * brush
int brushColorMap
int colorsTotal
int green
int interlace
int open
unsigned char ** pixels
int polyAllocated
int * polyInts
int red
int * style
int styleLength
int stylePos
int sx
int sy
struct gdImageStruct * tile
int tileColorMap
int transparent
struct gdFont

Definition at line 50 of file gd.h.

Class Members
char * data
int h
int nchars
int offset
int w
struct gdPoint

Definition at line 109 of file gd.h.

Class Members
int x
int y

Define Documentation

#define gdBrushed   (-3)

Definition at line 75 of file gd.h.

#define gdDashSize   4

Definition at line 70 of file gd.h.

#define gdImageBlue (   im,
 
)    ((im)->blue[(c)])

Definition at line 142 of file gd.h.

#define gdImageColorsTotal (   im)    ((im)->colorsTotal)

Definition at line 139 of file gd.h.

#define gdImageGetInterlaced (   im)    ((im)->interlace)

Definition at line 144 of file gd.h.

#define gdImageGetTransparent (   im)    ((im)->transparent)

Definition at line 143 of file gd.h.

#define gdImageGreen (   im,
 
)    ((im)->green[(c)])

Definition at line 141 of file gd.h.

#define gdImageRed (   im,
 
)    ((im)->red[(c)])

Definition at line 140 of file gd.h.

#define gdImageSX (   im)    ((im)->sx)

Definition at line 137 of file gd.h.

#define gdImageSY (   im)    ((im)->sy)

Definition at line 138 of file gd.h.

#define gdMaxColors   256

Definition at line 19 of file gd.h.

#define gdStyled   (-2)

Definition at line 74 of file gd.h.

#define gdStyledBrushed   (-4)

Definition at line 76 of file gd.h.

#define gdTiled   (-5)

Definition at line 77 of file gd.h.

#define gdTransparent   (-6)

Definition at line 81 of file gd.h.


Typedef Documentation

typedef gdFont* gdFontPtr

Definition at line 65 of file gd.h.

typedef struct gdImageStruct gdImage
typedef gdImage* gdImagePtr

Definition at line 48 of file gd.h.

typedef struct gdPoint * gdPointPtr

Function Documentation

void gdImageArc ( gdImagePtr  im,
int  cx,
int  cy,
int  w,
int  h,
int  s,
int  e,
int  color 
)

Definition at line 499 of file gd.c.

{
       int i;
       int lx = 0, ly = 0;
       int w2, h2;
       w2 = w/2;
       h2 = h/2;
       while (e < s) {
              e += 360;
       }
       for (i=s; (i <= e); i++) {
              int x, y;
              x = ((long)cost[i % 360] * (long)w2 / costScale) + cx; 
              y = ((long)sint[i % 360] * (long)h2 / sintScale) + cy;
              if (i != s) {
                     gdImageLine(im, lx, ly, x, y, color);     
              }
              lx = x;
              ly = y;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

int gdImageBoundsSafe ( gdImagePtr  im,
int  x,
int  y 
)

Definition at line 415 of file gd.c.

{
       return (!(((y < 0) || (y >= im->sy)) ||
              ((x < 0) || (x >= im->sx))));
}

Here is the caller graph for this function:

void gdImageChar ( gdImagePtr  im,
gdFontPtr  f,
int  x,
int  y,
int  c,
int  color 
)

Definition at line 421 of file gd.c.

{
       int cx, cy;
       int px, py;
       int fline;
       cx = 0;
       cy = 0;
       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++;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void gdImageCharUp ( gdImagePtr  im,
gdFontPtr  f,
int  x,
int  y,
char  c,
int  color 
)

Definition at line 444 of file gd.c.

{
       int cx, cy;
       int px, py;
       int fline;
       cx = 0;
       cy = 0;
       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++;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

int gdImageColorAllocate ( gdImagePtr  im,
int  r,
int  g,
int  b 
)

Definition at line 90 of file gd.c.

{
       int i;
       int ct = (-1);
       for (i=0; (i<(im->colorsTotal)); i++) {
              if (im->open[i]) {
                     ct = i;
                     break;
              }
       }      
       if (ct == (-1)) {
              ct = im->colorsTotal;
              if (ct == gdMaxColors) {
                     return -1;
              }
              im->colorsTotal++;
       }
       im->red[ct] = r;
       im->green[ct] = g;
       im->blue[ct] = b;
       im->open[ct] = 0;
       return ct;
}

Here is the caller graph for this function:

int gdImageColorClosest ( gdImagePtr  im,
int  r,
int  g,
int  b 
)

Definition at line 51 of file gd.c.

{
       int i;
       long rd, gd, bd;
       int ct = (-1);
       long mindist = 0;
       for (i=0; (i<(im->colorsTotal)); i++) {
              long dist;
              if (im->open[i]) {
                     continue;
              }
              rd = (im->red[i] - r);      
              gd = (im->green[i] - g);
              bd = (im->blue[i] - b);
              dist = rd * rd + gd * gd + bd * bd;
              if ((i == 0) || (dist < mindist)) {
                     mindist = dist;      
                     ct = i;
              }
       }
       return ct;
}

Here is the caller graph for this function:

void gdImageColorDeallocate ( gdImagePtr  im,
int  color 
)

Definition at line 114 of file gd.c.

{
       /* Mark it open. */
       im->open[color] = 1;
}
int gdImageColorExact ( gdImagePtr  im,
int  r,
int  g,
int  b 
)

Definition at line 74 of file gd.c.

{
       int i;
       for (i=0; (i<(im->colorsTotal)); i++) {
              if (im->open[i]) {
                     continue;
              }
              if ((im->red[i] == r) && 
                     (im->green[i] == g) &&
                     (im->blue[i] == b)) {
                     return i;
              }
       }
       return -1;
}

Here is the caller graph for this function:

void gdImageColorTransparent ( gdImagePtr  im,
int  color 
)

Definition at line 120 of file gd.c.

{
       im->transparent = color;
}

Here is the caller graph for this function:

void gdImageCopy ( gdImagePtr  dst,
gdImagePtr  src,
int  dstX,
int  dstY,
int  srcX,
int  srcY,
int  w,
int  h 
)

Definition at line 1973 of file gd.c.

{
       int c;
       int x, y;
       int tox, toy;
       int i;
       int colorMap[gdMaxColors];
       for (i=0; (i<gdMaxColors); i++) {
              colorMap[i] = (-1);
       }
       toy = dstY;
       for (y=srcY; (y < (srcY + h)); y++) {
              tox = dstX;
              for (x=srcX; (x < (srcX + w)); x++) {
                     int nc;
                     c = gdImageGetPixel(src, x, y);
                     /* Added 7/24/95: support transparent copies */
                     if (gdImageGetTransparent(src) == c) {
                            tox++;
                            continue;
                     }
                     /* Have we established a mapping for this color? */
                     if (colorMap[c] == (-1)) {
                            /* If it's the same image, mapping is trivial */
                            if (dst == src) {
                                   nc = c;
                            } else { 
                                   /* First look for an exact match */
                                   nc = gdImageColorExact(dst,
                                          src->red[c], src->green[c],
                                          src->blue[c]);
                            }      
                            if (nc == (-1)) {
                                   /* No, so try to allocate it */
                                   nc = gdImageColorAllocate(dst,
                                          src->red[c], src->green[c],
                                          src->blue[c]);
                                   /* If we're out of colors, go for the
                                          closest color */
                                   if (nc == (-1)) {
                                          nc = gdImageColorClosest(dst,
                                                 src->red[c], src->green[c],
                                                 src->blue[c]);
                                   }
                            }
                            colorMap[c] = nc;
                     }
                     gdImageSetPixel(dst, tox, toy, colorMap[c]);
                     tox++;
              }
              toy++;
       }
}                    

Here is the call graph for this function:

Here is the caller graph for this function:

void gdImageCopyResized ( gdImagePtr  dst,
gdImagePtr  src,
int  dstX,
int  dstY,
int  srcX,
int  srcY,
int  dstW,
int  dstH,
int  srcW,
int  srcH 
)

Definition at line 2027 of file gd.c.

{
       int c;
       int x, y;
       int tox, toy;
       int ydest;
       int i;
       int colorMap[gdMaxColors];
       /* Stretch vectors */
       int *stx;
       int *sty;
       /* We only need to use floating point to determine the correct
              stretch vector for one line's worth. */
       double accum;
       stx = (int *) malloc(sizeof(int) * srcW);
       sty = (int *) malloc(sizeof(int) * srcH);
       accum = 0;
       for (i=0; (i < srcW); i++) {
              int got;
              accum += (double)dstW/(double)srcW;
              got = floor(accum);
              stx[i] = got;
              accum -= got;
       }
       accum = 0;
       for (i=0; (i < srcH); i++) {
              int got;
              accum += (double)dstH/(double)srcH;
              got = floor(accum);
              sty[i] = got;
              accum -= got;
       }
       for (i=0; (i<gdMaxColors); i++) {
              colorMap[i] = (-1);
       }
       toy = dstY;
       for (y=srcY; (y < (srcY + srcH)); y++) {
              for (ydest=0; (ydest < sty[y-srcY]); ydest++) {
                     tox = dstX;
                     for (x=srcX; (x < (srcX + srcW)); x++) {
                            int nc;
                            if (!stx[x - srcX]) {
                                   continue;
                            }
                            c = gdImageGetPixel(src, x, y);
                            /* Added 7/24/95: support transparent copies */
                            if (gdImageGetTransparent(src) == c) {
                                   tox += stx[x-srcX];
                                   continue;
                            }
                            /* Have we established a mapping for this color? */
                            if (colorMap[c] == (-1)) {
                                   /* If it's the same image, mapping is trivial */
                                   if (dst == src) {
                                          nc = c;
                                   } else { 
                                          /* First look for an exact match */
                                          nc = gdImageColorExact(dst,
                                                 src->red[c], src->green[c],
                                                 src->blue[c]);
                                   }      
                                   if (nc == (-1)) {
                                          /* No, so try to allocate it */
                                          nc = gdImageColorAllocate(dst,
                                                 src->red[c], src->green[c],
                                                 src->blue[c]);
                                          /* If we're out of colors, go for the
                                                 closest color */
                                          if (nc == (-1)) {
                                                 nc = gdImageColorClosest(dst,
                                                        src->red[c], src->green[c],
                                                        src->blue[c]);
                                          }
                                   }
                                   colorMap[c] = nc;
                            }
                            for (i=0; (i < stx[x - srcX]); i++) {
                                   gdImageSetPixel(dst, tox, toy, colorMap[c]);
                                   tox++;
                            }
                     }
                     toy++;
              }
       }
       free(stx);
       free(sty);
}

Here is the call graph for this function:

Here is the caller graph for this function:

gdImagePtr gdImageCreate ( int  sx,
int  sy 
)

Definition at line 12 of file gd.c.

{
       int i;
       gdImagePtr im;
       im = (gdImage *) malloc(sizeof(gdImage));
       im->pixels = (unsigned char **) malloc(sizeof(unsigned char *) * sx);
       im->polyInts = 0;
       im->polyAllocated = 0;
       im->brush = 0;
       im->tile = 0;
       im->style = 0;
       for (i=0; (i<sx); i++) {
              im->pixels[i] = (unsigned char *) calloc(
                     sy, sizeof(unsigned char));
       }      
       im->sx = sx;
       im->sy = sy;
       im->colorsTotal = 0;
       im->transparent = (-1);
       im->interlace = 0;
       return im;
}

Here is the caller graph for this function:

Definition at line 2148 of file gd.c.

{
       int sx, sy;
       int x, y;
       int i;
       gdImagePtr im;
       if (!gdGetWord(&sx, in)) {
              goto fail1;
       }
       if (!gdGetWord(&sy, in)) {
              goto fail1;
       }
       im = gdImageCreate(sx, sy);
       if (!gdGetByte(&im->colorsTotal, in)) {
              goto fail2;
       }
       if (!gdGetWord(&im->transparent, in)) {
              goto fail2;
       }
       if (im->transparent == 257) {
              im->transparent = (-1);
       }
       for (i=0; (i<gdMaxColors); i++) {
              if (!gdGetByte(&im->red[i], in)) {
                     goto fail2;
              }
              if (!gdGetByte(&im->green[i], in)) {
                     goto fail2;
              }
              if (!gdGetByte(&im->blue[i], in)) {
                     goto fail2;
              }
       }      
       for (y=0; (y<sy); y++) {
              for (x=0; (x<sx); x++) {    
                     int ch;
                     ch = getc(in);
                     if (ch == EOF) {
                            gdImageDestroy(im);
                            return 0;
                     }
                     im->pixels[x][y] = ch;
              }
       }
       return im;
fail2:
       gdImageDestroy(im);
fail1:
       return 0;
}

Here is the call graph for this function:

Definition at line 1536 of file gd.c.

{
       int imageNumber;
       int BitPixel;
       int ColorResolution;
       int Background;
       int AspectRatio;
       int Transparent = (-1);
       unsigned char   buf[16];
       unsigned char   c;
       unsigned char   ColorMap[3][MAXCOLORMAPSIZE];
       unsigned char   localColorMap[3][MAXCOLORMAPSIZE];
       int             imw, imh;
       int             useGlobalColormap;
       int             bitPixel;
       int             imageCount = 0;
       char            version[4];
       gdImagePtr im = 0;
       ZeroDataBlock = FALSE;

       imageNumber = 1;
       if (! ReadOK(fd,buf,6)) {
              return 0;
       }
       if (strncmp((char *)buf,"GIF",3) != 0) {
              return 0;
       }
       strncpy(version, (char *)buf + 3, 3);
       version[3] = '\0';

       if ((strcmp(version, "87a") != 0) && (strcmp(version, "89a") != 0)) {
              return 0;
       }
       if (! ReadOK(fd,buf,7)) {
              return 0;
       }
       BitPixel        = 2<<(buf[4]&0x07);
       ColorResolution = (int) (((buf[4]&0x70)>>3)+1);
       Background      = buf[5];
       AspectRatio     = buf[6];

       if (BitSet(buf[4], LOCALCOLORMAP)) {    /* Global Colormap */
               if (ReadColorMap(fd, BitPixel, ColorMap)) {
                     return 0;
              }
       }
       for (;;) {
               if (! ReadOK(fd,&c,1)) {
                       return 0;
               }
               if (c == ';') {         /* GIF terminator */
                       int i;
                       if (imageCount < imageNumber) {
                               return 0;
                       }
                       /* Terminator before any image was declared! */
                       if (!im) {
                              return 0;
                       }
                     /* Check for open colors at the end, so
                          we can reduce colorsTotal and ultimately
                          BitsPerPixel */
                       for (i=((im->colorsTotal-1)); (i>=0); i--) {
                               if (im->open[i]) {
                                       im->colorsTotal--;
                               } else {
                                       break;
                               }
                       } 
                       return im;
               }

               if (c == '!') {         /* Extension */
                       if (! ReadOK(fd,&c,1)) {
                               return 0;
                       }
                       DoExtension(fd, c, &Transparent);
                       continue;
               }

               if (c != ',') {         /* Not a valid start character */
                       continue;
               }

               ++imageCount;

               if (! ReadOK(fd,buf,9)) {
                      return 0;
               }

               useGlobalColormap = ! BitSet(buf[8], LOCALCOLORMAP);

               bitPixel = 1<<((buf[8]&0x07)+1);

               imw = LM_to_uint(buf[4],buf[5]);
               imh = LM_to_uint(buf[6],buf[7]);
              if (!(im = gdImageCreate(imw, imh))) {
                      return 0;
              }
               im->interlace = BitSet(buf[8], INTERLACE);
               if (! useGlobalColormap) {
                       if (ReadColorMap(fd, bitPixel, localColorMap)) { 
                                 return 0;
                       }
                       ReadImage(im, fd, imw, imh, localColorMap, 
                                 BitSet(buf[8], INTERLACE), 
                                 imageCount != imageNumber);
               } else {
                       ReadImage(im, fd, imw, imh,
                                 ColorMap, 
                                 BitSet(buf[8], INTERLACE), 
                                 imageCount != imageNumber);
               }
               if (Transparent != (-1)) {
                       gdImageColorTransparent(im, Transparent);
               }        
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2225 of file gd.c.

{
       gdImagePtr im;       
       int bit;
       int w, h;
       int bytes;
       int ch;
       int i, x, y;
       char *sp;
       char s[161];
       if (!fgets(s, 160, fd)) {
              return 0;
       }
       sp = &s[0];
       /* Skip #define */
       sp = strchr(sp, ' ');
       if (!sp) {
              return 0;
       }
       /* Skip width label */
       sp++;
       sp = strchr(sp, ' ');
       if (!sp) {
              return 0;
       }
       /* Get width */
       w = atoi(sp + 1);
       if (!w) {
              return 0;
       }
       if (!fgets(s, 160, fd)) {
              return 0;
       }
       sp = s;
       /* Skip #define */
       sp = strchr(sp, ' ');
       if (!sp) {
              return 0;
       }
       /* Skip height label */
       sp++;
       sp = strchr(sp, ' ');
       if (!sp) {
              return 0;
       }
       /* Get height */
       h = atoi(sp + 1);
       if (!h) {
              return 0;
       }
       /* Skip declaration line */
       if (!fgets(s, 160, fd)) {
              return 0;
       }
       bytes = (w * h / 8) + 1;
       im = gdImageCreate(w, h);
       gdImageColorAllocate(im, 255, 255, 255);
       gdImageColorAllocate(im, 0, 0, 0);
       x = 0;
       y = 0;
       for (i=0; (i < bytes); i++) {
              char h[3];
              int b;
              /* Skip spaces, commas, CRs, 0x */
              while(1) {
                     ch = getc(fd);
                     if (ch == EOF) {
                            goto fail;
                     }
                     if (ch == 'x') {
                            break;
                     }      
              }
              /* Get hex value */
              ch = getc(fd);
              if (ch == EOF) {
                     goto fail;
              }
              h[0] = ch;
              ch = getc(fd);
              if (ch == EOF) {
                     goto fail;
              }
              h[1] = ch;
              h[2] = '\0';
              sscanf(h, "%x", &b);        
              for (bit = 1; (bit <= 128); (bit = bit << 1)) {
                     gdImageSetPixel(im, x++, y, (b & bit) ? 1 : 0);  
                     if (x == im->sx) {
                            x = 0;
                            y++;
                            if (y == im->sy) {
                                   return im;
                            }
                            /* Fix 8/8/95 */
                            break;
                     }
              }
       }
       /* Shouldn't happen */
       fprintf(stderr, "Error: bug in gdImageCreateFromXbm!\n");
       return 0;
fail:
       gdImageDestroy(im);
       return 0;
}

Here is the call graph for this function:

void gdImageDashedLine ( gdImagePtr  im,
int  x1,
int  y1,
int  x2,
int  y2,
int  color 
)

Definition at line 327 of file gd.c.

{
       int dx, dy, incr1, incr2, d, x, y, xend, yend, xdirflag, ydirflag;
       int dashStep = 0;
       int on = 1;
       dx = abs(x2-x1);
       dy = abs(y2-y1);
       if (dy <= dx) {
              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;
              if (((y2 - y1) * ydirflag) > 0) {
                     while (x < xend) {
                            x++;
                            if (d <0) {
                                   d+=incr1;
                            } else {
                                   y++;
                                   d+=incr2;
                            }
                            dashedSet;
                     }
              } else {
                     while (x < xend) {
                            x++;
                            if (d <0) {
                                   d+=incr1;
                            } else {
                                   y--;
                                   d+=incr2;
                            }
                            dashedSet;
                     }
              }             
       } else {
              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;
              if (((x2 - x1) * xdirflag) > 0) {
                     while (y < yend) {
                            y++;
                            if (d <0) {
                                   d+=incr1;
                            } else {
                                   x++;
                                   d+=incr2;
                            }
                            dashedSet;
                     }
              } else {
                     while (y < yend) {
                            y++;
                            if (d <0) {
                                   d+=incr1;
                            } else {
                                   x--;
                                   d+=incr2;
                            }
                            dashedSet;
                     }
              }
       }
}

Here is the caller graph for this function:

void gdImageDestroy ( gdImagePtr  im)

Definition at line 35 of file gd.c.

{
       int i;
       for (i=0; (i<im->sx); i++) {
              free(im->pixels[i]);
       }      
       free(im->pixels);
       if (im->polyInts) {
                     free(im->polyInts);
       }
       if (im->style) {
              free(im->style);
       }
       free(im);
}

Here is the caller graph for this function:

void gdImageFill ( gdImagePtr  im,
int  x,
int  y,
int  color 
)

Definition at line 612 of file gd.c.

{
       int lastBorder;
       int old;
       int leftLimit, rightLimit;
       int i;
        /* XIAO: overboard */
        if(x<0 || y<0 || x>=im->sx || y>=im->sy) return;
       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);
              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;
                     }
              }
       }
       /* 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 == old) {
                                   gdImageFill(im, i, y+1, color);           
                                   lastBorder = 0;
                            }
                     } else if (c != old) {
                            lastBorder = 1;
                     }
              }
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void gdImageFilledPolygon ( gdImagePtr  im,
gdPointPtr  p,
int  n,
int  c 
)

Definition at line 2352 of file gd.c.

{
       int i;
       int y;
       int y1, y2;
       int ints;
       if (!n) {
              return;
       }
       if (!im->polyAllocated) {
              im->polyInts = (int *) malloc(sizeof(int) * n);
              im->polyAllocated = n;
       }             
       if (im->polyAllocated < n) {
              while (im->polyAllocated < n) {
                     im->polyAllocated *= 2;
              }      
              im->polyInts = (int *) realloc(im->polyInts,
                     sizeof(int) * im->polyAllocated);
       }
       y1 = p[0].y;
       y2 = p[0].y;
       for (i=1; (i < n); i++) {
              if (p[i].y < y1) {
                     y1 = p[i].y;
              }
              if (p[i].y > y2) {
                     y2 = p[i].y;
              }
       }
       for (y=y1; (y <= y2); y++) {
              int interLast = 0;
              int dirLast = 0;
              int interFirst = 1;
              ints = 0;
              for (i=0; (i <= n); i++) {
                     int x1, x2;
                     int y1, y2;
                     int dir;
                     int ind1, ind2;
                     int lastInd1 = 0;
                     if ((i == n) || (!i)) {
                            ind1 = n-1;
                            ind2 = 0;
                     } else {
                            ind1 = i-1;
                            ind2 = i;
                     }
                     y1 = p[ind1].y;
                     y2 = p[ind2].y;
                     if (y1 < y2) {
                            y1 = p[ind1].y;
                            y2 = p[ind2].y;
                            x1 = p[ind1].x;
                            x2 = p[ind2].x;
                            dir = -1;
                     } else if (y1 > y2) {
                            y2 = p[ind1].y;
                            y1 = p[ind2].y;
                            x2 = p[ind1].x;
                            x1 = p[ind2].x;
                            dir = 1;
                     } else {
                            /* Horizontal; just draw it */
                            gdImageLine(im, 
                                   p[ind1].x, y1, 
                                   p[ind2].x, y1,
                                   c);
                            continue;
                     }
                     if ((y >= y1) && (y <= y2)) {
                            int inter = 
                                   (y-y1) * (x2-x1) / (y2-y1) + x1;
                            /* Only count intersections once
                                   except at maxima and minima. Also, 
                                   if two consecutive intersections are
                                   endpoints of the same horizontal line
                                   that is not at a maxima or minima, 
                                   discard the leftmost of the two. */
                            if (!interFirst) {
                                   if ((p[ind1].y == p[lastInd1].y) &&
                                          (p[ind1].x != p[lastInd1].x)) {
                                          if (dir == dirLast) {
                                                 if (inter > interLast) {
                                                        /* Replace the old one */
                                                        im->polyInts[ints] = inter;
                                                 } else {
                                                        /* Discard this one */
                                                 }      
                                                 continue;
                                          }
                                   }
                                   if (inter == interLast) {
                                          if (dir == dirLast) {
                                                 continue;
                                          }
                                   }
                            } 
                            if (i > 0) {
                                   im->polyInts[ints++] = inter;
                            }
                            lastInd1 = i;
                            dirLast = dir;
                            interLast = inter;
                            interFirst = 0;
                     }
              }
              qsort(im->polyInts, ints, sizeof(int), gdCompareInt);
              for (i=0; (i < (ints-1)); i+=2) {
                     gdImageLine(im, im->polyInts[i], y,
                            im->polyInts[i+1], y, c);
              }
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void gdImageFilledRectangle ( gdImagePtr  im,
int  x1,
int  y1,
int  x2,
int  y2,
int  color 
)

Definition at line 1963 of file gd.c.

{
       int x, y;
       for (y=y1; (y<=y2); y++) {
              for (x=x1; (x<=x2); x++) {
                     gdImageSetPixel(im, x, y, color);
              }
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void gdImageFillToBorder ( gdImagePtr  im,
int  x,
int  y,
int  border,
int  color 
)

Definition at line 543 of file gd.c.

{
       int lastBorder;
       /* Seek left */
       int leftLimit, rightLimit;
       int i;
        /* XIAO: overboard */
        if(x<0 || y<0 || x>=im->sx || y>=im->sy) return;
       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;
                     }
              }
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void gdImageGd ( gdImagePtr  im,
FILE *  out 
)

Definition at line 2199 of file gd.c.

{
       int x, y;
       int i;
       int trans;
       gdPutWord(im->sx, out);
       gdPutWord(im->sy, out);
       putc((unsigned char)im->colorsTotal, out);
       trans = im->transparent;
       if (trans == (-1)) {
              trans = 257;
       }      
       gdPutWord(trans, out);
       for (i=0; (i<gdMaxColors); i++) {
              putc((unsigned char)im->red[i], out);
              putc((unsigned char)im->green[i], out);   
              putc((unsigned char)im->blue[i], out);    
       }
       for (y=0; (y < im->sy); y++) {     
              for (x=0; (x < im->sx); x++) {     
                     putc((unsigned char)im->pixels[x][y], out);
              }
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

int gdImageGetPixel ( gdImagePtr  im,
int  x,
int  y 
)

Definition at line 216 of file gd.c.

{
       if (gdImageBoundsSafe(im, x, y)) {
              return im->pixels[x][y];
       } else {
              return 0;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void gdImageGif ( gdImagePtr  im,
FILE *  out 
)

Definition at line 764 of file gd.c.

{
       int interlace, transparent, BitsPerPixel;
       interlace = im->interlace;
       transparent = im->transparent;

       BitsPerPixel = colorstobpp(im->colorsTotal);
       /* Clear any old values in statics strewn through the GIF code */
       init_statics();
       /* All set, let's do it. */
       GIFEncode(
              out, im->sx, im->sy, interlace, 0, transparent, BitsPerPixel,
              im->red, im->green, im->blue, im);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void gdImageInterlace ( gdImagePtr  im,
int  interlaceArg 
)

Definition at line 2536 of file gd.c.

{
       im->interlace = interlaceArg;
}

Here is the caller graph for this function:

void gdImageLine ( gdImagePtr  im,
int  x1,
int  y1,
int  x2,
int  y2,
int  color 
)

Definition at line 227 of file gd.c.

{
       int dx, dy, incr1, incr2, d, x, y, xend, yend, xdirflag, ydirflag;
       dx = abs(x2-x1);
       dy = abs(y2-y1);
       if (dy <= dx) {
              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;
              }
              gdImageSetPixel(im, x, y, color);
              if (((y2 - y1) * ydirflag) > 0) {
                     while (x < xend) {
                            x++;
                            if (d <0) {
                                   d+=incr1;
                            } else {
                                   y++;
                                   d+=incr2;
                            }
                            gdImageSetPixel(im, x, y, color);
                     }
              } else {
                     while (x < xend) {
                            x++;
                            if (d <0) {
                                   d+=incr1;
                            } else {
                                   y--;
                                   d+=incr2;
                            }
                            gdImageSetPixel(im, x, y, color);
                     }
              }             
       } else {
              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;
              }
              gdImageSetPixel(im, x, y, color);
              if (((x2 - x1) * xdirflag) > 0) {
                     while (y < yend) {
                            y++;
                            if (d <0) {
                                   d+=incr1;
                            } else {
                                   x++;
                                   d+=incr2;
                            }
                            gdImageSetPixel(im, x, y, color);
                     }
              } else {
                     while (y < yend) {
                            y++;
                            if (d <0) {
                                   d+=incr1;
                            } else {
                                   x--;
                                   d+=incr2;
                            }
                            gdImageSetPixel(im, x, y, color);
                     }
              }
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void gdImagePolygon ( gdImagePtr  im,
gdPointPtr  p,
int  n,
int  c 
)

Definition at line 2332 of file gd.c.

{
       int i;
       int lx, ly;
       if (!n) {
              return;
       }
       lx = p->x;
       ly = p->y;
       gdImageLine(im, lx, ly, p[n-1].x, p[n-1].y, c);
       for (i=1; (i < n); i++) {
              p++;
              gdImageLine(im, lx, ly, p->x, p->y, c);
              lx = p->x;
              ly = p->y;
       }
}      

Here is the call graph for this function:

Here is the caller graph for this function:

void gdImageRectangle ( gdImagePtr  im,
int  x1,
int  y1,
int  x2,
int  y2,
int  color 
)

Definition at line 1955 of file gd.c.

{
       gdImageLine(im, x1, y1, x2, y1, color);          
       gdImageLine(im, x1, y2, x2, y2, color);          
       gdImageLine(im, x1, y1, x1, y2, color);
       gdImageLine(im, x2, y1, x2, y2, color);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void gdImageSetBrush ( gdImagePtr  im,
gdImagePtr  brush 
)

Definition at line 2484 of file gd.c.

{
       int i;
       im->brush = brush;
       for (i=0; (i < gdImageColorsTotal(brush)); i++) {
              int index;
              index = gdImageColorExact(im, 
                     gdImageRed(brush, i),
                     gdImageGreen(brush, i),
                     gdImageBlue(brush, i));
              if (index == (-1)) {
                     index = gdImageColorAllocate(im,
                            gdImageRed(brush, i),
                            gdImageGreen(brush, i),
                            gdImageBlue(brush, i));
                     if (index == (-1)) {
                            index = gdImageColorClosest(im,
                                   gdImageRed(brush, i),
                                   gdImageGreen(brush, i),
                                   gdImageBlue(brush, i));
                     }
              }
              im->brushColorMap[i] = index;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void gdImageSetPixel ( gdImagePtr  im,
int  x,
int  y,
int  color 
)

Definition at line 125 of file gd.c.

{
       int p;
       switch(color) {
              case gdStyled:
              if (!im->style) {
                     /* Refuse to draw if no style is set. */
                     return;
              } else {
                     p = im->style[im->stylePos++];
              }
              if (p != (gdTransparent)) {
                     gdImageSetPixel(im, x, y, p);
              }
              im->stylePos = im->stylePos %  im->styleLength;
              break;
              case gdStyledBrushed:
              if (!im->style) {
                     /* Refuse to draw if no style is set. */
                     return;
              }
              p = im->style[im->stylePos++];
              if ((p != gdTransparent) && (p != 0)) {
                     gdImageSetPixel(im, x, y, gdBrushed);
              }
              im->stylePos = im->stylePos %  im->styleLength;
              break;
              case gdBrushed:
              gdImageBrushApply(im, x, y);
              break;
              case gdTiled:
              gdImageTileApply(im, x, y);
              break;
              default:
              if (gdImageBoundsSafe(im, x, y)) {
                      im->pixels[x][y] = color;
              }
              break;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void gdImageSetStyle ( gdImagePtr  im,
int *  style,
int  noOfPixels 
)

Definition at line 2472 of file gd.c.

{
       if (im->style) {
              free(im->style);
       }
       im->style = (int *) 
              malloc(sizeof(int) * noOfPixels);
       memcpy(im->style, style, sizeof(int) * noOfPixels);
       im->styleLength = noOfPixels;
       im->stylePos = 0;
}

Here is the caller graph for this function:

void gdImageSetTile ( gdImagePtr  im,
gdImagePtr  tile 
)

Definition at line 2510 of file gd.c.

{
       int i;
       im->tile = tile;
       for (i=0; (i < gdImageColorsTotal(tile)); i++) {
              int index;
              index = gdImageColorExact(im, 
                     gdImageRed(tile, i),
                     gdImageGreen(tile, i),
                     gdImageBlue(tile, i));
              if (index == (-1)) {
                     index = gdImageColorAllocate(im,
                            gdImageRed(tile, i),
                            gdImageGreen(tile, i),
                            gdImageBlue(tile, i));
                     if (index == (-1)) {
                            index = gdImageColorClosest(im,
                                   gdImageRed(tile, i),
                                   gdImageGreen(tile, i),
                                   gdImageBlue(tile, i));
                     }
              }
              im->tileColorMap[i] = index;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void gdImageString ( gdImagePtr  im,
gdFontPtr  f,
int  x,
int  y,
char *  s,
int  color 
)

Definition at line 467 of file gd.c.

{
       int i;
       int l;
       l = strlen(s);
       for (i=0; (i<l); i++) {
              gdImageChar(im, f, x, y, s[i], color);
              x += f->w;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void gdImageStringUp ( gdImagePtr  im,
gdFontPtr  f,
int  x,
int  y,
char *  s,
int  color 
)

Definition at line 478 of file gd.c.

{
       int i;
       int l;
       l = strlen(s);
       for (i=0; (i<l); i++) {
              gdImageCharUp(im, f, x, y, s[i], color);
              y -= f->w;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function: