Diff for /loncom/cgi/mimeTeX/gifsave.c between versions 1.1 and 1.2

version 1.1, 2005/02/28 19:08:11 version 1.2, 2006/03/24 23:08:33
Line 20 Line 20
 #include <string.h> /* " */  #include <string.h> /* " */
 /* --- windows-specific header info --- */  /* --- windows-specific header info --- */
 #ifndef WINDOWS /* -DWINDOWS not supplied by user */  #ifndef WINDOWS /* -DWINDOWS not supplied by user */
   #if defined(_WIN32) /* try to recognize windows environments */    #if defined(_WINDOWS) || defined(_WIN32) || defined(WIN32) \
     ||  defined(DJGPP) /* try to recognize windows compilers */ \
     ||  defined(_USRDLL) /* must be WINDOWS if compiling for DLL */
     #define WINDOWS /* signal windows */      #define WINDOWS /* signal windows */
   #endif    #endif
 #endif  #endif
Line 67  typedef unsigned char Byte;     /* exact Line 69  typedef unsigned char Byte;     /* exact
   
 /* used by IO-routines */  /* used by IO-routines */
 static FILE *OutFile = NULL;    /* file to write to */  static FILE *OutFile = NULL;    /* file to write to */
 static int isCloseOutFile = 0; /* (added by j.forkosh) */  static Byte *OutBuffer = NULL; /* (added by j.forkosh) */
   static int isCloseOutFile = 0; /* " */
   int gifSize = 0; /* " #bytes comprising gif */
   int maxgifSize = 64000; /* " max #bytes written to OutBuffer */
   
 /* used when writing to a file bitwise */  /* used when writing to a file bitwise */
 static Byte Buffer[256];        /* there must be one more than `needed' */  static Byte Buffer[256];        /* there must be one more than `needed' */
Line 154  static int  (*GetPixel)(int x, int y); Line 159  static int  (*GetPixel)(int x, int y);
  *                rewrite file IO.   *                rewrite file IO.
  *   *
  *  INPUT         filename   *  INPUT         filename
  *                        name of file to create   *                        name of file to create,
    *                        or NULL for stdout,
    *                        or if *filename='\000' then it's the address of
    *                           a memory buffer to which gif will be written
  *   *
  *  RETURNS       GIF_OK       - OK   *  RETURNS       GIF_OK       - OK
  *                GIF_ERRWRITE - Error opening the file   *                GIF_ERRWRITE - Error opening the file
Line 162  static int  (*GetPixel)(int x, int y); Line 170  static int  (*GetPixel)(int x, int y);
 static int  static int
 Create(const char *filename)  Create(const char *filename)
 {  {
     if ( filename == NULL ) /* (added by j.forkosh) */      OutBuffer = NULL; /* (added by j.forkosh) */
       isCloseOutFile = 0; /* " */
       gifSize = 0; /* " */
       if ( filename == NULL ) /* " */
       { OutFile = stdout; /* " */        { OutFile = stdout; /* " */
  /*OutFile = fdopen(STDOUT_FILENO,"wb");*/ /* " doesn't work, */   /*OutFile = fdopen(STDOUT_FILENO,"wb");*/ /* " doesn't work, */
  #ifdef WINDOWS /* "   so instead... */   #ifdef WINDOWS /* "   so instead... */
Line 179  Create(const char *filename) Line 190  Create(const char *filename)
  #endif /* " */   #endif /* " */
       } /* " */        } /* " */
     else /* " */      else /* " */
       { if ((OutFile = fopen(filename, "wb")) == NULL)        if ( *filename != '\000' ) /* " */
   return GIF_ERRCREATE;   { if ((OutFile = fopen(filename, "wb")) == NULL)
  isCloseOutFile = 1; } /* (added by j.forkosh) */      return GIF_ERRCREATE;
     isCloseOutFile = 1; } /* (added by j.forkosh) */
         else /* " */
    OutBuffer = (Byte *)filename; /* " */
     return GIF_OK;      return GIF_OK;
 }  }
   
Line 202  Create(const char *filename) Line 216  Create(const char *filename)
 static int  static int
 Write(const void *buf, unsigned len)  Write(const void *buf, unsigned len)
 {  {
     if (fwrite(buf, sizeof(Byte), len, OutFile) < len)      if ( OutBuffer == NULL ) /* (added by j.forkosh) */
         return GIF_ERRWRITE;        { if (fwrite(buf, sizeof(Byte), len, OutFile) < len)
     return GIF_ERRWRITE; }
       else /* (added by j.forkosh) */
         { if ( gifSize+len <= maxgifSize ) /* " */
     memcpy(OutBuffer+gifSize,buf,len); } /* " */
       gifSize += len; /* " */
     return GIF_OK;      return GIF_OK;
 }  }
   
Line 223  Write(const void *buf, unsigned len) Line 242  Write(const void *buf, unsigned len)
 static int  static int
 WriteByte(Byte b)  WriteByte(Byte b)
 {  {
     if (putc(b, OutFile) == EOF)      if ( OutBuffer == NULL ) /* (added by j.forkosh) */
         return GIF_ERRWRITE;        { if (putc(b, OutFile) == EOF)
     return GIF_ERRWRITE; }
       else /* (added by j.forkosh) */
         { if ( gifSize < maxgifSize ) /* " */
     OutBuffer[gifSize] = b; } /* " */
       gifSize++; /* " */
     return GIF_OK;      return GIF_OK;
 }  }
   
Line 245  WriteByte(Byte b) Line 269  WriteByte(Byte b)
 static int  static int
 WriteWord(Word w)  WriteWord(Word w)
 {  {
     if (putc(w & 0xFF, OutFile) == EOF)      if ( OutBuffer == NULL ) /* (added by j.forkosh) */
         return GIF_ERRWRITE;        { if (putc(w & 0xFF, OutFile) == EOF)
     if (putc((w >> 8), OutFile) == EOF)    return GIF_ERRWRITE;
         return GIF_ERRWRITE;   if (putc((w >> 8), OutFile) == EOF)
     return GIF_ERRWRITE; }
       else /* (added by j.forkosh) */
         if ( gifSize+1 < maxgifSize ) /* " */
    { OutBuffer[gifSize] = (Byte)(w & 0xFF);  /* " */
     OutBuffer[gifSize+1] = (Byte)(w >> 8); }  /* " */
       gifSize += 2; /* " */
     return GIF_OK;      return GIF_OK;
 }  }
   
Line 265  Close(void) Line 295  Close(void)
 {  {
     if ( isCloseOutFile ) /* (added by j.forkosh) */      if ( isCloseOutFile ) /* (added by j.forkosh) */
       fclose(OutFile);        fclose(OutFile);
       OutBuffer = NULL; /* (added by j.forkosh) */
       isCloseOutFile = 0; /* " */
 }  }
   
   

Removed from v.1.1  
changed lines
  Added in v.1.2


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>