mgd.h File Reference

Go to the source code of this file.

Data Structures

struct  gdImageStruct
struct  gdGifBufferStruct
struct  gdFont
struct  gdPoint

Defines

#define GD_H   1
#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 gdImageStruct gdImage
typedef gdImagegdImagePtr
typedef gdGifBufferStruct gdGifBuffer
typedef gdFontgdFontPtr
typedef struct gdPointgdPointPtr

Functions

gdImagePtr gdImageCreate (int sx, int sy)
gdImagePtr gdImageCreateFromGif (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, gdGifBuffer *buffer)
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)

Variables

gdFontPtr gdFontMediumBold
gdFontPtr gdFontGiant
gdFontPtr gdFontSmall


Define Documentation

#define GD_H   1

Definition at line 2 of file mgd.h.

#define gdBrushed   (-3)

Definition at line 85 of file mgd.h.

Referenced by gdImageSetPixel().

#define gdDashSize   4

Definition at line 80 of file mgd.h.

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

Definition at line 150 of file mgd.h.

Referenced by gdImageSetBrush().

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

Definition at line 147 of file mgd.h.

Referenced by gdImageSetBrush().

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

Definition at line 152 of file mgd.h.

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

Definition at line 151 of file mgd.h.

Referenced by gdImageBrushApply(), gdImageCopy(), gdImageCopyResized(), gdImageFill(), and gdImageTileApply().

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

Definition at line 149 of file mgd.h.

Referenced by gdImageSetBrush().

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

Definition at line 148 of file mgd.h.

Referenced by gdImageSetBrush().

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

Definition at line 145 of file mgd.h.

Referenced by gdImageBrushApply(), gdImageFill(), and gdImageTileApply().

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

Definition at line 146 of file mgd.h.

Referenced by gdImageBrushApply(), gdImageFill(), and gdImageTileApply().

#define gdMaxColors   256

Definition at line 19 of file mgd.h.

Referenced by gdImageColorAllocate(), gdImageCopy(), gdImageCopyResized(), and ReadImage().

#define gdStyled   (-2)

Definition at line 84 of file mgd.h.

Referenced by gdImageSetPixel().

#define gdStyledBrushed   (-4)

Definition at line 86 of file mgd.h.

Referenced by gdImageSetPixel().

#define gdTiled   (-5)

Definition at line 87 of file mgd.h.

Referenced by gdImageFill(), and gdImageSetPixel().

#define gdTransparent   (-6)

Definition at line 91 of file mgd.h.

Referenced by gdImageSetPixel().


Typedef Documentation

typedef gdFont* gdFontPtr

Definition at line 70 of file mgd.h.

typedef struct gdGifBufferStruct gdGifBuffer

typedef struct gdImageStruct gdImage

typedef gdImage* gdImagePtr

Definition at line 48 of file mgd.h.

typedef struct gdPoint * gdPointPtr


Function Documentation

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

Definition at line 826 of file mgd.c.

Referenced by gdImageGetPixel(), and gdImageSetPixel().

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

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

Definition at line 831 of file mgd.c.

Referenced by gdImageString().

00832 {
00833    int cx, cy;
00834    int px, py;
00835    int fline;
00836    cx = 0;
00837    cy = 0;
00838    if ((c < f->offset) || (c >= (f->offset + f->nchars))) {
00839       return;
00840    }
00841    fline = (c - f->offset) * f->h;
00842    for (py = y; (py < (y + f->h)); py++) {
00843       for (px = x; (px < (x + f->w)); px++) {
00844          if (f->data[fline + cy] & (1 << cx)) {
00845             gdImageSetPixel(im, px, py, color);
00846          }
00847          cx++;
00848       }
00849       cx = 0;
00850       cy++;
00851    }
00852 }

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

Definition at line 854 of file mgd.c.

Referenced by gdImageStringUp().

00855 {
00856    int cx, cy;
00857    int px, py;
00858    int fline;
00859    cx = 0;
00860    cy = 0;
00861    if ((c < f->offset) || (c >= (f->offset + f->nchars))) {
00862       return;
00863    }
00864    fline = (c - f->offset) * f->h;
00865    for (py = y; (py > (y - f->w)); py--) {
00866       for (px = x; (px < (x + f->h)); px++) {
00867          if (f->data[fline + cy] & (1 << cx)) {
00868             gdImageSetPixel(im, px, py, color);
00869          }
00870          cy++;
00871       }
00872       cy = 0;
00873       cx++;
00874    }
00875 }

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

Definition at line 492 of file mgd.c.

Referenced by gdImageCopy(), gdImageCopyResized(), gdImageSetBrush(), generate_hist_graph(), and show_custom_gif().

