Back to index

wims  3.65+svn20090927
Defines | Typedefs | Functions | Variables
gd.c File Reference
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include "gd.h"
#include "mtables.c"
#include <ctype.h>

Go to the source code of this file.

Defines

#define dashedSet
#define TRUE   1
#define FALSE   0
#define GIFBITS   12
#define HSIZE   5003 /* 80% occupancy */
#define ARGVAL()   (*++(*argv) || (--argc && *++argv))
#define MAXCODE(n_bits)   (((code_int) 1 << (n_bits)) - 1)
#define HashTabOf(i)   htab[i]
#define CodeTabOf(i)   codetab[i]
#define tab_prefixof(i)   CodeTabOf(i)
#define tab_suffixof(i)   ((char_type*)(htab))[i]
#define de_stack   ((char_type*)&tab_suffixof((code_int)1<<GIFBITS))
#define MAXCOLORMAPSIZE   256
#define TRUE   1
#define FALSE   0
#define CM_RED   0
#define CM_GREEN   1
#define CM_BLUE   2
#define MAX_LWZ_BITS   12
#define INTERLACE   0x40
#define LOCALCOLORMAP   0x80
#define BitSet(byte, bit)   (((byte) & (bit)) == (bit))
#define ReadOK(file, buffer, len)   (fread(buffer, len, 1, file) != 0)
#define LM_to_uint(a, b)   (((b)<<8)|(a))

Typedefs

typedef int code_int
typedef long int count_int
typedef unsigned char char_type

Functions

static void gdImageBrushApply (gdImagePtr im, int x, int y)
static void gdImageTileApply (gdImagePtr im, int x, int y)
gdImagePtr gdImageCreate (int sx, int sy)
void gdImageDestroy (gdImagePtr im)
int gdImageColorClosest (gdImagePtr im, int r, int g, int b)
int gdImageColorExact (gdImagePtr im, int r, int g, int b)
int gdImageColorAllocate (gdImagePtr im, int r, int g, int b)
void gdImageColorDeallocate (gdImagePtr im, int color)
void gdImageColorTransparent (gdImagePtr im, int color)
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)
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 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)
static int colorstobpp (int colors)
static void BumpPixel (void)
static int GIFNextPixel (gdImagePtr im)
static void GIFEncode (FILE *fp, int GWidth, int GHeight, int GInterlace, int Background, int Transparent, int BitsPerPixel, int *Red, int *Green, int *Blue, gdImagePtr im)
static void Putword (int w, FILE *fp)
static void compress (int init_bits, FILE *outfile, gdImagePtr im)
static void output (code_int code)
static void cl_block (void)
static void cl_hash (register count_int hsize)
static void char_init (void)
static void char_out (int c)
static void flush_char (void)
static void init_statics (void)
void gdImageGif (gdImagePtr im, FILE *out)
static int ReadColorMap (FILE *fd, int number, unsigned char(*buffer)[256])
static int DoExtension (FILE *fd, int label, int *Transparent)
static int GetDataBlock (FILE *fd, unsigned char *buf)
static int GetCode (FILE *fd, int code_size, int flag)
static int LWZReadByte (FILE *fd, int flag, int input_code_size)
static void ReadImage (gdImagePtr im, FILE *fd, int len, int height, unsigned char(*cmap)[256], int interlace, int ignore)
gdImagePtr gdImageCreateFromGif (FILE *fd)
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)
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)
int gdGetWord (int *result, FILE *in)
void gdPutWord (int w, FILE *out)
int gdGetByte (int *result, FILE *in)
gdImagePtr gdImageCreateFromGd (FILE *in)
void gdImageGd (gdImagePtr im, FILE *out)
gdImagePtr gdImageCreateFromXbm (FILE *fd)
void gdImagePolygon (gdImagePtr im, gdPointPtr p, int n, int c)
int gdCompareInt (const void *a, const void *b)
void gdImageFilledPolygon (gdImagePtr im, gdPointPtr p, int n, int c)
void gdImageSetStyle (gdImagePtr im, int *style, int noOfPixels)
void gdImageSetBrush (gdImagePtr im, gdImagePtr brush)
void gdImageSetTile (gdImagePtr im, gdImagePtr tile)
void gdImageInterlace (gdImagePtr im, int interlaceArg)

Variables

static int Width
static int Height
static int curx
static int cury
static long CountDown
static int Pass = 0
static int Interlace
static int n_bits
static int maxbits = GIFBITS
static code_int maxcode
static code_int maxmaxcode = (code_int)1 << GIFBITS
static count_int htab [HSIZE]
static unsigned short codetab [HSIZE]
static code_int hsize = HSIZE
static code_int free_ent = 0
static int clear_flg = 0
static int offset
static long int in_count = 1
static long int out_count = 0
static int g_init_bits
static FILE * g_outfile
static int ClearCode
static int EOFCode
static unsigned long cur_accum = 0
static int cur_bits = 0
static unsigned long masks []
static int a_count
static char accum [256]
struct {
int transparent
int delayTime
int inputFlag
int disposal
Gif89
int ZeroDataBlock

Define Documentation

#define ARGVAL ( )    (*++(*argv) || (--argc && *++argv))

Definition at line 1100 of file gd.c.

#define BitSet (   byte,
  bit 
)    (((byte) & (bit)) == (bit))

