gd.h File Reference

#include <stdio.h>

Go to the source code of this file.

Data Structures

struct  gdImageStruct
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 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, int c, int color)
void gdImageString (gdImagePtr im, gdFontPtr f, int x, int y, unsigned char *s, int color)
void gdImageStringUp (gdImagePtr im, gdFontPtr f, int x, int y, unsigned char *s, int color)
void gdImageString16 (gdImagePtr im, gdFontPtr f, int x, int y, unsigned short *s, int color)
void gdImageStringUp16 (gdImagePtr im, gdFontPtr f, int x, int y, unsigned short *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)


Define Documentation

#define GD_H   1

Definition at line 2 of file gd.h.

#define gdBrushed   (-3)

Definition at line 75 of file gd.h.

Referenced by gdImageSetPixel().

#define gdDashSize   4

Definition at line 70 of file gd.h.

Referenced by dashedSet().

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

Definition at line 144 of file gd.h.

Referenced by gdImageSetBrush(), gdImageSetTile(), and main().

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

Definition at line 141 of file gd.h.

Referenced by gdImageSetBrush(), gdImageSetTile(), and main().

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

Definition at line 146 of file gd.h.

Referenced by main().

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

Definition at line 145 of file gd.h.

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

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

Definition at line 143 of file gd.h.

Referenced by gdImageSetBrush(), gdImageSetTile(), and main().

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

Definition at line 142 of file gd.h.

Referenced by gdImageSetBrush(), gdImageSetTile(), and main().

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

Definition at line 139 of file gd.h.

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

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

Definition at line 140 of file gd.h.

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

#define gdMaxColors   256

Definition at line 19 of file gd.h.

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

#define gdStyled   (-2)

Definition at line 74 of file gd.h.

Referenced by gdImageSetPixel().

#define gdStyledBrushed   (-4)

Definition at line 76 of file gd.h.

Referenced by gdImageSetPixel(), and main().

#define gdTiled   (-5)

Definition at line 77 of file gd.h.

Referenced by gdImageFill(), and gdImageSetPixel().

#define gdTransparent   (-6)

Definition at line 81 of file gd.h.

Referenced by gdImageSetPixel().


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 549 of file gd.cpp.

References cost, costScale, gdImageLine(), sint, and sintScale.

Referenced by main(), and pie_gif().

00550 {
00551         int i;
00552         int lx = 0, ly = 0;
00553         int w2, h2;
00554         w2 = w/2;
00555         h2 = h/2;
00556         while (e < s) {
00557                 e += 360;
00558         }
00559         for (i=s; (i <= e); i++) {
00560                 int x, y;
00561                 x = ((long)cost[i % 360] * (long)w2 / costScale) + cx; 
00562                 y = ((long)sint[i % 360] * (long)h2 / sintScale) + cy;
00563                 if (i != s) {
00564                         gdImageLine(im, lx, ly, x, y, color);   
00565                 }
00566                 lx = x;
00567                 ly = y;
00568         }
00569 }

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

Definition at line 425 of file gd.cpp.

References gdImageStruct::sx, and gdImageStruct::sy.

Referenced by gdImageGetPixel(), and gdImageSetPixel().

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

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

Definition at line 431 of file gd.cpp.

References gdFont::data, gdImageSetPixel(), gdFont::h, gdFont::nchars, gdFont::offset, and gdFont::w.

Referenced by gdImageString(), and gdImageString16().

00433 {
00434         int cx, cy;
00435         int px, py;
00436         int fline;
00437         cx = 0;
00438         cy = 0;
00439         if ((c < f->offset) || (c >= (f->offset + f->nchars))) {
00440                 return;
00441         }
00442         fline = (c - f->offset) * f->h * f->w;
00443         for (py = y; (py < (y + f->h)); py++) {
00444                 for (px = x; (px < (x + f->w)); px++) {
00445                         if (f->data[fline + cy * f->w + cx]) {
00446                                 gdImageSetPixel(im, px, py, color);     
00447                         }
00448                         cx++;
00449                 }
00450                 cx = 0;
00451                 cy++;
00452         }
00453 }

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

Definition at line 455 of file gd.cpp.

References gdFont::data, gdImageSetPixel(), gdFont::h, gdFont::nchars, gdFont::offset, and gdFont::w.

Referenced by gdImageStringUp(), and gdImageStringUp16().

00457 {
00458         int cx, cy;
00459         int px, py;
00460         int fline;
00461         cx = 0;
00462         cy = 0;
00463         if ((c < f->offset) || (c >= (f->offset + f->nchars))) {
00464                 return;
00465         }
00466         fline = (c - f->offset) * f->h * f->w;
00467         for (py = y; (py > (y - f->w)); py--) {
00468                 for (px = x; (px < (x + f->h)); px++) {
00469                         if (f->data[fline + cy * f->w + cx]) {
00470                                 gdImageSetPixel(im, px, py, color);     
00471                         }
00472                         cy++;
00473                 }
00474                 cy = 0;
00475                 cx++;
00476         }
00477 }

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

Definition at line 91 of file gd.cpp.

References gdImageStruct::blue, gdImageStruct::colorsTotal, gdMaxColors, gdImageStruct::green, gdImageStruct::open, and gdImageStruct::red.

Referenced by gdImageCopy(), gdImageCopyResized(), gdImageCreateFromXbm(), gdImageSetBrush(), gdImageSetTile(), main(), out_err(), and out_graph().

00092 {
00093         int i;
00094         int ct = (-1);
00095         for (i=0; (i<(im->colorsTotal)); i++) {
00096                 if (im->open[i]) {
00097                         ct = i;
00098                         break;
00099                 }
00100         }       
00101         if (ct == (-1)) {
00102                 ct = im->colorsTotal;
00103                 if (ct == gdMaxColors) {
00104                         return -1;
00105                 }
00106                 im->colorsTotal++;
00107         }
00108         im->red[ct] = r;
00109         im->green[ct] = g;
00110         im->blue[ct] = b;
00111         im->open[ct] = 0;
00112         return ct;
00113 }

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

Definition at line 52 of file gd.cpp.

References gdImageStruct::blue, gdImageStruct::colorsTotal, gdImageStruct::green, gdImageStruct::open, and gdImageStruct::red.

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

00053 {
00054         int i;
00055         long rd, gd, bd;
00056         int ct = (-1);
00057         long mindist = 0;
00058         for (i=0; (i<(im->colorsTotal)); i++) {
00059                 long dist;
00060                 if (im->open[i]) {
00061                         continue;
00062                 }
00063                 rd = (im->red[i] - r);  
00064                 gd = (im->green[i] - g);
00065                 bd = (im->blue[i] - b);
00066                 dist = rd * rd + gd * gd + bd * bd;
00067                 if ((i == 0) || (dist < mindist)) {
00068                         mindist = dist; 
00069                         ct = i;
00070                 }
00071         }
00072         return ct;
00073 }