00493 {
00494    int i;
00495    int ct = (-1);
00496    
00497    /* check if color exists already */
00498    for (i = 0; (i < (im->colorsTotal)); i++) {
00499       if (!im->open[i] &&
00500           im->red[i] == r &&
00501           im->green[i] == g &&
00502           im->blue[i] == b) {
00503          return i;
00504       }
00505    }
00506    
00507    for (i = 0; (i < (im->colorsTotal)); i++) {
00508       if (im->open[i]) {
00509          ct = i;
00510          break;
00511       }
00512    }
00513    if (ct == (-1)) {
00514       ct = im->colorsTotal;
00515       if (ct == gdMaxColors) {
00516          return -1;
00517       }
00518       im->colorsTotal++;
00519    }
00520    im->red[ct] = r;
00521    im->green[ct] = g;
00522    im->blue[ct] = b;
00523    im->open[ct] = 0;
00524    return ct;
00525 }

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

Definition at line 455 of file mgd.c.

Referenced by gdImageCopy(), gdImageCopyResized(), gdImageSetBrush(), and show_custom_gif().

00456 {
00457    int i;
00458    long rd, gd, bd;
00459    int ct = (-1);
00460    long mindist = 0;
00461    for (i = 0; (i < (im->colorsTotal)); i++) {
00462       long dist;
00463       if (im->open[i]) {
00464          continue;
00465       }
00466       rd = (im->red[i] - r);
00467       gd = (im->green[i] - g);
00468       bd = (im->blue[i] - b);
00469       dist = rd * rd + gd * gd + bd * bd;
00470       if ((i == 0) || (dist < mindist)) {
00471          mindist = dist;
00472          ct = i;
00473       }
00474    }
00475    return ct;
00476 }

void gdImageColorDeallocate ( gdImagePtr  im,
int  color 
)

Definition at line 527 of file mgd.c.

00528 {
00529    /* Mark it open. */
00530    im->open[color] = 1;
00531 }

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

Definition at line 478 of file mgd.c.

Referenced by gdImageCopy(), gdImageCopyResized(), and gdImageSetBrush().

00479 {
00480    int i;
00481    for (i = 0; (i < (im->colorsTotal)); i++) {
00482       if (im->open[i]) {
00483          continue;
00484       }
00485       if ((im->red[i] == r) && (im->green[i] == g) && (im->blue[i] == b)) {
00486          return i;
00487       }
00488    }
00489    return -1;
00490 }

void gdImageColorTransparent ( gdImagePtr  im,
int  color 
)

Definition at line 533 of file mgd.c.

Referenced by generate_hist_graph().

00534 {
00535    im->transparent = color;
00536 }

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

Definition at line 2317 of file mgd.c.

02319 {
02320    int c;
02321    int x, y;
02322    int tox, toy;
02323    int i;
02324    int colorMap[gdMaxColors];
02325    for (i = 0; (i < gdMaxColors); i++) {
02326       colorMap[i] = (-1);
02327    }
02328    toy = dstY;
02329    for (y = srcY; (y < (srcY + h)); y++) {
02330       tox = dstX;
02331       for (x = srcX; (x < (srcX + w)); x++) {
02332          int nc;
02333          c = gdImageGetPixel(src, x, y);
02334          /* Added 7/24/95: support transparent copies */
02335          if (gdImageGetTransparent(src) == c) {
02336             tox++;
02337             continue;
02338          }
02339          /* Have we established a mapping for this color? */
02340          if (colorMap[c] == (-1)) {
02341             /* If it's the same image, mapping is trivial */
02342             if (dst == src) {
02343                nc = c;
02344             } else {
02345                /* First look for an exact match */
02346                nc = gdImageColorExact(dst, src->red[c], src->green[c], src->blue[c]);
02347             }
02348             if (nc == (-1)) {
02349                /* No, so try to allocate it */
02350                nc = gdImageColorAllocate(dst, src->red[c], src->green[c], src->blue[c]);
02351                /* If we're out of colors, go for the
02352                   closest color */
02353                if (nc == (-1)) {
02354                   nc = gdImageColorClosest(dst, src->red[c], src->green[c], src->blue[c]);
02355                }
02356             }
02357             colorMap[c] = nc;
02358          }
02359          gdImageSetPixel(dst, tox, toy, colorMap[c]);
02360          tox++;
02361       }
02362       toy++;
02363    }
02364 }

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 2366 of file mgd.c.