Definition at line 1500 of file gd.c.

#define CM_BLUE   2

Definition at line 1494 of file gd.c.

#define CM_GREEN   1

Definition at line 1493 of file gd.c.

#define CM_RED   0

Definition at line 1492 of file gd.c.

#define CodeTabOf (   i)    codetab[i]

Definition at line 1115 of file gd.c.

Value:
{ \
              dashStep++; \
              if (dashStep == gdDashSize) { \
                     dashStep = 0; \
                     on = !on; \
              } \
              if (on) { \
                     gdImageSetPixel(im, x, y, color); \
              } \
       }

Definition at line 315 of file gd.c.

Definition at line 1130 of file gd.c.

#define FALSE   0

Definition at line 1490 of file gd.c.

#define FALSE   0

Definition at line 1490 of file gd.c.

#define GIFBITS   12

Definition at line 1074 of file gd.c.

#define HashTabOf (   i)    htab[i]

Definition at line 1114 of file gd.c.

#define HSIZE   5003 /* 80% occupancy */

Definition at line 1076 of file gd.c.

#define INTERLACE   0x40

Definition at line 1498 of file gd.c.

#define LM_to_uint (   a,
 
)    (((b)<<8)|(a))

Definition at line 1504 of file gd.c.

#define LOCALCOLORMAP   0x80

Definition at line 1499 of file gd.c.

#define MAX_LWZ_BITS   12

Definition at line 1496 of file gd.c.

#define MAXCODE (   n_bits)    (((code_int) 1 << (n_bits)) - 1)

Definition at line 1109 of file gd.c.

Definition at line 1487 of file gd.c.

#define ReadOK (   file,
  buffer,
  len 
)    (fread(buffer, len, 1, file) != 0)

Definition at line 1502 of file gd.c.

#define tab_prefixof (   i)    CodeTabOf(i)

Definition at line 1128 of file gd.c.

#define tab_suffixof (   i)    ((char_type*)(htab))[i]

Definition at line 1129 of file gd.c.

#define TRUE   1

Definition at line 1489 of file gd.c.

#define TRUE   1

Definition at line 1489 of file gd.c.


Typedef Documentation

typedef unsigned char char_type

Definition at line 1081 of file gd.c.

typedef int code_int

Definition at line 740 of file gd.c.

typedef long int count_int

Definition at line 746 of file gd.c.


Function Documentation

static void BumpPixel ( void  ) [static]

Definition at line 825 of file gd.c.

{
        /*
         * Bump the current X position
         */
        ++curx;

        /*
         * If we are at the end of a scan line, set curx back to the beginning
         * If we are interlaced, bump the cury to the appropriate spot,
         * otherwise, just increment it.
         */
        if( curx == Width ) {
                curx = 0;

                if( !Interlace )
                        ++cury;
                else {
                     switch( Pass ) {

                       case 0:
                          cury += 8;
                          if( cury >= Height ) {
                                ++Pass;
                                cury = 4;
                          }
                          break;

                       case 1:
                          cury += 8;
                          if( cury >= Height ) {
                                ++Pass;
                                cury = 2;
                          }
                          break;

                       case 2:
                          cury += 4;
                          if( cury >= Height ) {
                             ++Pass;
                             cury = 1;
                          }
                          break;

                       case 3:
                          cury += 2;
                          break;
                        }
                }
        }
}

Here is the caller graph for this function:

static void char_init ( void  ) [static]

Definition at line 1409 of file gd.c.

{
        a_count = 0;
}

Here is the caller graph for this function:

static void char_out ( int  c) [static]

Definition at line 1424 of file gd.c.