void gdImageColorDeallocate ( gdImagePtr  im,
int  color 
)

Definition at line 115 of file gd.cpp.

References gdImageStruct::open.

00116 {
00117         /* Mark it open. */
00118         im->open[color] = 1;
00119 }

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

Definition at line 75 of file gd.cpp.

References gdImageStruct::blue, gdImageStruct::colorsTotal, gdImageStruct::green, gdImageStruct::open, and gdImageStruct::red.

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

00076 {
00077         int i;
00078         for (i=0; (i<(im->colorsTotal)); i++) {
00079                 if (im->open[i]) {
00080                         continue;
00081                 }
00082                 if ((im->red[i] == r) && 
00083                         (im->green[i] == g) &&
00084                         (im->blue[i] == b)) {
00085                         return i;
00086                 }
00087         }
00088         return -1;
00089 }

void gdImageColorTransparent ( gdImagePtr  im,
int  color 
)

Definition at line 121 of file gd.cpp.

References gdImageStruct::transparent.

Referenced by main().

00122 {
00123         im->transparent = color;
00124 }

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

Definition at line 2063 of file gd.cpp.

References gdImageStruct::blue, gdImageColorAllocate(), gdImageColorClosest(), gdImageColorExact(), gdImageGetPixel(), gdImageGetTransparent, gdImageSetPixel(), gdMaxColors, gdImageStruct::green, and gdImageStruct::red.

Referenced by out_graph().

02064 {
02065         int c;
02066         int x, y;
02067         int tox, toy;
02068         int i;
02069         int colorMap[gdMaxColors];
02070         for (i=0; (i<gdMaxColors); i++) {
02071                 colorMap[i] = (-1);
02072         }
02073         toy = dstY;
02074         for (y=srcY; (y < (srcY + h)); y++) {
02075                 tox = dstX;
02076                 for (x=srcX; (x < (srcX + w)); x++) {
02077                         int nc;
02078                         c = gdImageGetPixel(src, x, y);
02079                         /* Added 7/24/95: support transparent copies */
02080                         if (gdImageGetTransparent(src) == c) {
02081                                 tox++;
02082                                 continue;
02083                         }
02084                         /* Have we established a mapping for this color? */
02085                         if (colorMap[c] == (-1)) {
02086                                 /* If it's the same image, mapping is trivial */
02087                                 if (dst == src) {
02088                                         nc = c;
02089                                 } else { 
02090                                         /* First look for an exact match */
02091                                         nc = gdImageColorExact(dst,
02092                                                 src->red[c], src->green[c],
02093                                                 src->blue[c]);
02094                                 }       
02095                                 if (nc == (-1)) {
02096                                         /* No, so try to allocate it */
02097                                         nc = gdImageColorAllocate(dst,
02098                                                 src->red[c], src->green[c],
02099                                                 src->blue[c]);
02100                                         /* If we're out of colors, go for the
02101                                                 closest color */
02102                                         if (nc == (-1)) {
02103                                                 nc = gdImageColorClosest(dst,
02104                                                         src->red[c], src->green[c],
02105                                                         src->blue[c]);
02106                                         }
02107                                 }
02108                                 colorMap[c] = nc;
02109                         }
02110                         gdImageSetPixel(dst, tox, toy, colorMap[c]);
02111                         tox++;
02112                 }
02113                 toy++;
02114         }
02115 }                       

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 2117 of file gd.cpp.

References gdImageStruct::blue, gdImageColorAllocate(), gdImageColorClosest(), gdImageColorExact(), gdImageGetPixel(), gdImageGetTransparent, gdImageSetPixel(), gdMaxColors, gdImageStruct::green, and gdImageStruct::red.

Referenced by main(), and out_graph().

02118 {
02119         int c;
02120         int x, y;
02121         int tox, toy;
02122         int ydest;
02123         int i;
02124         int colorMap[gdMaxColors];
02125         /* Stretch vectors */
02126         int *stx;
02127         int *sty;
02128         /* We only need to use floating point to determine the correct
02129                 stretch vector for one line's worth. */
02130         double accum;
02131         stx = (int *) malloc(sizeof(int) * srcW);
02132         sty = (int *) malloc(sizeof(int) * srcH);
02133         accum = 0;
02134         for (i=0; (i < srcW); i++) {
02135                 int got;
02136                 accum += (double)dstW/(double)srcW;
02137                 got = floor(accum);
02138                 stx[i] = got;
02139                 accum -= got;
02140         }
02141         accum = 0;
02142         for (i=0; (i < srcH); i++) {
02143                 int got;
02144                 accum += (double)dstH/(double)srcH;
02145                 got = floor(accum);
02146                 sty[i] = got;
02147                 accum -= got;
02148         }
02149         for (i=0; (i<gdMaxColors); i++) {
02150                 colorMap[i] = (-1);
02151         }
02152         toy = dstY;
02153         for (y=srcY; (y < (srcY + srcH)); y++) {
02154                 for (ydest=0; (ydest < sty[y-srcY]); ydest++) {
02155                         tox = dstX;
02156                         for (x=srcX; (x < (srcX + srcW)); x++) {
02157                                 int nc;
02158                                 if (!stx[x - srcX]) {
02159                                         continue;
02160                                 }
02161                                 c = gdImageGetPixel(src, x, y);
02162                                 /* Added 7/24/95: support transparent copies */
02163                                 if (gdImageGetTransparent(src) == c) {
02164                                         tox += stx[x-srcX];
02165                                         continue;
02166                                 }
02167                                 /* Have we established a mapping for this color? */
02168                                 if (colorMap[c] == (-1)) {
02169                                         /* If it's the same image, mapping is trivial */
02170                                         if (dst == src) {
02171                                                 nc = c;
02172                                         } else { 
02173                                                 /* First look for an exact match */
02174                                                 nc = gdImageColorExact(dst,
02175                                                         src->red[c], src->green[c],
02176                                                         src->blue[c]);
02177                                         }       
02178                                         if (nc == (-1)) {
02179                                                 /* No, so try to allocate it */
02180                                                 nc = gdImageColorAllocate(dst,
02181                                                         src->red[c], src->green[c],
02182                                                         src->blue[c]);
02183                                                 /* If we're out of colors, go for the
02184                                                         closest color */
02185                                                 if (nc == (-1)) {
02186                                                         nc = gdImageColorClosest(dst,
02187                                                                 src->red[c], src->green[c],
02188                                                                 src->blue[c]);
02189                                                 }
02190                                         }
02191                                         colorMap[c] = nc;
02192                                 }
02193                                 for (i=0; (i < stx[x - srcX]); i++) {
02194                                         gdImageSetPixel(dst, tox, toy, colorMap[c]);
02195                                         tox++;
02196                                 }
02197                         }
02198                         toy++;
02199                 }
02200         }
02201         free(stx);
02202         free(sty);
02203 }