02368 {
02369    int c;
02370    int x, y;
02371    int tox, toy;
02372    int ydest;
02373    int i;
02374    int colorMap[gdMaxColors];
02375    /* Stretch vectors */
02376    int *stx;
02377    int *sty;
02378    /* We only need to use floating point to determine the correct
02379       stretch vector for one line's worth. */
02380    double accum;
02381    stx = (int *) M_MALLOC(sizeof(int) * srcW);
02382    sty = (int *) M_MALLOC(sizeof(int) * srcH);
02383    accum = 0;
02384    for (i = 0; (i < srcW); i++) {
02385       int got;
02386       accum += (double) dstW / (double) srcW;
02387       got = (int) floor(accum);
02388       stx[i] = got;
02389       accum -= got;
02390    }
02391    accum = 0;
02392    for (i = 0; (i < srcH); i++) {
02393       int got;
02394       accum += (double) dstH / (double) srcH;
02395       got = (int) floor(accum);
02396       sty[i] = got;
02397       accum -= got;
02398    }
02399    for (i = 0; (i < gdMaxColors); i++) {
02400       colorMap[i] = (-1);
02401    }
02402    toy = dstY;
02403    for (y = srcY; (y < (srcY + srcH)); y++) {
02404       for (ydest = 0; (ydest < sty[y - srcY]); ydest++) {
02405          tox = dstX;
02406          for (x = srcX; (x < (srcX + srcW)); x++) {
02407             int nc;
02408             if (!stx[x - srcX]) {
02409                continue;
02410             }
02411             c = gdImageGetPixel(src, x, y);
02412             /* Added 7/24/95: support transparent copies */
02413             if (gdImageGetTransparent(src) == c) {
02414                tox += stx[x - srcX];
02415                continue;
02416             }
02417             /* Have we established a mapping for this color? */
02418             if (colorMap[c] == (-1)) {
02419                /* If it's the same image, mapping is trivial */
02420                if (dst == src) {
02421                   nc = c;
02422                } else {
02423                   /* First look for an exact match */
02424                   nc = gdImageColorExact(dst, src->red[c], src->green[c], src->blue[c]);
02425                }
02426                if (nc == (-1)) {
02427                   /* No, so try to allocate it */
02428                   nc = gdImageColorAllocate(dst,
02429                                             src->red[c], src->green[c], src->blue[c]);
02430                   /* If we're out of colors, go for the
02431                      closest color */
02432                   if (nc == (-1)) {
02433                      nc = gdImageColorClosest(dst,
02434                                               src->red[c], src->green[c], src->blue[c]);
02435                   }
02436                }
02437                colorMap[c] = nc;
02438             }
02439             for (i = 0; (i < stx[x - srcX]); i++) {
02440                gdImageSetPixel(dst, tox, toy, colorMap[c]);
02441                tox++;
02442             }
02443          }
02444          toy++;
02445       }
02446    }
02447    M_FREE(stx);
02448    M_FREE(sty);
02449 }

gdImagePtr gdImageCreate ( int  sx,
int  sy 
)

Definition at line 417 of file mgd.c.

Referenced by generate_hist_graph().

00418 {
00419    int i;
00420    gdImagePtr im;
00421    im = (gdImage *) M_MALLOC(sizeof(gdImage));
00422    im->pixels = (unsigned char **) M_MALLOC(sizeof(unsigned char *) * sx);
00423    im->polyInts = 0;
00424    im->polyAllocated = 0;
00425    im->brush = 0;
00426    im->tile = 0;
00427    im->style = 0;
00428    for (i = 0; (i < sx); i++) {
00429       im->pixels[i] = (unsigned char *) M_CALLOC(sy, sizeof(unsigned char));
00430    }
00431    im->sx = sx;
00432    im->sy = sy;
00433    im->colorsTotal = 0;
00434    im->transparent = (-1);
00435    im->interlace = 0;
00436    return im;
00437 }

gdImagePtr gdImageCreateFromGif ( FILE *  fd  ) 

Definition at line 1888 of file mgd.c.

Referenced by show_custom_gif().