{
        accum[ a_count++ ] = c;
        if( a_count >= 254 )
                flush_char();
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void cl_block ( void  ) [static]

Definition at line 1349 of file gd.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void cl_hash ( register count_int  hsize) [static]

Definition at line 1360 of file gd.c.

{

        register count_int *htab_p = htab+hsize;

        register long i;
        register long m1 = -1;

        i = hsize - 16;
        do {                            /* might use Sys V memset(3) here */
                *(htab_p-16) = m1;
                *(htab_p-15) = m1;
                *(htab_p-14) = m1;
                *(htab_p-13) = m1;
                *(htab_p-12) = m1;
                *(htab_p-11) = m1;
                *(htab_p-10) = m1;
                *(htab_p-9) = m1;
                *(htab_p-8) = m1;
                *(htab_p-7) = m1;
                *(htab_p-6) = m1;
                *(htab_p-5) = m1;
                *(htab_p-4) = m1;
                *(htab_p-3) = m1;
                *(htab_p-2) = m1;
                *(htab_p-1) = m1;
                htab_p -= 16;
        } while ((i -= 16) >= 0);

        for ( i += 16; i > 0; --i )
                *--htab_p = m1;
}

Here is the caller graph for this function:

static int colorstobpp ( int  colors) [static]

Definition at line 780 of file gd.c.

{
    int bpp = 0;

    if ( colors <= 2 )
        bpp = 1;
    else if ( colors <= 4 )
        bpp = 2;
    else if ( colors <= 8 )
        bpp = 3;
    else if ( colors <= 16 )
        bpp = 4;
    else if ( colors <= 32 )
        bpp = 5;
    else if ( colors <= 64 )
        bpp = 6;
    else if ( colors <= 128 )
        bpp = 7;
    else if ( colors <= 256 )
        bpp = 8;
    return bpp;
    }

Here is the caller graph for this function:

static void compress ( int  init_bits,
FILE *  outfile,
gdImagePtr  im 
) [static]

Definition at line 1167 of file gd.c.

{
    register long fcode;
    register code_int i /* = 0 */;
    register int c;
    register code_int ent;
    register code_int disp;
    register code_int hsize_reg;
    register int hshift;

    /*
     * Set up the globals:  g_init_bits - initial number of bits
     *                      g_outfile   - pointer to output file
     */
    g_init_bits = init_bits;
    g_outfile = outfile;

    /*
     * Set up the necessary values
     */
    offset = 0;
    out_count = 0;
    clear_flg = 0;
    in_count = 1;
    maxcode = MAXCODE(n_bits = g_init_bits);

    ClearCode = (1 << (init_bits - 1));
    EOFCode = ClearCode + 1;
    free_ent = ClearCode + 2;

    char_init();

    ent = GIFNextPixel( im );

    hshift = 0;
    for ( fcode = (long) hsize;  fcode < 65536L; fcode *= 2L )
        ++hshift;
    hshift = 8 - hshift;                /* set hash code range bound */

    hsize_reg = hsize;
    cl_hash( (count_int) hsize_reg);            /* clear hash table */

    output( (code_int)ClearCode );

#ifdef SIGNED_COMPARE_SLOW
    while ( (c = GIFNextPixel( im )) != (unsigned) EOF ) {
#else /*SIGNED_COMPARE_SLOW*/
    while ( (c = GIFNextPixel( im )) != EOF ) {  /* } */
#endif /*SIGNED_COMPARE_SLOW*/

        ++in_count;

        fcode = (long) (((long) c << maxbits) + ent);
        i = (((code_int)c << hshift) ^ ent);    /* xor hashing */

        if ( HashTabOf (i) == fcode ) {
            ent = CodeTabOf (i);
            continue;
        } else if ( (long)HashTabOf (i) < 0 )      /* empty slot */
            goto nomatch;
        disp = hsize_reg - i;           /* secondary hash (after G. Knott) */
        if ( i == 0 )
            disp = 1;
probe:
        if ( (i -= disp) < 0 )
            i += hsize_reg;

        if ( HashTabOf (i) == fcode ) {
            ent = CodeTabOf (i);
            continue;
        }
        if ( (long)HashTabOf (i) > 0 )
            goto probe;
nomatch:
        output ( (code_int) ent );
        ++out_count;
        ent = c;
#ifdef SIGNED_COMPARE_SLOW
        if ( (unsigned) free_ent < (unsigned) maxmaxcode) {
#else /*SIGNED_COMPARE_SLOW*/
        if ( free_ent < maxmaxcode ) {  /* } */
#endif /*SIGNED_COMPARE_SLOW*/
            CodeTabOf (i) = free_ent++; /* code -> hashtable */
            HashTabOf (i) = fcode;
        } else
                cl_block();
    }
    /*
     * Put out the final code.
     */
    output( (code_int)ent );
    ++out_count;
    output( (code_int) EOFCode );
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int DoExtension ( FILE *  fd,
int  label,
int *  Transparent 
) [static]

Definition at line 1676 of file gd.c.

{
       static unsigned char     buf[256];

       switch (label) {
       case 0xf9:              /* Graphic Control Extension */
               (void) GetDataBlock(fd, (unsigned char*) buf);
               Gif89.disposal    = (buf[0] >> 2) & 0x7;
               Gif89.inputFlag   = (buf[0] >> 1) & 0x1;
               Gif89.delayTime   = LM_to_uint(buf[1],buf[2]);
               if ((buf[0] & 0x1) != 0)
                       *Transparent = buf[3];

               while (GetDataBlock(fd, (unsigned char*) buf) != 0)
                       ;
               return FALSE;
       default:
               break;
       }
       while (GetDataBlock(fd, (unsigned char*) buf) != 0)
               ;

       return FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void flush_char ( void  ) [static]

Definition at line 1435 of file gd.c.

{
        if( a_count > 0 ) {
                fputc( a_count, g_outfile );
                fwrite( accum, 1, a_count, g_outfile );
                a_count = 0;
        }
}

Here is the caller graph for this function:

int gdCompareInt ( const void *  a,
const void *  b 
)

Definition at line 2467 of file gd.c.

{
       return (*(const int *)a) - (*(const int *)b);
}

Here is the caller graph for this function:

int gdGetByte ( int *  result,
FILE *  in 
)

Definition at line 2137 of file gd.c.

{
       int r;
       r = getc(in);
       if (r == EOF) {
              return 0;
       }
       *result = r;
       return 1;
}

Here is the caller graph for this function:

int gdGetWord ( int *  result,
FILE *  in 
)

Definition at line 2115 of file gd.c.

{
       int r;
       r = getc(in);
       if (r == EOF) {
              return 0;
       }
       *result = r << 8;
       r = getc(in); 
       if (r == EOF) {
              return 0;
       }
       *result += r;
       return 1;
}

Here is the caller graph for this function:

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

Definition at line 499 of file gd.c.

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 415 of file gd.c.

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

Here is the caller graph for this function:

static void gdImageBrushApply ( gdImagePtr  im,
int  x,
int  y 
) [static]

Definition at line 166 of file gd.c.

{
       int lx, ly;
       int hy;
       int hx;
       int x1, y1, x2, y2;
       int srcx, srcy;
       if (!im->brush) {
              return;
       }
       hy = gdImageSY(im->brush)/2;
       y1 = y - hy;
       y2 = y1 + gdImageSY(im->brush);    
       hx = gdImageSX(im->brush)/2;
       x1 = x - hx;
       x2 = x1 + gdImageSX(im->brush);
       srcy = 0;
       for (ly = y1; (ly < y2); ly++) {
              srcx = 0;
              for (lx = x1; (lx < x2); lx++) {
                     int p;
                     p = gdImageGetPixel(im->brush, srcx, srcy);
                     /* Allow for non-square brushes! */
                     if (p != gdImageGetTransparent(im->brush)) {
                            gdImageSetPixel(im, lx, ly,
                                   im->brushColorMap[p]);
                     }
                     srcx++;
              }
              srcy++;
       }      
}             

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 421 of file gd.c.

{
       int cx, cy;
       int px, py;
       int fline;
       cx = 0;
       cy = 0;
       if ((c < f->offset) || (c >= (f->offset + f->nchars))) {
              return;
       }
       fline = (c - f->offset) * f->h * f->w;
       for (py = y; (py < (y + f->h)); py++) {
              for (px = x; (px < (x + f->w)); px++) {
                     if (f->data[fline + cy * f->w + cx]) {
                            gdImageSetPixel(im, px, py, color);       
                     }
                     cx++;
              }
              cx = 0;
              cy++;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 444 of file gd.c.

{
       int cx, cy;
       int px, py;
       int fline;
       cx = 0;
       cy = 0;
       if ((c < f->offset) || (c >= (f->offset + f->nchars))) {
              return;
       }
       fline = (c - f->offset) * f->h * f->w;
       for (py = y; (py > (y - f->w)); py--) {
              for (px = x; (px < (x + f->h)); px++) {
                     if (f->data[fline + cy * f->w + cx]) {
                            gdImageSetPixel(im, px, py, color);       
                     }
                     cy++;
              }
              cy = 0;
              cx++;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 90 of file gd.c.

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

Here is the caller graph for this function:

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

Definition at line 51 of file gd.c.

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

Here is the caller graph for this function:

void gdImageColorDeallocate ( gdImagePtr  im,
int  color 
)

Definition at line 114 of file gd.c.

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

Definition at line 74 of file gd.c.

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

Here is the caller graph for this function:

void gdImageColorTransparent ( gdImagePtr  im,
int  color 
)

Definition at line 120 of file gd.c.

{
       im->transparent = color;
}

Here is the caller graph for this function:

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

Definition at line 1973 of file gd.c.

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 2027 of file gd.c.

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

Here is the call graph for this function:

Here is the caller graph for this function:

gdImagePtr gdImageCreate ( int  sx,
int  sy 
)

Definition at line 12 of file gd.c.

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

Here is the caller graph for this function:

Definition at line 2148 of file gd.c.

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

Here is the call graph for this function:

Definition at line 1536 of file gd.c.

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

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

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

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

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

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

               ++imageCount;

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

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

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2225 of file gd.c.

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

Here is the call graph for this function:

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

Definition at line 327 of file gd.c.

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

Here is the caller graph for this function:

void gdImageDestroy ( gdImagePtr  im)

Definition at line 35 of file gd.c.

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

Here is the caller graph for this function:

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

Definition at line 612 of file gd.c.

{
       int lastBorder;
       int old;
       int leftLimit, rightLimit;
       int i;
        /* XIAO: overboard */
        if(x<0 || y<0 || x>=im->sx || y>=im->sy) return;
       old = gdImageGetPixel(im, x, y);
       if (color == gdTiled) {
              /* Tile fill -- got to watch out! */
              int p, tileColor;    
              int srcx, srcy;
              if (!im->tile) {
                     return;
              }
              /* Refuse to flood-fill with a transparent pattern --
                     I can't do it without allocating another image */
              if (gdImageGetTransparent(im->tile) != (-1)) {
                     return;
              }      
              srcx = x % gdImageSX(im->tile);
              srcy = y % gdImageSY(im->tile);
              p = gdImageGetPixel(im->tile, srcx, srcy);
              tileColor = im->tileColorMap[p];
              if (old == tileColor) {
                     /* Nothing to be done */
                     return;
              }
       } else {
              if (old == color) {
                     /* Nothing to be done */
                     return;
              }
       }
       /* Seek left */
       leftLimit = (-1);
       for (i = x; (i >= 0); i--) {
              if (gdImageGetPixel(im, i, y) != old) {
                     break;
              }
              gdImageSetPixel(im, i, y, color);
              leftLimit = i;
       }
       if (leftLimit == (-1)) {
              return;
       }
       /* Seek right */
       rightLimit = x;
       for (i = (x+1); (i < im->sx); i++) {      
              if (gdImageGetPixel(im, i, y) != old) {
                     break;
              }
              gdImageSetPixel(im, i, y, color);
              rightLimit = i;
       }
       /* Look at lines above and below and start paints */
       /* Above */
       if (y > 0) {
              lastBorder = 1;
              for (i = leftLimit; (i <= rightLimit); i++) {
                     int c;
                     c = gdImageGetPixel(im, i, y-1);
                     if (lastBorder) {
                            if (c == old) {      
                                   gdImageFill(im, i, y-1, color);           
                                   lastBorder = 0;
                            }
                     } else if (c != old) {
                            lastBorder = 1;
                     }
              }
       }
       /* Below */
       if (y < ((im->sy) - 1)) {
              lastBorder = 1;
              for (i = leftLimit; (i <= rightLimit); i++) {
                     int c;
                     c = gdImageGetPixel(im, i, y+1);
                     if (lastBorder) {
                            if (c == old) {
                                   gdImageFill(im, i, y+1, color);           
                                   lastBorder = 0;
                            }
                     } else if (c != old) {
                            lastBorder = 1;
                     }
              }
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 2352 of file gd.c.

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 1963 of file gd.c.

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 543 of file gd.c.

{
       int lastBorder;
       /* Seek left */
       int leftLimit, rightLimit;
       int i;
        /* XIAO: overboard */
        if(x<0 || y<0 || x>=im->sx || y>=im->sy) return;
       leftLimit = (-1);
       if (border < 0) {
              /* Refuse to fill to a non-solid border */
              return;
       }
       for (i = x; (i >= 0); i--) {
              if (gdImageGetPixel(im, i, y) == border) {
                     break;
              }
              gdImageSetPixel(im, i, y, color);
              leftLimit = i;
       }
       if (leftLimit == (-1)) {
              return;
       }
       /* Seek right */
       rightLimit = x;
       for (i = (x+1); (i < im->sx); i++) {      
              if (gdImageGetPixel(im, i, y) == border) {
                     break;
              }
              gdImageSetPixel(im, i, y, color);
              rightLimit = i;
       }
       /* Look at lines above and below and start paints */
       /* Above */
       if (y > 0) {
              lastBorder = 1;
              for (i = leftLimit; (i <= rightLimit); i++) {
                     int c;
                     c = gdImageGetPixel(im, i, y-1);
                     if (lastBorder) {
                            if ((c != border) && (c != color)) {      
                                   gdImageFillToBorder(im, i, y-1, 
                                          border, color);             
                                   lastBorder = 0;
                            }
                     } else if ((c == border) || (c == color)) {
                            lastBorder = 1;
                     }
              }
       }
       /* Below */
       if (y < ((im->sy) - 1)) {
              lastBorder = 1;
              for (i = leftLimit; (i <= rightLimit); i++) {
                     int c;
                     c = gdImageGetPixel(im, i, y+1);
                     if (lastBorder) {
                            if ((c != border) && (c != color)) {      
                                   gdImageFillToBorder(im, i, y+1, 
                                          border, color);             
                                   lastBorder = 0;
                            }
                     } else if ((c == border) || (c == color)) {
                            lastBorder = 1;
                     }
              }
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void gdImageGd ( gdImagePtr  im,
FILE *  out 
)

Definition at line 2199 of file gd.c.

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 216 of file gd.c.

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

Here is the call graph for this function:

Here is the caller graph for this function:

void gdImageGif ( gdImagePtr  im,
FILE *  out 
)

Definition at line 764 of file gd.c.

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

void gdImageInterlace ( gdImagePtr  im,
int  interlaceArg 
)

Definition at line 2536 of file gd.c.

{
       im->interlace = interlaceArg;
}

Here is the caller graph for this function:

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

Definition at line 227 of file gd.c.

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 2332 of file gd.c.

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 1955 of file gd.c.

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

Here is the call graph for this function:

Here is the caller graph for this function:

void gdImageSetBrush ( gdImagePtr  im,
gdImagePtr  brush 
)

Definition at line 2484 of file gd.c.

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 125 of file gd.c.

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 2472 of file gd.c.

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

Here is the caller graph for this function:

void gdImageSetTile ( gdImagePtr  im,
gdImagePtr  tile 
)

Definition at line 2510 of file gd.c.

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 467 of file gd.c.

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 478 of file gd.c.

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

Here is the call graph for this function:

Here is the caller graph for this function:

static void gdImageTileApply ( gdImagePtr  im,
int  x,
int  y 
) [static]

Definition at line 199 of file gd.c.

{
       int srcx, srcy;
       int p;
       if (!im->tile) {
              return;
       }
       srcx = x % gdImageSX(im->tile);
       srcy = y % gdImageSY(im->tile);
       p = gdImageGetPixel(im->tile, srcx, srcy);
       /* Allow for transparency */
       if (p != gdImageGetTransparent(im->tile)) {
              gdImageSetPixel(im, x, y,
                     im->tileColorMap[p]);
       }
}             

Here is the call graph for this function:

Here is the caller graph for this function:

void gdPutWord ( int  w,
FILE *  out 
)

Definition at line 2131 of file gd.c.

{
       putc((unsigned char)(w >> 8), out);
       putc((unsigned char)(w & 0xFF), out);
}

Here is the caller graph for this function:

static int GetCode ( FILE *  fd,
int  code_size,
int  flag 
) [static]

Definition at line 1720 of file gd.c.

{
       static unsigned char    buf[280];
       static int              curbit, lastbit, done, last_byte;
       int                     i, j, ret;
       unsigned char           count;

       if (flag) {
               curbit = 0;
               lastbit = 0;
               done = FALSE;
               return 0;
       }

       if ( (curbit+code_size) >= lastbit) {
               if (done) {
                       if (curbit >= lastbit) {
                                /* Oh well */
                       }                        
                       return -1;
               }
               buf[0] = buf[last_byte-2];
               buf[1] = buf[last_byte-1];

               if ((count = GetDataBlock(fd, &buf[2])) == 0)
                       done = TRUE;

               last_byte = 2 + count;
               curbit = (curbit - lastbit) + 16;
               lastbit = (2+count)*8 ;
       }

       ret = 0;
       for (i = curbit, j = 0; j < code_size; ++i, ++j)
               ret |= ((buf[ i / 8 ] & (1 << (i % 8))) != 0) << j;

       curbit += code_size;

       return ret;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int GetDataBlock ( FILE *  fd,
unsigned char *  buf 
) [static]

Definition at line 1702 of file gd.c.

{
       unsigned char   count;

       if (! ReadOK(fd,&count,1)) {
               return -1;
       }

       ZeroDataBlock = count == 0;

       if ((count != 0) && (! ReadOK(fd, buf, count))) {
               return -1;
       }

       return count;
}

Here is the caller graph for this function:

static void GIFEncode ( FILE *  fp,
int  GWidth,
int  GHeight,
int  GInterlace,
int  Background,
int  Transparent,
int  BitsPerPixel,
int *  Red,
int *  Green,
int *  Blue,
gdImagePtr  im 
) [static]

Definition at line 900 of file gd.c.

{
        int B;
        int RWidth, RHeight;
        int LeftOfs, TopOfs;
        int Resolution;
        int ColorMapSize;
        int InitCodeSize;
        int i;

        Interlace = GInterlace;

        ColorMapSize = 1 << BitsPerPixel;

        RWidth = Width = GWidth;
        RHeight = Height = GHeight;
        LeftOfs = TopOfs = 0;

        Resolution = BitsPerPixel;

        /*
         * Calculate number of bits we are expecting
         */
        CountDown = (long)Width * (long)Height;

        /*
         * Indicate which pass we are on (if interlace)
         */
        Pass = 0;

        /*
         * The initial code size
         */
        if( BitsPerPixel <= 1 )
                InitCodeSize = 2;
        else
                InitCodeSize = BitsPerPixel;

        /*
         * Set up the current x and y position
         */
        curx = cury = 0;

        /*
         * Write the Magic header
         */
        fwrite( Transparent < 0 ? "GIF87a" : "GIF89a", 1, 6, fp );

        /*
         * Write out the screen width and height
         */
        Putword( RWidth, fp );
        Putword( RHeight, fp );

        /*
         * Indicate that there is a global colour map
         */
        B = 0x80;       /* Yes, there is a color map */

        /*
         * OR in the resolution
         */
        B |= (Resolution - 1) << 5;

        /*
         * OR in the Bits per Pixel
         */
        B |= (BitsPerPixel - 1);

        /*
         * Write it out
         */
        fputc( B, fp );

        /*
         * Write out the Background colour
         */
        fputc( Background, fp );

        /*
         * Byte of 0's (future expansion)
         */
        fputc( 0, fp );

        /*
         * Write out the Global Colour Map
         */
        for( i=0; i<ColorMapSize; ++i ) {
                fputc( Red[i], fp );
                fputc( Green[i], fp );
                fputc( Blue[i], fp );
        }

       /*
        * Write out extension for transparent colour index, if necessary.
        */
       if ( Transparent >= 0 ) {
           fputc( '!', fp );
           fputc( 0xf9, fp );
           fputc( 4, fp );
           fputc( 1, fp );
           fputc( 0, fp );
           fputc( 0, fp );
           fputc( (unsigned char) Transparent, fp );
           fputc( 0, fp );
       }

        /*
         * Write an Image separator
         */
        fputc( ',', fp );

        /*
         * Write the Image header
         */

        Putword( LeftOfs, fp );
        Putword( TopOfs, fp );
        Putword( Width, fp );
        Putword( Height, fp );

        /*
         * Write out whether or not the image is interlaced
         */
        if( Interlace )
                fputc( 0x40, fp );
        else
                fputc( 0x00, fp );

        /*
         * Write out the initial code size
         */
        fputc( InitCodeSize, fp );

        /*
         * Go and actually compress the data
         */
        compress( InitCodeSize+1, fp, im );

        /*
         * Write out a Zero-length packet (to end the series)
         */
        fputc( 0, fp );

        /*
         * Write the GIF file terminator
         */
        fputc( ';', fp );
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int GIFNextPixel ( gdImagePtr  im) [static]

Definition at line 881 of file gd.c.

{
        int r;

        if( CountDown == 0 )
                return EOF;

        --CountDown;

        r = gdImageGetPixel(im, curx, cury);

        BumpPixel();

        return r;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void init_statics ( void  ) [static]

Definition at line 1444 of file gd.c.

                               {
       /* Some of these are properly initialized later. What I'm doing
              here is making sure code that depends on C's initialization
              of statics doesn't break when the code gets called more
              than once. */
       Width = 0;
       Height = 0;
       curx = 0;
       cury = 0;
       CountDown = 0;
       Pass = 0;
       Interlace = 0;
       a_count = 0;
       cur_accum = 0;
       cur_bits = 0;
       g_init_bits = 0;
       g_outfile = 0;
       ClearCode = 0;
       EOFCode = 0;
       free_ent = 0;
       clear_flg = 0;
       offset = 0;
       in_count = 1;
       out_count = 0;       
       hsize = HSIZE;
       n_bits = 0;
       maxbits = GIFBITS;
       maxcode = 0;
       maxmaxcode = (code_int)1 << GIFBITS;
}

Here is the caller graph for this function:

static int LWZReadByte ( FILE *  fd,
int  flag,
int  input_code_size 
) [static]

Definition at line 1762 of file gd.c.

{
       static int      fresh = FALSE;
       int             code, incode;
       static int      code_size, set_code_size;
       static int      max_code, max_code_size;
       static int      firstcode, oldcode;
       static int      clear_code, end_code;
       static int      table[2][(1<< MAX_LWZ_BITS)];
       static int      stack[(1<<(MAX_LWZ_BITS))*2], *sp;
       register int    i;

       if (flag) {
               set_code_size = input_code_size;
               code_size = set_code_size+1;
               clear_code = 1 << set_code_size ;
               end_code = clear_code + 1;
               max_code_size = 2*clear_code;
               max_code = clear_code+2;

               GetCode(fd, 0, TRUE);
               
               fresh = TRUE;

               for (i = 0; i < clear_code; ++i) {
                       table[0][i] = 0;
                       table[1][i] = i;
               }
               for (; i < (1<<MAX_LWZ_BITS); ++i)
                       table[0][i] = table[1][0] = 0;

               sp = stack;

               return 0;
       } else if (fresh) {
               fresh = FALSE;
               do {
                       firstcode = oldcode =
                               GetCode(fd, code_size, FALSE);
               } while (firstcode == clear_code);
               return firstcode;
       }

       if (sp > stack)
               return *--sp;

       while ((code = GetCode(fd, code_size, FALSE)) >= 0) {
               if (code == clear_code) {
                       for (i = 0; i < clear_code; ++i) {
                               table[0][i] = 0;
                               table[1][i] = i;
                       }
                       for (; i < (1<<MAX_LWZ_BITS); ++i)
                               table[0][i] = table[1][i] = 0;
                       code_size = set_code_size+1;
                       max_code_size = 2*clear_code;
                       max_code = clear_code+2;
                       sp = stack;
                       firstcode = oldcode =
                                       GetCode(fd, code_size, FALSE);
                       return firstcode;
               } else if (code == end_code) {
                       int             count;
                       unsigned char   buf[260];

                       if (ZeroDataBlock)
                               return -2;

                       while ((count = GetDataBlock(fd, buf)) > 0)
                               ;

                       if (count != 0)
                       return -2;
               }

               incode = code;

               if (code >= max_code) {
                       *sp++ = firstcode;
                       code = oldcode;
               }

               while (code >= clear_code) {
                       *sp++ = table[1][code];
                       if (code == table[0][code]) {
                               /* Oh well */
                       }
                       code = table[0][code];
               }

               *sp++ = firstcode = table[1][code];

               if ((code = max_code) <(1<<MAX_LWZ_BITS)) {
                       table[0][code] = oldcode;
                       table[1][code] = firstcode;
                       ++max_code;
                       if ((max_code >= max_code_size) &&
                               (max_code_size < (1<<MAX_LWZ_BITS))) {
                               max_code_size *= 2;
                               ++code_size;
                       }
               }

               oldcode = incode;

               if (sp > stack)
                       return *--sp;
       }
       return code;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void output ( code_int  code) [static]

Definition at line 1288 of file gd.c.

{
    cur_accum &= masks[ cur_bits ];

    if( cur_bits > 0 )
        cur_accum |= ((long)code << cur_bits);
    else
        cur_accum = code;

    cur_bits += n_bits;

    while( cur_bits >= 8 ) {
        char_out( (unsigned int)(cur_accum & 0xff) );
        cur_accum >>= 8;
        cur_bits -= 8;
    }

    /*
     * If the next entry is going to be too big for the code size,
     * then increase it, if possible.
     */
   if ( free_ent > maxcode || clear_flg ) {

            if( clear_flg ) {

                maxcode = MAXCODE (n_bits = g_init_bits);
                clear_flg = 0;

            } else {

                ++n_bits;
                if ( n_bits == maxbits )
                    maxcode = maxmaxcode;
                else
                    maxcode = MAXCODE(n_bits);
            }
        }

    if( code == EOFCode ) {
        /*
         * At EOF, write the rest of the buffer.
         */
        while( cur_bits > 0 ) {
                char_out( (unsigned int)(cur_accum & 0xff) );
                cur_accum >>= 8;
                cur_bits -= 8;
        }

        flush_char();

        fflush( g_outfile );

        if( ferror( g_outfile ) )
              return;
    }
}

Here is the call graph for this function:

static void Putword ( int  w,
FILE *  fp 
) [static]

Definition at line 1054 of file gd.c.

{
        fputc( w & 0xff, fp );
        fputc( (w / 256) & 0xff, fp );
}

Here is the caller graph for this function:

static int ReadColorMap ( FILE *  fd,
int  number,
unsigned char(*)  buffer[256] 
) [static]

Definition at line 1656 of file gd.c.

{
       int             i;
       unsigned char   rgb[3];


       for (i = 0; i < number; ++i) {
               if (! ReadOK(fd, rgb, sizeof(rgb))) {
                       return TRUE;
               }
               buffer[CM_RED][i] = rgb[0] ;
               buffer[CM_GREEN][i] = rgb[1] ;
               buffer[CM_BLUE][i] = rgb[2] ;
       }


       return FALSE;
}

Here is the caller graph for this function:

static void ReadImage ( gdImagePtr  im,
FILE *  fd,
int  len,
int  height,
unsigned char(*)  cmap[256],
int  interlace,
int  ignore 
) [static]

Definition at line 1874 of file gd.c.

{
       unsigned char   c;      
       int             v;
       int             xpos = 0, ypos = 0, pass = 0;
       int i;
       /* Stash the color map into the image */
       for (i=0; (i<gdMaxColors); i++) {
               im->red[i] = cmap[CM_RED][i];     
               im->green[i] = cmap[CM_GREEN][i]; 
               im->blue[i] = cmap[CM_BLUE][i];   
               im->open[i] = 1;
       }
       /* Many (perhaps most) of these colors will remain marked open. */
       im->colorsTotal = gdMaxColors;
       /*
       **  Initialize the Compression routines
       */
       if (! ReadOK(fd,&c,1)) {
               return; 
       }
       if (LWZReadByte(fd, TRUE, c) < 0) {
               return;
       }

       /*
       **  If this is an "uninteresting picture" ignore it.
       */
       if (ignore) {
               while (LWZReadByte(fd, FALSE, c) >= 0)
                       ;
               return;
       }

       while ((v = LWZReadByte(fd,FALSE,c)) >= 0 ) {
               /* This how we recognize which colors are actually used. */
               if (im->open[v]) {
                       im->open[v] = 0;
               }
               gdImageSetPixel(im, xpos, ypos, v);
               ++xpos;
               if (xpos == len) {
                       xpos = 0;
                       if (interlace) {
                               switch (pass) {
                               case 0:
                               case 1:
                                       ypos += 8; break;
                               case 2:
                                       ypos += 4; break;
                               case 3:
                                       ypos += 2; break;
                               }

                               if (ypos >= height) {
                                       ++pass;
                                       switch (pass) {
                                       case 1:
                                               ypos = 4; break;
                                       case 2:
                                               ypos = 2; break;
                                       case 3:
                                               ypos = 1; break;
                                       default:
                                               goto fini;
                                       }
                               }
                       } else {
                               ++ypos;
                       }
               }
               if (ypos >= height)
                       break;
       }

fini:
       if (LWZReadByte(fd,FALSE,c)>=0) {
               /* Ignore extra */
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

int a_count [static]

Definition at line 1403 of file gd.c.

char accum[256] [static]

Definition at line 1417 of file gd.c.

int clear_flg = 0 [static]

Definition at line 1138 of file gd.c.

int ClearCode [static]

Definition at line 1163 of file gd.c.

unsigned short codetab[HSIZE] [static]

Definition at line 1113 of file gd.c.

long CountDown [static]

Definition at line 817 of file gd.c.

unsigned long cur_accum = 0 [static]

Definition at line 1279 of file gd.c.

int cur_bits = 0 [static]

Definition at line 1280 of file gd.c.

int curx [static]

Definition at line 816 of file gd.c.

int cury [static]

Definition at line 816 of file gd.c.

int EOFCode [static]

Definition at line 1164 of file gd.c.

code_int free_ent = 0 [static]

Definition at line 1132 of file gd.c.

int g_init_bits [static]

Definition at line 1160 of file gd.c.

FILE* g_outfile [static]

Definition at line 1161 of file gd.c.

struct { ... } Gif89 [static]
int Height [static]

Definition at line 815 of file gd.c.

code_int hsize = HSIZE [static]

Definition at line 1117 of file gd.c.

count_int htab[HSIZE] [static]

Definition at line 1112 of file gd.c.

long int in_count = 1 [static]

Definition at line 1141 of file gd.c.

int Interlace [static]

Definition at line 819 of file gd.c.

unsigned long masks[] [static]
Initial value:
 { 0x0000, 0x0001, 0x0003, 0x0007, 0x000F,
                                  0x001F, 0x003F, 0x007F, 0x00FF,
                                  0x01FF, 0x03FF, 0x07FF, 0x0FFF,
                                  0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF }

Definition at line 1282 of file gd.c.

int maxbits = GIFBITS [static]

Definition at line 1103 of file gd.c.

code_int maxcode [static]

Definition at line 1104 of file gd.c.

code_int maxmaxcode = (code_int)1 << GIFBITS [static]

Definition at line 1105 of file gd.c.

int n_bits [static]

Definition at line 1102 of file gd.c.

int offset [static]

Definition at line 1140 of file gd.c.

long int out_count = 0 [static]

Definition at line 1142 of file gd.c.

int Pass = 0 [static]

Definition at line 818 of file gd.c.

int Width [static]

Definition at line 815 of file gd.c.

Definition at line 1533 of file gd.c.