gdImagePtr gdImageCreate ( int  sx,
int  sy 
)

Definition at line 11 of file gd.cpp.

References gdImageStruct::brush, gdImageStruct::colorsTotal, gdImageStruct::interlace, gdImageStruct::pixels, gdImageStruct::polyAllocated, gdImageStruct::polyInts, gdImageStruct::style, gdImageStruct::sx, gdImageStruct::sy, gdImageStruct::tile, and gdImageStruct::transparent.

Referenced by gdImageCreateFromGd(), gdImageCreateFromXbm(), main(), out_err(), out_graph(), and pie_gif().

00012 {
00013         int i;
00014         gdImagePtr im;
00015         im = (gdImage *) malloc(sizeof(gdImage));
00016         /* NOW ROW-MAJOR IN GD 1.3 */
00017         im->pixels = (unsigned char **) malloc(sizeof(unsigned char *) * sy);
00018         im->polyInts = 0;
00019         im->polyAllocated = 0;
00020         im->brush = 0;
00021         im->tile = 0;
00022         im->style = 0;
00023         for (i=0; (i<sy); i++) {
00024                 /* NOW ROW-MAJOR IN GD 1.3 */
00025                 im->pixels[i] = (unsigned char *) calloc(
00026                         sx, sizeof(unsigned char));
00027         }       
00028         im->sx = sx;
00029         im->sy = sy;
00030         im->colorsTotal = 0;
00031         im->transparent = (-1);
00032         im->interlace = 0;
00033         return im;
00034 }

gdImagePtr gdImageCreateFromGd ( FILE *  in  ) 

Definition at line 2238 of file gd.cpp.

References gdImageStruct::colorsTotal, gdGetByte(), gdGetWord(), gdImageCreate(), gdMaxColors, gdImageStruct::green, gdImageStruct::red, and gdImageStruct::transparent.

02239 {
02240         int sx, sy;
02241         int x, y;
02242         int i;
02243         gdImagePtr im;
02244         if (!gdGetWord(&sx, in)) {
02245                 goto fail1;
02246         }
02247         if (!gdGetWord(&sy, in)) {
02248                 goto fail1;
02249         }
02250         im = gdImageCreate(sx, sy);
02251         if (!gdGetByte(&im->colorsTotal, in)) {
02252                 goto fail2;
02253         }
02254         if (!gdGetWord(&im->transparent, in)) {
02255                 goto fail2;
02256         }
02257         if (im->transparent == 257) {
02258                 im->transparent = (-1);
02259         }
02260         for (i=0; (i<gdMaxColors); i++) {
02261                 if (!gdGetByte(&im->red[i], in)) {
02262                         goto fail2;
02263                 }
02264                 if (!gdGetByte(&im->green[i], in)) {
02265                         goto fail2;
02266                 }
02267                 if (!gdGetByte(&im->blue[i], in)) {
02268                         goto fail2;
02269                 }
02270         }       
02271         for (y=0; (y<sy); y++) {
02272                 for (x=0; (x<sx); x++) {        
02273                         int ch;
02274                         ch = getc(in);
02275                         if (ch == EOF) {
02276                                 gdImageDestroy(im);
02277                                 return 0;
02278                         }
02279                         /* ROW-MAJOR IN GD 1.3 */
02280                         im->pixels[y][x] = ch;
02281                 }
02282         }
02283         return im;
02284 fail2:
02285         gdImageDestroy(im);
02286 fail1:
02287         return 0;
02288 }

gdImagePtr gdImageCreateFromGif ( FILE *  fd  ) 

Definition at line 1589 of file gd.cpp.

References BitSet, gdImageStruct::colorsTotal, FALSE, LOCALCOLORMAP, MAXCOLORMAPSIZE, gdImageStruct::open, ReadColorMap(), and ReadOK.

Referenced by main(), and out_graph().

01590 {
01591        int imageNumber;
01592        int BitPixel;
01593        int ColorResolution;
01594        int Background;
01595        int AspectRatio;
01596        int Transparent = (-1);
01597        unsigned char   buf[16];
01598        unsigned char   c;
01599        unsigned char   ColorMap[3][MAXCOLORMAPSIZE];
01600        unsigned char   localColorMap[3][MAXCOLORMAPSIZE];
01601        int             imw, imh;
01602        int             useGlobalColormap;
01603        int             bitPixel;
01604        int             imageCount = 0;
01605        char            version[4];
01606        gdImagePtr im = 0;
01607        ZeroDataBlock = FALSE;
01608 
01609        imageNumber = 1;
01610        if (! ReadOK(fd,buf,6)) {
01611                 return 0;
01612         }
01613        if (strncmp((char *)buf,"GIF",3) != 0) {
01614                 return 0;
01615         }
01616        strncpy(version, (char *)buf + 3, 3);
01617        version[3] = '\0';
01618 
01619        if ((strcmp(version, "87a") != 0) && (strcmp(version, "89a") != 0)) {
01620                 return 0;
01621         }
01622        if (! ReadOK(fd,buf,7)) {
01623                 return 0;
01624         }
01625        BitPixel        = 2<<(buf[4]&0x07);
01626        ColorResolution = (int) (((buf[4]&0x70)>>3)+1);
01627        Background      = buf[5];
01628        AspectRatio     = buf[6];
01629 
01630        if (BitSet(buf[4], LOCALCOLORMAP)) {    /* Global Colormap */
01631                if (ReadColorMap(fd, BitPixel, ColorMap)) {
01632                         return 0;
01633                 }
01634        }
01635        for (;;) {
01636                if (! ReadOK(fd,&c,1)) {
01637                        return 0;
01638                }
01639                if (c == ';') {         /* GIF terminator */
01640                        int i;
01641                        if (imageCount < imageNumber) {
01642                                return 0;
01643                        }
01644                        /* Terminator before any image was declared! */
01645                        if (!im) {
01646                               return 0;
01647                        }
01648                        /* Check for open colors at the end, so
01649                           we can reduce colorsTotal and ultimately
01650                           BitsPerPixel */
01651                        for (i=((im->colorsTotal-1)); (i>=0); i--) {
01652                                if (im->open[i]) {
01653                                        im->colorsTotal--;
01654                                } else {
01655                                        break;
01656                                }
01657                        } 
01658                        return im;
01659                }
01660 
01661                if (c == '!') {         /* Extension */
01662                        if (! ReadOK(fd,&c,1)) {
01663                                return 0;
01664                        }
01665                        DoExtension(fd, c, &Transparent);
01666                        continue;
01667                }
01668 
01669                if (c != ',') {         /* Not a valid start character */
01670                        continue;
01671                }
01672 
01673                ++imageCount;
01674 
01675                if (! ReadOK(fd,buf,9)) {
01676                        return 0;
01677                }
01678 
01679                useGlobalColormap = ! BitSet(buf[8], LOCALCOLORMAP);
01680 
01681                bitPixel = 1<<((buf[8]&0x07)+1);
01682 
01683                imw = LM_to_uint(buf[4],buf[5]);
01684                imh = LM_to_uint(buf[6],buf[7]);
01685                if (!(im = gdImageCreate(imw, imh))) {
01686                          return 0;
01687                }
01688                im->interlace = BitSet(buf[8], INTERLACE);
01689                if (! useGlobalColormap) {
01690                        if (ReadColorMap(fd, bitPixel, localColorMap)) { 
01691                                  return 0;
01692                        }
01693                        ReadImage(im, fd, imw, imh, localColorMap, 
01694                                  BitSet(buf[8], INTERLACE), 
01695                                  imageCount != imageNumber);
01696                } else {
01697                        ReadImage(im, fd, imw, imh,
01698                                  ColorMap, 
01699                                  BitSet(buf[8], INTERLACE), 
01700                                  imageCount != imageNumber);
01701                }
01702                if (Transparent != (-1)) {
01703                        gdImageColorTransparent(im, Transparent);
01704                }           
01705        }
01706 }