01889 {
01890    int imageNumber;
01891    int BitPixel;
01892    int ColorResolution;
01893    int Background;
01894    int AspectRatio;
01895    int Transparent = (-1);
01896    unsigned char buf[16];
01897    unsigned char c;
01898    unsigned char ColorMap[3][MAXCOLORMAPSIZE];
01899    unsigned char localColorMap[3][MAXCOLORMAPSIZE];
01900    int imw, imh;
01901    int useGlobalColormap;
01902    int bitPixel;
01903    int imageCount = 0;
01904    char version[4];
01905    gdImagePtr im = 0;
01906    ZeroDataBlock = FALSE;
01907 
01908    imageNumber = 1;
01909    if (!ReadOK(fd, buf, 6)) {
01910       return 0;
01911    }
01912    if (strncmp((char *) buf, "GIF", 3) != 0) {
01913       return 0;
01914    }
01915    strncpy(version, (char *) buf + 3, 3);
01916    version[3] = '\0';
01917 
01918    if ((strcmp(version, "87a") != 0) && (strcmp(version, "89a") != 0)) {
01919       return 0;
01920    }
01921    if (!ReadOK(fd, buf, 7)) {
01922       return 0;
01923    }
01924    BitPixel = 2 << (buf[4] & 0x07);
01925    ColorResolution = (int) (((buf[4] & 0x70) >> 3) + 1);
01926    Background = buf[5];
01927    AspectRatio = buf[6];
01928 
01929    if (BitSet(buf[4], LOCALCOLORMAP)) { /* Global Colormap */
01930       if (ReadColorMap(fd, BitPixel, ColorMap)) {
01931          return 0;
01932       }
01933    }
01934    for (;;) {
01935       if (!ReadOK(fd, &c, 1)) {
01936          return 0;
01937       }
01938       if (c == ';') {           /* GIF terminator */
01939          int i;
01940          if (imageCount < imageNumber) {
01941             return 0;
01942          }
01943          /* Terminator before any image was declared! */
01944          if (!im) {
01945             return 0;
01946          }
01947          /* Check for open colors at the end, so
01948             we can reduce colorsTotal and ultimately
01949             BitsPerPixel */
01950          for (i = ((im->colorsTotal - 1)); (i >= 0); i--) {
01951             if (im->open[i]) {
01952                im->colorsTotal--;
01953             } else {
01954                break;
01955             }
01956          }
01957          return im;
01958       }
01959 
01960       if (c == '!') {           /* Extension */
01961          if (!ReadOK(fd, &c, 1)) {
01962             return 0;
01963          }
01964          DoExtension(fd, c, &Transparent);
01965          continue;
01966       }
01967 
01968       if (c != ',') {           /* Not a valid start character */
01969          continue;
01970       }
01971 
01972       ++imageCount;
01973 
01974       if (!ReadOK(fd, buf, 9)) {
01975          return 0;
01976       }
01977 
01978       useGlobalColormap = !BitSet(buf[8], LOCALCOLORMAP);
01979 
01980       bitPixel = 1 << ((buf[8] & 0x07) + 1);
01981 
01982       imw = LM_to_uint(buf[4], buf[5]);
01983       imh = LM_to_uint(buf[6], buf[7]);
01984       if (!(im = gdImageCreate(imw, imh))) {
01985          return 0;
01986       }
01987       im->interlace = BitSet(buf[8], INTERLACE);
01988       if (!useGlobalColormap) {
01989          if (ReadColorMap(fd, bitPixel, localColorMap)) {
01990             return 0;
01991          }
01992          ReadImage(im, fd, imw, imh, localColorMap,
01993                    BitSet(buf[8], INTERLACE), imageCount != imageNumber);
01994       } else {
01995          ReadImage(im, fd, imw, imh,
01996                    ColorMap, BitSet(buf[8], INTERLACE), imageCount != imageNumber);
01997       }
01998       if (Transparent != (-1)) {
01999          gdImageColorTransparent(im, Transparent);
02000       }
02001    }
02002 }

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

Definition at line 738 of file mgd.c.

Referenced by generate_hist_graph().

00739 {
00740    int dx, dy, incr1, incr2, d, x, y, xend, yend, xdirflag, ydirflag;
00741    int dashStep = 0;
00742    int on = 1;
00743    dx = abs(x2 - x1);
00744    dy = abs(y2 - y1);
00745    if (dy <= dx) {
00746       d = 2 * dy - dx;
00747       incr1 = 2 * dy;
00748       incr2 = 2 * (dy - dx);
00749       if (x1 > x2) {
00750          x = x2;
00751          y = y2;
00752          ydirflag = (-1);
00753          xend = x1;
00754       } else {
00755          x = x1;
00756          y = y1;
00757          ydirflag = 1;
00758          xend = x2;
00759       }
00760       dashedSet;
00761       if (((y2 - y1) * ydirflag) > 0) {
00762          while (x < xend) {
00763             x++;
00764             if (d < 0) {
00765                d += incr1;
00766             } else {
00767                y++;
00768                d += incr2;
00769             }
00770             dashedSet;
00771          }
00772       } else {
00773          while (x < xend) {
00774             x++;
00775             if (d < 0) {
00776                d += incr1;
00777             } else {
00778                y--;
00779                d += incr2;
00780             }
00781             dashedSet;
00782          }
00783       }
00784    } else {
00785       d = 2 * dx - dy;
00786       incr1 = 2 * dx;
00787       incr2 = 2 * (dx - dy);
00788       if (y1 > y2) {
00789          y = y2;
00790          x = x2;
00791          yend = y1;
00792          xdirflag = (-1);
00793       } else {
00794          y = y1;
00795          x = x1;
00796          yend = y2;
00797          xdirflag = 1;
00798       }
00799       dashedSet;
00800       if (((x2 - x1) * xdirflag) > 0) {
00801          while (y < yend) {
00802             y++;
00803             if (d < 0) {
00804                d += incr1;
00805             } else {
00806                x++;
00807                d += incr2;
00808             }
00809             dashedSet;
00810          }
00811       } else {
00812          while (y < yend) {
00813             y++;
00814             if (d < 0) {
00815                d += incr1;
00816             } else {
00817                x--;
00818                d += incr2;
00819             }
00820             dashedSet;
00821          }
00822       }
00823    }
00824 }

void gdImageDestroy ( gdImagePtr  im  ) 

