summaryrefslogtreecommitdiff
path: root/src/gd_gd2.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gd_gd2.c')
-rw-r--r--src/gd_gd2.c55
1 files changed, 35 insertions, 20 deletions
diff --git a/src/gd_gd2.c b/src/gd_gd2.c
index 26e87c8..3adbe50 100644
--- a/src/gd_gd2.c
+++ b/src/gd_gd2.c
@@ -10,18 +10,20 @@
*
*/
-/* 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
@@ -253,7 +255,7 @@ gdImageCreateFromGd2 (FILE * inFile)
im = gdImageCreateFromGd2Ctx (in);
- in->free (in);
+ in->gd_free (in);
return im;
}
@@ -265,14 +267,14 @@ gdImageCreateFromGd2Ctx (gdIOCtxPtr in)
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. */
@@ -436,7 +438,7 @@ gdImageCreateFromGd2Part (FILE * inFile, int srcx, int srcy, int w, int h)
im = gdImageCreateFromGd2PartCtx (in, srcx, srcy, w, h);
- in->free (in);
+ in->gd_free (in);
return im;
}
@@ -453,9 +455,9 @@ gdImageCreateFromGd2PartCtx (gdIOCtx * in, int srcx, int srcy, int w, int h)
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;
@@ -638,10 +640,10 @@ gdImageCreateFromGd2PartCtx (gdIOCtx * in, int srcx, int srcy, int w, int h)
{
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
{
@@ -713,12 +715,12 @@ _gdImageGd2 (gdImagePtr im, gdIOCtx * out, int cs, int fmt)
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"); */
@@ -911,7 +913,7 @@ gdImageGd2 (gdImagePtr im, FILE * outFile, int cs, int fmt)
{
gdIOCtx *out = gdNewFileCtx (outFile);
_gdImageGd2 (im, out, cs, fmt);
- out->free (out);
+ out->gd_free (out);
}
void *
@@ -921,9 +923,22 @@ gdImageGd2Ptr (gdImagePtr im, int cs, int fmt, int *size)
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 */