gdImagePtr gdImageCreateFromXbm ( FILE *  fd  ) 

Definition at line 2317 of file gd.cpp.

References gdImageColorAllocate(), gdImageCreate(), gdImageDestroy(), gdImageSetPixel(), gdImageStruct::sx, and gdImageStruct::sy.

02318 {
02319         gdImagePtr im;  
02320         int bit;
02321         int w, h;
02322         int bytes;
02323         int ch;
02324         int i, x, y;
02325         char *sp;
02326         char s[161];
02327         if (!fgets(s, 160, fd)) {
02328                 return 0;
02329         }
02330         sp = &s[0];
02331         /* Skip #define */
02332         sp = strchr(sp, ' ');
02333         if (!sp) {
02334                 return 0;
02335         }
02336         /* Skip width label */
02337         sp++;
02338         sp = strchr(sp, ' ');
02339         if (!sp) {
02340                 return 0;
02341         }
02342         /* Get width */
02343         w = atoi(sp + 1);
02344         if (!w) {
02345                 return 0;
02346         }
02347         if (!fgets(s, 160, fd)) {
02348                 return 0;
02349         }
02350         sp = s;
02351         /* Skip #define */
02352         sp = strchr(sp, ' ');
02353         if (!sp) {
02354                 return 0;
02355         }
02356         /* Skip height label */
02357         sp++;
02358         sp = strchr(sp, ' ');
02359         if (!sp) {
02360                 return 0;
02361         }
02362         /* Get height */
02363         h = atoi(sp + 1);
02364         if (!h) {
02365                 return 0;
02366         }
02367         /* Skip declaration line */
02368         if (!fgets(s, 160, fd)) {
02369                 return 0;
02370         }
02371         bytes = (w * h / 8) + 1;
02372         im = gdImageCreate(w, h);
02373         gdImageColorAllocate(im, 255, 255, 255);
02374         gdImageColorAllocate(im, 0, 0, 0);
02375         x = 0;
02376         y = 0;
02377         for (i=0; (i < bytes); i++) {
02378                 char h[3];
02379                 int b;
02380                 /* Skip spaces, commas, CRs, 0x */
02381                 while(1) {
02382                         ch = getc(fd);
02383                         if (ch == EOF) {
02384                                 goto fail;
02385                         }
02386                         if (ch == 'x') {
02387                                 break;
02388                         }       
02389                 }
02390                 /* Get hex value */
02391                 ch = getc(fd);
02392                 if (ch == EOF) {
02393                         goto fail;
02394                 }
02395                 h[0] = ch;
02396                 ch = getc(fd);
02397                 if (ch == EOF) {
02398                         goto fail;
02399                 }
02400                 h[1] = ch;
02401                 h[2] = '\0';
02402                 sscanf(h, "%x", &b);            
02403                 for (bit = 1; (bit <= 128); (bit = bit << 1)) {
02404                         gdImageSetPixel(im, x++, y, (b & bit) ? 1 : 0); 
02405                         if (x == im->sx) {
02406                                 x = 0;
02407                                 y++;
02408                                 if (y == im->sy) {
02409                                         return im;
02410                                 }
02411                                 /* Fix 8/8/95 */
02412                                 break;
02413                         }
02414                 }
02415         }
02416         /* Shouldn't happen */
02417         fprintf(stderr, "Error: bug in gdImageCreateFromXbm!\n");
02418         return 0;
02419 fail:
02420         gdImageDestroy(im);
02421         return 0;
02422 }

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

Definition at line 319 of file gd.cpp.

References dashedSet().