Definition at line 439 of file mgd.c.

Referenced by generate_hist_graph(), and show_custom_gif().

00440 {
00441    int i;
00442    for (i = 0; (i < im->sx); i++) {
00443       M_FREE(im->pixels[i]);
00444    }
00445    M_FREE(im->pixels);
00446    if (im->polyInts) {
00447       M_FREE(im->polyInts);
00448    }
00449    if (im->style) {
00450       M_FREE(im->style);
00451    }
00452    M_FREE(im);
00453 }

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

Definition at line 964 of file mgd.c.

Referenced by gdImageFill(), and show_custom_gif().

00965 {
00966    int lastBorder;
00967    int old;
00968    int leftLimit, rightLimit;
00969    int i;
00970    old = gdImageGetPixel(im, x, y);
00971    if (color == gdTiled) {
00972       /* Tile fill -- got to watch out! */
00973       int p, tileColor;
00974       int srcx, srcy;
00975       if (!im->tile) {
00976          return;
00977       }
00978       /* Refuse to flood-fill with a transparent pattern --
00979          I can't do it without allocating another image */
00980       if (gdImageGetTransparent(im->tile) != (-1)) {
00981          return;
00982       }
00983       srcx = x % gdImageSX(im->tile);
00984       srcy = y % gdImageSY(im->tile);
00985       p = gdImageGetPixel(im->tile, srcx, srcy);
00986       tileColor = im->tileColorMap[p];
00987       if (old == tileColor) {
00988          /* Nothing to be done */
00989          return;
00990       }
00991    } else {
00992       if (old == color) {
00993          /* Nothing to be done */
00994          return;
00995       }
00996    }
00997    /* Seek left */
00998    leftLimit = (-1);
00999    for (i = x; (i >= 0); i--) {
01000       if (gdImageGetPixel(im, i, y) != old) {
01001          break;
01002       }
01003       gdImageSetPixel(im, i, y, color);
01004       leftLimit = i;
01005    }
01006    if (leftLimit == (-1)) {
01007       return;
01008    }
01009    /* Seek right */
01010    rightLimit = x;
01011    for (i = (x + 1); (i < im->sx); i++) {
01012       if (gdImageGetPixel(im, i, y) != old) {
01013          break;
01014       }
01015       gdImageSetPixel(im, i, y, color);
01016       rightLimit = i;
01017    }
01018    /* Look at lines above and below and start paints */
01019    /* Above */
01020    if (y > 0) {
01021       lastBorder = 1;
01022       for (i = leftLimit; (i <= rightLimit); i++) {
01023          int c;
01024          c = gdImageGetPixel(im, i, y - 1);
01025          if (lastBorder) {
01026             if (c == old) {
01027                gdImageFill(im, i, y - 1, color);
01028                lastBorder = 0;
01029             }
01030          } else if (c != old) {
01031             lastBorder = 1;
01032          }
01033       }
01034    }
01035    /* Below */
01036    if (y < ((im->sy) - 1)) {
01037       lastBorder = 1;
01038       for (i = leftLimit; (i <= rightLimit); i++) {
01039          int c;
01040          c = gdImageGetPixel(im, i, y + 1);
01041          if (lastBorder) {
01042             if (c == old) {
01043                gdImageFill(im, i, y + 1, color);
01044                lastBorder = 0;
01045             }
01046          } else if (c != old) {
01047             lastBorder = 1;
01048          }
01049       }
01050    }
01051 }

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

Definition at line 2471 of file mgd.c.

Referenced by generate_hist_graph().

