Source

gd-libgd / src / gd_gd2.c

Diff from to

src/gd_gd2.c

    *
  */
 
-/* 2.03: gd2 is no longer mandatory */
-#ifdef HAVE_LIBZ
-
 #include <stdio.h>
 #include <errno.h>
 #include <math.h>
 #include <string.h>
 #include <stdlib.h>
-#include <zlib.h>
 #include "gd.h"
 #include "gdhelpers.h"
 
+/* 2.03: gd2 is no longer mandatory */
+/* JCE - test after including gd.h so that HAVE_LIBZ can be set in
+ * a config.h file included by gd.h */
+#ifdef HAVE_LIBZ
+#include <zlib.h>
+
 #define TRUE 1
 #define FALSE 0
 
 
   im = gdImageCreateFromGd2Ctx (in);
 
-  in->free (in);
+  in->gd_free (in);
 
   return im;
 }
   int i;
   int ncx, ncy, nc, cs, cx, cy;
   int x, y, ylo, yhi, xlo, xhi;
-  int ch, vers, fmt;
+  int vers, fmt;
   t_chunk_info *chunkIdx = NULL;	/* So we can gdFree it with impunity. */
   unsigned char *chunkBuf = NULL;	/* So we can gdFree it with impunity. */
   int chunkNum = 0;
-  int chunkMax;
+  int chunkMax = 0;
   uLongf chunkLen;
-  int chunkPos;
-  int compMax;
+  int chunkPos = 0;
+  int compMax = 0;
   int bytesPerPixel;
   char *compBuf = NULL;		/* So we can gdFree it with impunity. */
 
 
   im = gdImageCreateFromGd2PartCtx (in, srcx, srcy, w, h);
 
-  in->free (in);
+  in->gd_free (in);
 
   return im;
 }
   t_chunk_info *chunkIdx = NULL;
   char *chunkBuf = NULL;
   int chunkNum;
-  int chunkMax;
+  int chunkMax = 0;
   uLongf chunkLen;
-  int chunkPos;
+  int chunkPos = 0;
   int compMax;
   char *compBuf = NULL;
 
 		    {
 		      if (im->trueColor)
 			{
-			  ch = chunkBuf[chunkPos++] << 24 +
-			    chunkBuf[chunkPos++] << 16 +
-			    chunkBuf[chunkPos++] << 8 +
-			    chunkBuf[chunkPos++];
+                          ch = chunkBuf[chunkPos++];
+                          ch = (ch << 8) + chunkBuf[chunkPos++];
+                          ch = (ch << 8) + chunkBuf[chunkPos++];
+                          ch = (ch << 8) + chunkBuf[chunkPos++];
 			}
 		      else
 			{
   char *chunkData = NULL;	/* So we can gdFree it with impunity. */
   char *compData = NULL;	/* So we can gdFree it with impunity. */
   uLongf compLen;
-  int idxPos;
+  int idxPos = 0;
   int idxSize;
   t_chunk_info *chunkIdx = NULL;
   int posSave;
   int bytesPerPixel = im->trueColor ? 4 : 1;
-  int compMax;
+  int compMax = 0;
 
   /*printf("Trying to write GD2 file\n"); */
 
 {
   gdIOCtx *out = gdNewFileCtx (outFile);
   _gdImageGd2 (im, out, cs, fmt);
-  out->free (out);
+  out->gd_free (out);
 }
 
 void *
   gdIOCtx *out = gdNewDynamicCtx (2048, NULL);
   _gdImageGd2 (im, out, cs, fmt);
   rv = gdDPExtractData (out, size);
-  out->free (out);
+  out->gd_free (out);
   return rv;
 }
 
+#else /* no HAVE_LIBZ */
+gdImagePtr
+gdImageCreateFromGd2 (FILE * inFile)
+{
+  fprintf(stderr,"GD2 support is not available - no libz\n");
+  return NULL;
+}
+gdImagePtr
+gdImageCreateFromGd2Ctx (gdIOCtxPtr in)
+{
+  fprintf(stderr,"GD2 support is not available - no libz\n");
+  return NULL;
+}
 #endif /* HAVE_LIBZ */