00320 {
00321         int dx, dy, incr1, incr2, d, x, y, xend, yend, xdirflag, ydirflag;
00322         int dashStep = 0;
00323         int on = 1;
00324         dx = abs(x2-x1);
00325         dy = abs(y2-y1);
00326         if (dy <= dx) {
00327                 d = 2*dy - dx;
00328                 incr1 = 2*dy;
00329                 incr2 = 2 * (dy - dx);
00330                 if (x1 > x2) {
00331                         x = x2;
00332                         y = y2;
00333                         ydirflag = (-1);
00334                         xend = x1;
00335                 } else {
00336                         x = x1;
00337                         y = y1;
00338                         ydirflag = 1;
00339                         xend = x2;
00340                 }
00341                 dashedSet(im, x, y, color, &on, &dashStep);
00342                 if (((y2 - y1) * ydirflag) > 0) {
00343                         while (x < xend) {
00344                                 x++;
00345                                 if (d <0) {
00346                                         d+=incr1;
00347                                 } else {
00348                                         y++;
00349                                         d+=incr2;
00350                                 }
00351                                 dashedSet(im, x, y, color, &on, &dashStep);
00352                         }
00353                 } else {
00354                         while (x < xend) {
00355                                 x++;
00356                                 if (d <0) {
00357                                         d+=incr1;
00358                                 } else {
00359                                         y--;
00360                                         d+=incr2;
00361                                 }
00362                                 dashedSet(im, x, y, color, &on, &dashStep);
00363                         }
00364                 }               
00365         } else {
00366                 d = 2*dx - dy;
00367                 incr1 = 2*dx;
00368                 incr2 = 2 * (dx - dy);
00369                 if (y1 > y2) {
00370                         y = y2;
00371                         x = x2;
00372                         yend = y1;
00373                         xdirflag = (-1);
00374                 } else {
00375                         y = y1;
00376                         x = x1;
00377                         yend = y2;
00378                         xdirflag = 1;
00379                 }
00380                 dashedSet(im, x, y, color, &on, &dashStep);
00381                 if (((x2 - x1) * xdirflag) > 0) {
00382                         while (y < yend) {
00383                                 y++;
00384                                 if (d <0) {
00385                                         d+=incr1;
00386                                 } else {
00387                                         x++;
00388                                         d+=incr2;
00389                                 }
00390                                 dashedSet(im, x, y, color, &on, &dashStep);
00391                         }
00392                 } else {
00393                         while (y < yend) {
00394                                 y++;
00395                                 if (d <0) {
00396                                         d+=incr1;
00397                                 } else {
00398                                         x--;
00399                                         d+=incr2;
00400                                 }
00401                                 dashedSet(im, x, y, color, &on, &dashStep);
00402                         }
00403                 }
00404         }
00405 }

void gdImageDestroy ( gdImagePtr  im  ) 

Definition at line 36 of file gd.cpp.

References gdImageStruct::pixels, gdImageStruct::polyInts, gdImageStruct::style, and gdImageStruct::sy.

Referenced by GDC_destroy_image(), gdImageCreateFromXbm(), main(), out_err(), and pie_gif().

00037 {
00038         int i;
00039         for (i=0; (i<im->sy); i++) {
00040                 free(im->pixels[i]);
00041         }       
00042         free(im->pixels);
00043         if (im->polyInts) {
00044                         free(im->polyInts);
00045         }
00046         if (im->style) {
00047                 free(im->style);
00048         }
00049         free(im);
00050 }

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

Definition at line 660 of file gd.cpp.

References gdImageFill(), gdImageGetPixel(), gdImageGetTransparent, gdImageSetPixel(), gdImageSX, gdImageSY, gdTiled, gdImageStruct::sx, gdImageStruct::sy, gdImageStruct::tile, and gdImageStruct::tileColorMap.

Referenced by gdImageFill(), and main().

00661 {
00662         int lastBorder;
00663         int old;
00664         int leftLimit, rightLimit;
00665         int i;
00666         old = gdImageGetPixel(im, x, y);
00667         if (color == gdTiled) {
00668                 /* Tile fill -- got to watch out! */
00669                 int p, tileColor;       
00670                 int srcx, srcy;
00671                 if (!im->tile) {
00672                         return;
00673                 }
00674                 /* Refuse to flood-fill with a transparent pattern --
00675                         I can't do it without allocating another image */
00676                 if (gdImageGetTransparent(im->tile) != (-1)) {
00677                         return;
00678                 }       
00679                 srcx = x % gdImageSX(im->tile);
00680                 srcy = y % gdImageSY(im->tile);
00681                 p = gdImageGetPixel(im->tile, srcx, srcy);
00682                 tileColor = im->tileColorMap[p];
00683                 if (old == tileColor) {
00684                         /* Nothing to be done */
00685                         return;
00686                 }
00687         } else {
00688                 if (old == color) {
00689                         /* Nothing to be done */
00690                         return;
00691                 }
00692         }
00693         /* Seek left */
00694         leftLimit = (-1);
00695         for (i = x; (i >= 0); i--) {
00696                 if (gdImageGetPixel(im, i, y) != old) {
00697                         break;
00698                 }
00699                 gdImageSetPixel(im, i, y, color);
00700                 leftLimit = i;
00701         }
00702         if (leftLimit == (-1)) {
00703                 return;
00704         }
00705         /* Seek right */
00706         rightLimit = x;
00707         for (i = (x+1); (i < im->sx); i++) {    
00708                 if (gdImageGetPixel(im, i, y) != old) {
00709                         break;
00710                 }
00711                 gdImageSetPixel(im, i, y, color);
00712                 rightLimit = i;
00713         }
00714         /* Look at lines above and below and start paints */
00715         /* Above */
00716         if (y > 0) {
00717                 lastBorder = 1;
00718                 for (i = leftLimit; (i <= rightLimit); i++) {
00719                         int c;
00720                         c = gdImageGetPixel(im, i, y-1);
00721                         if (lastBorder) {
00722                                 if (c == old) { 
00723                                         gdImageFill(im, i, y-1, color);         
00724                                         lastBorder = 0;
00725                                 }
00726                         } else if (c != old) {
00727                                 lastBorder = 1;
00728                         }
00729                 }
00730         }
00731         /* Below */
00732         if (y < ((im->sy) - 1)) {
00733                 lastBorder = 1;
00734                 for (i = leftLimit; (i <= rightLimit); i++) {
00735                         int c;
00736                         c = gdImageGetPixel(im, i, y+1);
00737                         if (lastBorder) {
00738                                 if (c == old) {
00739                                         gdImageFill(im, i, y+1, color);         
00740                                         lastBorder = 0;
00741                                 }
00742                         } else if (c != old) {
00743                                 lastBorder = 1;
00744                         }
00745                 }
00746         }
00747 }

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

Definition at line 2444 of file gd.cpp.

References gdCompareInt(), gdImageLine(), gdImageStruct::polyAllocated, gdImageStruct::polyInts, gdPoint::x, and gdPoint::y.

Referenced by draw_3d_area(), draw_3d_bar(), draw_3d_line(), main(), and pie_gif().