02472 {
02473    int i;
02474    int y;
02475    int y1, y2;
02476    int ints;
02477    if (!n) {
02478       return;
02479    }
02480    if (!im->polyAllocated) {
02481       im->polyInts = (int *) M_MALLOC(sizeof(int) * n);
02482       im->polyAllocated = n;
02483    }
02484    if (im->polyAllocated < n) {
02485       while (im->polyAllocated < n) {
02486          im->polyAllocated *= 2;
02487       }
02488       im->polyInts = (int *) realloc(im->polyInts, sizeof(int) * im->polyAllocated);
02489    }
02490    y1 = p[0].y;
02491    y2 = p[0].y;
02492    for (i = 1; (i < n); i++) {
02493       if (p[i].y < y1) {
02494          y1 = p[i].y;
02495       }
02496       if (p[i].y > y2) {
02497          y2 = p[i].y;
02498       }
02499    }
02500    for (y = y1; (y <= y2); y++) {
02501       int interLast = 0;
02502       int dirLast = 0;
02503       int interFirst = 1;
02504       ints = 0;
02505       for (i = 0; (i <= n); i++) {
02506          int x1, x2;
02507          int y1, y2;
02508          int dir;
02509          int ind1, ind2;
02510          int lastInd1 = 0;
02511          if ((i == n) || (!i)) {
02512             ind1 = n - 1;
02513             ind2 = 0;
02514          } else {
02515             ind1 = i - 1;
02516             ind2 = i;
02517          }
02518          y1 = p[ind1].y;
02519          y2 = p[ind2].y;
02520          if (y1 < y2) {
02521             y1 = p[ind1].y;
02522             y2 = p[ind2].y;
02523             x1 = p[ind1].x;
02524             x2 = p[ind2].x;
02525             dir = -1;
02526          } else if (y1 > y2) {
02527             y2 = p[ind1].y;
02528             y1 = p[ind2].y;
02529             x2 = p[ind1].x;
02530             x1 = p[ind2].x;
02531             dir = 1;
02532          } else {
02533             /* Horizontal; just draw it */
02534             gdImageLine(im, p[ind1].x, y1, p[ind2].x, y1, c);
02535             continue;
02536          }
02537          if ((y >= y1) && (y <= y2)) {
02538             int inter = (y - y1) * (x2 - x1) / (y2 - y1) + x1;
02539             /* Only count intersections once
02540                except at maxima and minima. Also, 
02541                if two consecutive intersections are
02542                endpoints of the same horizontal line
02543                that is not at a maxima or minima,   
02544                discard the leftmost of the two. */
02545             if (!interFirst) {
02546                if ((p[ind1].y == p[lastInd1].y) && (p[ind1].x != p[lastInd1].x)) {
02547                   if (dir == dirLast) {
02548                      if (inter > interLast) {
02549                         /* Replace the old one */
02550                         im->polyInts[ints] = inter;
02551                      } else {
02552                         /* Discard this one */
02553                      }
02554                      continue;
02555                   }
02556                }
02557                if (inter == interLast) {
02558                   if (dir == dirLast) {
02559                      continue;
02560                   }
02561                }
02562             }
02563             if (i > 0) {
02564                im->polyInts[ints++] = inter;
02565             }
02566             lastInd1 = i;
02567             dirLast = dir;
02568             interLast = inter;
02569             interFirst = 0;
02570          }
02571       }
02572       qsort(im->polyInts, ints, sizeof(int), gdCompareInt);
02573       for (i = 0; (i < (ints - 1)); i += 2) {
02574          gdImageLine(im, im->polyInts[i], y, im->polyInts[i + 1], y, c);
02575       }
02576    }
02577 }

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

Definition at line 2307 of file mgd.c.

Referenced by generate_hist_graph(), and show_custom_gif().

02308 {
02309    int x, y;
02310    for (y = y1; (y <= y2); y++) {
02311       for (x = x1; (x <= x2); x++) {
02312          gdImageSetPixel(im, x, y, color);
02313       }
02314    }
02315 }

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

Definition at line 899 of file mgd.c.

Referenced by gdImageFillToBorder().

00900 {
00901    int lastBorder;
00902    /* Seek left */
00903    int leftLimit, rightLimit;
00904    int i;
00905    leftLimit = (-1);
00906    if (border < 0) {
00907       /* Refuse to fill to a non-solid border */
00908       return;
00909    }
00910    for (i = x; (i >= 0); i--) {
00911       if (gdImageGetPixel(im, i, y) == border) {
00912          break;
00913       }
00914       gdImageSetPixel(im, i, y, color);
00915       leftLimit = i;
00916    }
00917    if (leftLimit == (-1)) {
00918       return;
00919    }
00920    /* Seek right */
00921    rightLimit = x;
00922    for (i = (x + 1); (i < im->sx); i++) {
00923       if (gdImageGetPixel(im, i, y) == border) {
00924          break;
00925       }
00926       gdImageSetPixel(im, i, y, color);
00927       rightLimit = i;
00928    }
00929    /* Look at lines above and below and start paints */
00930    /* Above */
00931    if (y > 0) {
00932       lastBorder = 1;
00933       for (i = leftLimit; (i <= rightLimit); i++) {
00934          int c;
00935          c = gdImageGetPixel(im, i, y - 1);
00936          if (lastBorder) {
00937             if ((c != border) && (c != color)) {
00938                gdImageFillToBorder(im, i, y - 1, border, color);
00939                lastBorder = 0;
00940             }
00941          } else if ((c == border) || (c == color)) {
00942             lastBorder = 1;
00943          }
00944       }
00945    }
00946    /* Below */
00947    if (y < ((im->sy) - 1)) {
00948       lastBorder = 1;
00949       for (i = leftLimit; (i <= rightLimit); i++) {
00950          int c;
00951          c = gdImageGetPixel(im, i, y + 1);
00952          if (lastBorder) {
00953             if ((c != border) && (c != color)) {
00954                gdImageFillToBorder(im, i, y + 1, border, color);
00955                lastBorder = 0;
00956             }
00957          } else if ((c == border) || (c == color)) {
00958             lastBorder = 1;
00959          }
00960       }
00961    }
00962 }

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

Definition at line 627 of file mgd.c.

Referenced by gdImageBrushApply(), gdImageCopy(), gdImageCopyResized(), gdImageFill(), gdImageFillToBorder(), gdImageTileApply(), and GIFNextPixel().

00628 {
00629    if (gdImageBoundsSafe(im, x, y)) {
00630       return im->pixels[x][y];
00631    } else {
00632       return 0;
00633    }
00634 }

void gdImageGif ( gdImagePtr  im,
gdGifBuffer buffer 
)

Definition at line 1118 of file mgd.c.

Referenced by generate_hist_graph(), and show_custom_gif().

01119 {
01120    int interlace, transparent, BitsPerPixel;
01121    interlace = im->interlace;
01122    transparent = im->transparent;
01123 
01124    /* allocate buffer */
01125    buffer->size = 0;
01126    buffer->data = gif_buffer;
01127 
01128    BitsPerPixel = colorstobpp(im->colorsTotal);
01129    /* Clear any old values in statics strewn through the GIF code */
01130    init_statics();
01131    /* All set, let's do it. */
01132    GIFEncode(buffer, im->sx, im->sy, interlace, 0, transparent, BitsPerPixel,
01133              im->red, im->green, im->blue, im);
01134 }

void gdImageInterlace ( gdImagePtr  im,
int  interlaceArg 
)

Definition at line 2619 of file mgd.c.

Referenced by generate_hist_graph(), and show_custom_gif().

02620 {
02621    im->interlace = interlaceArg;
02622 }

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

Definition at line 638 of file mgd.c.

Referenced by gdImageFilledPolygon(), gdImagePolygon(), gdImageRectangle(), generate_hist_graph(), haxis(), taxis(), and vaxis().

00639 {
00640    int dx, dy, incr1, incr2, d, x, y, xend, yend, xdirflag, ydirflag;
00641    dx = abs(x2 - x1);
00642    dy = abs(y2 - y1);
00643    if (dy <= dx) {
00644       d = 2 * dy - dx;
00645       incr1 = 2 * dy;
00646       incr2 = 2 * (dy - dx);
00647       if (x1 > x2) {
00648          x = x2;
00649          y = y2;
00650          ydirflag = (-1);
00651          xend = x1;
00652       } else {
00653          x = x1;
00654          y = y1;
00655          ydirflag = 1;
00656          xend = x2;
00657       }
00658       gdImageSetPixel(im, x, y, color);
00659       if (((y2 - y1) * ydirflag) > 0) {
00660          while (x < xend) {
00661             x++;
00662             if (d < 0) {
00663                d += incr1;
00664             } else {
00665                y++;
00666                d += incr2;
00667             }
00668             gdImageSetPixel(im, x, y, color);
00669          }
00670       } else {
00671          while (x < xend) {
00672             x++;
00673             if (d < 0) {
00674                d += incr1;
00675             } else {
00676                y--;
00677                d += incr2;
00678             }
00679             gdImageSetPixel(im, x, y, color);
00680          }
00681       }
00682    } else {
00683       d = 2 * dx - dy;
00684       incr1 = 2 * dx;
00685       incr2 = 2 * (dx - dy);
00686       if (y1 > y2) {
00687          y = y2;
00688          x = x2;
00689          yend = y1;
00690          xdirflag = (-1);
00691       } else {
00692          y = y1;
00693          x = x1;
00694          yend = y2;
00695          xdirflag = 1;
00696       }
00697       gdImageSetPixel(im, x, y, color);
00698       if (((x2 - x1) * xdirflag) > 0) {
00699          while (y < yend) {
00700             y++;
00701             if (d < 0) {
00702                d += incr1;
00703             } else {
00704                x++;
00705                d += incr2;
00706             }
00707             gdImageSetPixel(im, x, y, color);
00708          }
00709       } else {
00710          while (y < yend) {
00711             y++;
00712             if (d < 0) {
00713                d += incr1;
00714             } else {
00715                x--;
00716                d += incr2;
00717             }
00718             gdImageSetPixel(im, x, y, color);
00719          }
00720       }
00721    }
00722 }

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

Definition at line 2451 of file mgd.c.

02452 {
02453    int i;
02454    int lx, ly;
02455    if (!n) {
02456       return;
02457    }
02458    lx = p->x;
02459    ly = p->y;
02460    gdImageLine(im, lx, ly, p[n - 1].x, p[n - 1].y, c);
02461    for (i = 1; (i < n); i++) {
02462       p++;
02463       gdImageLine(im, lx, ly, p->x, p->y, c);
02464       lx = p->x;
02465       ly = p->y;
02466    }
02467 }

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

Definition at line 2299 of file mgd.c.

Referenced by generate_hist_graph(), and show_custom_gif().

02300 {
02301    gdImageLine(im, x1, y1, x2, y1, color);
02302    gdImageLine(im, x1, y2, x2, y2, color);
02303    gdImageLine(im, x1, y1, x1, y2, color);
02304    gdImageLine(im, x2, y1, x2, y2, color);
02305 }