02445 {
02446         int i;
02447         int y;
02448         int y1, y2;
02449         int ints;
02450         if (!n) {
02451                 return;
02452         }
02453         if (!im->polyAllocated) {
02454                 im->polyInts = (int *) malloc(sizeof(int) * n);
02455                 im->polyAllocated = n;
02456         }               
02457         if (im->polyAllocated < n) {
02458                 while (im->polyAllocated < n) {
02459                         im->polyAllocated *= 2;
02460                 }       
02461                 im->polyInts = (int *) realloc(im->polyInts,
02462                         sizeof(int) * im->polyAllocated);
02463         }
02464         y1 = p[0].y;
02465         y2 = p[0].y;
02466         for (i=1; (i < n); i++) {
02467                 if (p[i].y < y1) {
02468                         y1 = p[i].y;
02469                 }
02470                 if (p[i].y > y2) {
02471                         y2 = p[i].y;
02472                 }
02473         }
02474         /* Fix in 1.3: count a vertex only once */
02475         for (y=y1; (y < y2); y++) {
02476                 int interLast = 0;
02477                 int dirLast = 0;
02478                 int interFirst = 1;
02479                 ints = 0;
02480                 for (i=0; (i <= n); i++) {
02481                         int x1, x2;
02482                         int y1, y2;
02483                         int dir;
02484                         int ind1, ind2;
02485                         int lastInd1 = 0;
02486                         if ((i == n) || (!i)) {
02487                                 ind1 = n-1;
02488                                 ind2 = 0;
02489                         } else {
02490                                 ind1 = i-1;
02491                                 ind2 = i;
02492                         }
02493                         y1 = p[ind1].y;
02494                         y2 = p[ind2].y;
02495                         if (y1 < y2) {
02496                                 y1 = p[ind1].y;
02497                                 y2 = p[ind2].y;
02498                                 x1 = p[ind1].x;
02499                                 x2 = p[ind2].x;
02500                                 dir = -1;
02501                         } else if (y1 > y2) {
02502                                 y2 = p[ind1].y;
02503                                 y1 = p[ind2].y;
02504                                 x2 = p[ind1].x;
02505                                 x1 = p[ind2].x;
02506                                 dir = 1;
02507                         } else {
02508                                 /* Horizontal; just draw it */
02509                                 gdImageLine(im, 
02510                                         p[ind1].x, y1, 
02511                                         p[ind2].x, y1,
02512                                         c);
02513                                 continue;
02514                         }
02515                         if ((y >= y1) && (y <= y2)) {
02516                                 int inter = 
02517                                         (y-y1) * (x2-x1) / (y2-y1) + x1;
02518                                 /* Only count intersections once
02519                                         except at maxima and minima. Also, 
02520                                         if two consecutive intersections are
02521                                         endpoints of the same horizontal line
02522                                         that is not at a maxima or minima,      
02523                                         discard the leftmost of the two. */
02524                                 if (!interFirst) {
02525                                         if ((p[ind1].y == p[lastInd1].y) &&
02526                                                 (p[ind1].x != p[lastInd1].x)) {
02527                                                 if (dir == dirLast) {
02528                                                         if (inter > interLast) {
02529                                                                 /* Replace the old one */
02530                                                                 im->polyInts[ints] = inter;
02531                                                         } else {
02532                                                                 /* Discard this one */
02533                                                         }       
02534                                                         continue;
02535                                                 }
02536                                         }
02537                                         if (inter == interLast) {
02538                                                 if (dir == dirLast) {
02539                                                         continue;
02540                                                 }
02541                                         }
02542                                 } 
02543                                 if (i > 0) {
02544                                         im->polyInts[ints++] = inter;
02545                                 }
02546                                 lastInd1 = i;
02547                                 dirLast = dir;
02548                                 interLast = inter;
02549                                 interFirst = 0;
02550                         }
02551                 }
02552                 qsort(im->polyInts, ints, sizeof(int), gdCompareInt);
02553                 for (i=0; (i < (ints-1)); i+=2) {
02554                         gdImageLine(im, im->polyInts[i], y,
02555                                 im->polyInts[i+1], y, c);
02556                 }
02557         }
02558 }

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

Definition at line 2053 of file gd.cpp.

References gdImageSetPixel().

02054 {
02055         int x, y;
02056         for (y=y1; (y<=y2); y++) {
02057                 for (x=x1; (x<=x2); x++) {
02058                         gdImageSetPixel(im, x, y, color);
02059                 }
02060         }
02061 }

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

Definition at line 593 of file gd.cpp.

References gdImageFillToBorder(), gdImageGetPixel(), gdImageSetPixel(), gdImageStruct::sx, and gdImageStruct::sy.

Referenced by gdImageFillToBorder(), and pie_gif().

00594 {
00595         int lastBorder;
00596         /* Seek left */
00597         int leftLimit, rightLimit;
00598         int i;
00599         leftLimit = (-1);
00600         if (border < 0) {
00601                 /* Refuse to fill to a non-solid border */
00602                 return;
00603         }
00604         for (i = x; (i >= 0); i--) {
00605                 if (gdImageGetPixel(im, i, y) == border) {
00606                         break;
00607                 }
00608                 gdImageSetPixel(im, i, y, color);
00609                 leftLimit = i;
00610         }
00611         if (leftLimit == (-1)) {
00612                 return;
00613         }
00614         /* Seek right */
00615         rightLimit = x;
00616         for (i = (x+1); (i < im->sx); i++) {    
00617                 if (gdImageGetPixel(im, i, y) == border) {
00618                         break;
00619                 }
00620                 gdImageSetPixel(im, i, y, color);
00621                 rightLimit = i;
00622         }
00623         /* Look at lines above and below and start paints */
00624         /* Above */
00625         if (y > 0) {
00626                 lastBorder = 1;
00627                 for (i = leftLimit; (i <= rightLimit); i++) {
00628                         int c;
00629                         c = gdImageGetPixel(im, i, y-1);
00630                         if (lastBorder) {
00631                                 if ((c != border) && (c != color)) {    
00632                                         gdImageFillToBorder(im, i, y-1, 
00633                                                 border, color);         
00634                                         lastBorder = 0;
00635                                 }
00636                         } else if ((c == border) || (c == color)) {
00637                                 lastBorder = 1;
00638                         }
00639                 }
00640         }
00641         /* Below */
00642         if (y < ((im->sy) - 1)) {
00643                 lastBorder = 1;
00644                 for (i = leftLimit; (i <= rightLimit); i++) {
00645                         int c;
00646                         c = gdImageGetPixel(im, i, y+1);
00647                         if (lastBorder) {
00648                                 if ((c != border) && (c != color)) {    
00649                                         gdImageFillToBorder(im, i, y+1, 
00650                                                 border, color);         
00651                                         lastBorder = 0;
00652                                 }
00653                         } else if ((c == border) || (c == color)) {
00654                                 lastBorder = 1;
00655                         }
00656                 }
00657         }
00658 }

void gdImageGd ( gdImagePtr  im,
FILE *  out 
)

Definition at line 2290 of file gd.cpp.

References gdImageStruct::blue, gdImageStruct::colorsTotal, gdMaxColors, gdPutWord(), gdImageStruct::green, gdImageStruct::pixels, gdImageStruct::red, gdImageStruct::sx, gdImageStruct::sy, and gdImageStruct::transparent.

Referenced by main().

02291 {
02292         int x, y;
02293         int i;
02294         int trans;
02295         gdPutWord(im->sx, out);
02296         gdPutWord(im->sy, out);
02297         putc((unsigned char)im->colorsTotal, out);
02298         trans = im->transparent;
02299         if (trans == (-1)) {
02300                 trans = 257;
02301         }       
02302         gdPutWord(trans, out);
02303         for (i=0; (i<gdMaxColors); i++) {
02304                 putc((unsigned char)im->red[i], out);
02305                 putc((unsigned char)im->green[i], out); 
02306                 putc((unsigned char)im->blue[i], out);  
02307         }
02308         for (y=0; (y < im->sy); y++) {  
02309                 for (x=0; (x < im->sx); x++) {  
02310                         /* ROW-MAJOR IN GD 1.3 */
02311                         putc((unsigned char)im->pixels[y][x], out);
02312                 }
02313         }
02314 }

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

Definition at line 218 of file gd.cpp.

References gdImageBoundsSafe(), and gdImageStruct::pixels.

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

00219 {
00220         if (gdImageBoundsSafe(im, x, y)) {
00221                 /* NOW ROW-MAJOR IN GD 1.3 */
00222                 return im->pixels[y][x];
00223         } else {
00224                 return 0;
00225         }
00226 }

void gdImageGif ( gdImagePtr  im,
FILE *  out 
)

Definition at line 792 of file gd.cpp.

References gdImageStruct::blue, colorstobpp(), gdImageStruct::colorsTotal, GIFEncode(), gdImageStruct::green, init_statics(), gdImageStruct::interlace, gdImageStruct::red, gdImageStruct::sx, gdImageStruct::sy, gdImageStruct::transparent, and transparent.

Referenced by main(), out_err(), and pie_gif().

00793 {
00794         int interlace, transparent, BitsPerPixel;
00795         interlace = im->interlace;
00796         transparent = im->transparent;
00797 
00798         BitsPerPixel = colorstobpp(im->colorsTotal);
00799         /* Clear any old values in statics strewn through the GIF code */
00800         init_statics();
00801         /* All set, let's do it. */
00802         GIFEncode(
00803                 out, im->sx, im->sy, interlace, 0, transparent, BitsPerPixel,
00804                 im->red, im->green, im->blue, im);
00805 }

void gdImageInterlace ( gdImagePtr  im,
int  interlaceArg 
)

Definition at line 2629 of file gd.cpp.

References gdImageStruct::interlace.

Referenced by main().

02630 {
02631         im->interlace = interlaceArg;
02632 }

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

Definition at line 230 of file gd.cpp.

References gdImageSetPixel().

Referenced by draw_3d_area(), draw_3d_bar(), draw_3d_line(), gdImageArc(), gdImageFilledPolygon(), gdImagePolygon(), gdImageRectangle(), main(), and pie_gif().

00231 {
00232         int dx, dy, incr1, incr2, d, x, y, xend, yend, xdirflag, ydirflag;
00233         dx = abs(x2-x1);
00234         dy = abs(y2-y1);
00235         if (dy <= dx) {
00236                 d = 2*dy - dx;
00237                 incr1 = 2*dy;
00238                 incr2 = 2 * (dy - dx);
00239                 if (x1 > x2) {
00240                         x = x2;
00241                         y = y2;
00242                         ydirflag = (-1);
00243                         xend = x1;
00244                 } else {
00245                         x = x1;
00246                         y = y1;
00247                         ydirflag = 1;
00248                         xend = x2;
00249                 }
00250                 gdImageSetPixel(im, x, y, color);
00251                 if (((y2 - y1) * ydirflag) > 0) {
00252                         while (x < xend) {
00253                                 x++;
00254                                 if (d <0) {
00255                                         d+=incr1;
00256                                 } else {
00257                                         y++;
00258                                         d+=incr2;
00259                                 }
00260                                 gdImageSetPixel(im, x, y, color);
00261                         }
00262                 } else {
00263                         while (x < xend) {
00264                                 x++;
00265                                 if (d <0) {
00266                                         d+=incr1;
00267                                 } else {
00268                                         y--;
00269                                         d+=incr2;
00270                                 }
00271                                 gdImageSetPixel(im, x, y, color);
00272                         }
00273                 }               
00274         } else {
00275                 d = 2*dx - dy;
00276                 incr1 = 2*dx;
00277                 incr2 = 2 * (dx - dy);
00278                 if (y1 > y2) {
00279                         y = y2;
00280                         x = x2;
00281                         yend = y1;
00282                         xdirflag = (-1);
00283                 } else {
00284                         y = y1;
00285                         x = x1;
00286                         yend = y2;
00287                         xdirflag = 1;
00288                 }
00289                 gdImageSetPixel(im, x, y, color);
00290                 if (((x2 - x1) * xdirflag) > 0) {
00291                         while (y < yend) {
00292                                 y++;
00293                                 if (d <0) {
00294                                         d+=incr1;
00295                                 } else {
00296                                         x++;
00297                                         d+=incr2;
00298                                 }
00299                                 gdImageSetPixel(im, x, y, color);
00300                         }
00301                 } else {
00302                         while (y < yend) {
00303                                 y++;
00304                                 if (d <0) {
00305                                         d+=incr1;
00306                                 } else {
00307                                         x--;
00308                                         d+=incr2;
00309                                 }
00310                                 gdImageSetPixel(im, x, y, color);
00311                         }
00312                 }
00313         }
00314 }

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

Definition at line 2424 of file gd.cpp.

References gdImageLine(), gdPoint::x, and gdPoint::y.

02425 {
02426         int i;
02427         int lx, ly;
02428         if (!n) {
02429                 return;
02430         }
02431         lx = p->x;
02432         ly = p->y;
02433         gdImageLine(im, lx, ly, p[n-1].x, p[n-1].y, c);
02434         for (i=1; (i < n); i++) {
02435                 p++;
02436                 gdImageLine(im, lx, ly, p->x, p->y, c);
02437                 lx = p->x;
02438                 ly = p->y;
02439         }
02440 }       

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

Definition at line 2045 of file gd.cpp.

References gdImageLine().

02046 {
02047         gdImageLine(im, x1, y1, x2, y1, color);         
02048         gdImageLine(im, x1, y2, x2, y2, color);         
02049         gdImageLine(im, x1, y1, x1, y2, color);
02050         gdImageLine(im, x2, y1, x2, y2, color);
02051 }

void gdImageSetBrush ( gdImagePtr  im,
gdImagePtr  brush 
)

Definition at line 2577 of file gd.cpp.