void gdImageSetBrush ( gdImagePtr  im,
gdImagePtr  brush 
)

Definition at line 2596 of file mgd.c.

02597 {
02598    int i;
02599    im->brush = brush;
02600    for (i = 0; (i < gdImageColorsTotal(brush)); i++) {
02601       int index;
02602       index = gdImageColorExact(im,
02603                                 gdImageRed(brush, i),
02604                                 gdImageGreen(brush, i), gdImageBlue(brush, i));
02605       if (index == (-1)) {
02606          index = gdImageColorAllocate(im,
02607                                       gdImageRed(brush, i),
02608                                       gdImageGreen(brush, i), gdImageBlue(brush, i));
02609          if (index == (-1)) {
02610             index = gdImageColorClosest(im,
02611                                         gdImageRed(brush, i),
02612                                         gdImageGreen(brush, i), gdImageBlue(brush, i));
02613          }
02614       }
02615       im->brushColorMap[i] = index;
02616    }
02617 }

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

Definition at line 538 of file mgd.c.

Referenced by gdImageBrushApply(), gdImageChar(), gdImageCharUp(), gdImageCopy(), gdImageCopyResized(), gdImageFill(), gdImageFilledRectangle(), gdImageFillToBorder(), gdImageLine(), gdImageSetPixel(), gdImageTileApply(), and ReadImage().

00539 {
00540    int p;
00541    switch (color) {
00542    case gdStyled:
00543       if (!im->style) {
00544          /* Refuse to draw if no style is set. */
00545          return;
00546       } else {
00547          p = im->style[im->stylePos++];
00548       }
00549       if (p != (gdTransparent)) {
00550          gdImageSetPixel(im, x, y, p);
00551       }
00552       im->stylePos = im->stylePos % im->styleLength;
00553       break;
00554    case gdStyledBrushed:
00555       if (!im->style) {
00556          /* Refuse to draw if no style is set. */
00557          return;
00558       }
00559       p = im->style[im->stylePos++];
00560       if ((p != gdTransparent) && (p != 0)) {
00561          gdImageSetPixel(im, x, y, gdBrushed);
00562       }
00563       im->stylePos = im->stylePos % im->styleLength;
00564       break;
00565    case gdBrushed:
00566       gdImageBrushApply(im, x, y);
00567       break;
00568    case gdTiled:
00569       gdImageTileApply(im, x, y);
00570       break;
00571    default:
00572       if (gdImageBoundsSafe(im, x, y)) {
00573          im->pixels[x][y] = color;
00574       }
00575       break;
00576    }
00577 }

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

Definition at line 2584 of file mgd.c.

02585 {
02586    if (im->style) {
02587       M_FREE(im->style);
02588    }
02589    im->style = (int *)
02590        M_MALLOC(sizeof(int) * noOfPixels);
02591    memcpy(im->style, style, sizeof(int) * noOfPixels);
02592    im->styleLength = noOfPixels;
02593    im->stylePos = 0;
02594 }

void gdImageSetTile ( gdImagePtr  im,
gdImagePtr  tile 
)

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

Definition at line 877 of file mgd.c.

Referenced by generate_hist_graph(), haxis(), show_custom_gif(), taxis(), and vaxis().

00878 {
00879    int i;
00880    int l;
00881    l = strlen(s);
00882    for (i = 0; (i < l); i++) {
00883       gdImageChar(im, f, x, y, s[i], color);
00884       x += f->w;
00885    }
00886 }

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

Definition at line 888 of file mgd.c.

Referenced by generate_hist_graph().

00889 {
00890    int i;
00891    int l;
00892    l = strlen(s);
00893    for (i = 0; (i < l); i++) {
00894       gdImageCharUp(im, f, x, y, s[i], color);
00895       y -= f->w;
00896    }
00897 }


Variable Documentation

gdFontPtr gdFontGiant

Definition at line 409 of file mgd.c.

Referenced by generate_hist_graph(), and show_custom_gif().

gdFontPtr gdFontMediumBold

Definition at line 408 of file mgd.c.

Referenced by generate_hist_graph(), and show_custom_gif().

gdFontPtr gdFontSmall

Definition at line 410 of file mgd.c.

Referenced by generate_hist_graph(), and show_custom_gif().


Midas DOC Version 3.0.0 ---- PSI Stefan Ritt ----
Contributions: Pierre-Andre Amaudruz - Sergio Ballestrero - Suzannah Daviel - Doxygen - Peter Green - Qing Gu - Greg Hackman - Gertjan Hofman - Paul Knowles - Exaos Lee - Rudi Meier - Glenn Moloney - Dave Morris - John M O'Donnell - Konstantin Olchanski - Renee Poutissou - Tamsen Schurman - Andreas Suter - Jan M.Wouters - Piotr Adam Zolnierczuk