References gdImageStruct::brush, gdImageStruct::brushColorMap, gdImageBlue, gdImageColorAllocate(), gdImageColorClosest(), gdImageColorExact(), gdImageColorsTotal, gdImageGreen, and gdImageRed.

Referenced by main().

02578 {
02579         int i;
02580         im->brush = brush;
02581         for (i=0; (i < gdImageColorsTotal(brush)); i++) {
02582                 int index;
02583                 index = gdImageColorExact(im, 
02584                         gdImageRed(brush, i),
02585                         gdImageGreen(brush, i),
02586                         gdImageBlue(brush, i));
02587                 if (index == (-1)) {
02588                         index = gdImageColorAllocate(im,
02589                                 gdImageRed(brush, i),
02590                                 gdImageGreen(brush, i),
02591                                 gdImageBlue(brush, i));
02592                         if (index == (-1)) {
02593                                 index = gdImageColorClosest(im,
02594                                         gdImageRed(brush, i),
02595                                         gdImageGreen(brush, i),
02596                                         gdImageBlue(brush, i));
02597                         }
02598                 }
02599                 im->brushColorMap[i] = index;
02600         }
02601 }

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

Definition at line 126 of file gd.cpp.

References gdBrushed, gdImageBoundsSafe(), gdImageBrushApply(), gdImageSetPixel(), gdImageTileApply(), gdStyled, gdStyledBrushed, gdTiled, gdTransparent, gdImageStruct::pixels, gdImageStruct::style, gdImageStruct::styleLength, and gdImageStruct::stylePos.

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

00127 {
00128         int p;
00129         switch(color) {
00130                 case gdStyled:
00131                 if (!im->style) {
00132                         /* Refuse to draw if no style is set. */
00133                         return;
00134                 } else {
00135                         p = im->style[im->stylePos++];
00136                 }
00137                 if (p != (gdTransparent)) {
00138                         gdImageSetPixel(im, x, y, p);
00139                 }
00140                 im->stylePos = im->stylePos %  im->styleLength;
00141                 break;
00142                 case gdStyledBrushed:
00143                 if (!im->style) {
00144                         /* Refuse to draw if no style is set. */
00145                         return;
00146                 }
00147                 p = im->style[im->stylePos++];
00148                 if ((p != gdTransparent) && (p != 0)) {
00149                         gdImageSetPixel(im, x, y, gdBrushed);
00150                 }
00151                 im->stylePos = im->stylePos %  im->styleLength;
00152                 break;
00153                 case gdBrushed:
00154                 gdImageBrushApply(im, x, y);
00155                 break;
00156                 case gdTiled:
00157                 gdImageTileApply(im, x, y);
00158                 break;
00159                 default:
00160                 if (gdImageBoundsSafe(im, x, y)) {
00161                         /* NOW ROW-MAJOR IN GD 1.3 */
00162                         im->pixels[y][x] = color;
00163                 }
00164                 break;
00165         }
00166 }

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

Definition at line 2565 of file gd.cpp.

References gdImageStruct::style, gdImageStruct::styleLength, and gdImageStruct::stylePos.

Referenced by main().

02566 {
02567         if (im->style) {
02568                 free(im->style);
02569         }
02570         im->style = (int *) 
02571                 malloc(sizeof(int) * noOfPixels);
02572         memcpy(im->style, style, sizeof(int) * noOfPixels);
02573         im->styleLength = noOfPixels;
02574         im->stylePos = 0;
02575 }

void gdImageSetTile ( gdImagePtr  im,
gdImagePtr  tile 
)

Definition at line 2603 of file gd.cpp.

References gdImageBlue, gdImageColorAllocate(), gdImageColorClosest(), gdImageColorExact(), gdImageColorsTotal, gdImageGreen, gdImageRed, gdImageStruct::tile, and gdImageStruct::tileColorMap.

02604 {
02605         int i;
02606         im->tile = tile;
02607         for (i=0; (i < gdImageColorsTotal(tile)); i++) {
02608                 int index;
02609                 index = gdImageColorExact(im, 
02610                         gdImageRed(tile, i),
02611                         gdImageGreen(tile, i),
02612                         gdImageBlue(tile, i));
02613                 if (index == (-1)) {
02614                         index = gdImageColorAllocate(im,
02615                                 gdImageRed(tile, i),
02616                                 gdImageGreen(tile, i),
02617                                 gdImageBlue(tile, i));
02618                         if (index == (-1)) {
02619                                 index = gdImageColorClosest(im,
02620                                         gdImageRed(tile, i),
02621                                         gdImageGreen(tile, i),
02622                                         gdImageBlue(tile, i));
02623                         }
02624                 }
02625                 im->tileColorMap[i] = index;
02626         }
02627 }

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

Definition at line 479 of file gd.cpp.

References gdImageChar(), and gdFont::w.

Referenced by GDCImageStringNL(), main(), out_err(), and pie_gif().

00481 {
00482         int i;
00483         int l;
00484         l = strlen((char *)s);
00485         for (i=0; (i<l); i++) {
00486                 gdImageChar(im, f, x, y, s[i], color);
00487                 x += f->w;
00488         }
00489 }

void gdImageString16 ( gdImagePtr  im,
gdFontPtr  f,
int  x,
int  y,
unsigned short *  s,
int  color 
)

Definition at line 505 of file gd.cpp.

References gdImageChar(), strlen16(), and gdFont::w.

00507 {
00508         int i;
00509         int l;
00510         l = strlen16(s);
00511         for (i=0; (i<l); i++) {
00512                 gdImageChar(im, f, x, y, s[i], color);
00513                 x += f->w;
00514         }
00515 }

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

Definition at line 491 of file gd.cpp.

References gdImageCharUp(), and gdFont::w.

Referenced by main().

00493 {
00494         int i;
00495         int l;
00496         l = strlen((char *)s);
00497         for (i=0; (i<l); i++) {
00498                 gdImageCharUp(im, f, x, y, s[i], color);
00499                 y -= f->w;
00500         }
00501 }

void gdImageStringUp16 ( gdImagePtr  im,
gdFontPtr  f,
int  x,
int  y,
unsigned short *  s,
int  color 
)

Definition at line 517 of file gd.cpp.

References gdImageCharUp(), strlen16(), and gdFont::w.

00519 {
00520         int i;
00521         int l;
00522         l = strlen16(s);
00523         for (i=0; (i<l); i++) {
00524                 gdImageCharUp(im, f, x, y, s[i], color);
00525                 y -= f->w;
00526         }
00527 }


Generated on Sat Dec 15 00:01:27 2007 for BulmaGes by  doxygen 1.5.1