static int gdAlphaOverlayColor(int src, int dst, int max);
static int gdImageGetTrueColorPixel(gdImagePtr im, int x, int y);
+void php_gd_error_ex(int type, const char *format, ...)
+{
+ va_list args;
+
+ TSRMLS_FETCH();
+
+ va_start(args, format);
+ php_verror(NULL, "", type, format, args TSRMLS_CC);
+ va_end(args);
+}
+
+void php_gd_error(const char *format, ...)
+{
+ va_list args;
+
+ TSRMLS_FETCH();
+
+ va_start(args, format);
+ php_verror(NULL, "", E_WARNING, format, args TSRMLS_CC);
+ va_end(args);
+}
+
gdImagePtr
gdImageCreate (int sx, int sy)
{
}
}
/* Shouldn't happen */
- fprintf (stderr, "Error: bug in gdImageCreateFromXbm!\n");
+ php_gd_error("Error: bug in gdImageCreateFromXbm\n");
return 0;
fail:
gdImageDestroy (im);
#include <stdio.h>
#include "gd_io.h"
+void php_gd_error_ex(int type, const char *format, ...);
+
+void php_gd_error(const char *format, ...);
+
+
/* The maximum number of palette entries in palette-based images.
In the wonderful new world of gd 2.0, you can of course have
many more colors when using truecolor mode. */
out = fopen ("test/arctest.png", "wb");
if (!out)
{
- fprintf (stderr, "Can't create test/arctest.png\n");
+ php_gd_error("Can't create test/arctest.png\n");
exit (1);
}
gdImagePng (im, out);
fclose (out);
- fprintf (stderr, "Test image written to test/arctest.png\n");
+ php_gd_error("Test image written to test/arctest.png\n");
/* Destroy it */
gdImageDestroy (im);
/* Use this for commenting out debug-print statements. */
/* Just use the first '#define' to allow all the prints... */
-/*#define GD2_DBG(s) (s) */
-#define GD2_DBG(s)
+#define GD2_DBG(s) (s)
+//#define GD2_DBG(s)
typedef struct
{
int sidx;
int nc;
- GD2_DBG (printf ("Reading gd2 header info\n"));
+ GD2_DBG(php_gd_error("Reading gd2 header info\n"));
for (i = 0; i < 4; i++)
{
};
id[4] = 0;
- GD2_DBG (printf ("Got file code: %s\n", id));
+ GD2_DBG(php_gd_error("Got file code: %s\n", id));
/* Equiv. of 'magick'. */
if (strcmp (id, GD2_ID) != 0)
{
- GD2_DBG (printf ("Not a valid gd2 file\n"));
+ GD2_DBG(php_gd_error("Not a valid gd2 file\n"));
goto fail1;
};
{
goto fail1;
};
- GD2_DBG (printf ("Version: %d\n", *vers));
+ GD2_DBG(php_gd_error("Version: %d\n", *vers));
if ((*vers != 1) && (*vers != 2))
{
- GD2_DBG (printf ("Bad version: %d\n", *vers));
+ GD2_DBG(php_gd_error("Bad version: %d\n", *vers));
goto fail1;
};
/* Image Size */
if (!gdGetWord (sx, in))
{
- GD2_DBG (printf ("Could not get x-size\n"));
+ GD2_DBG(php_gd_error("Could not get x-size\n"));
goto fail1;
}
if (!gdGetWord (sy, in))
{
- GD2_DBG (printf ("Could not get y-size\n"));
+ GD2_DBG(php_gd_error("Could not get y-size\n"));
goto fail1;
}
- GD2_DBG (printf ("Image is %dx%d\n", *sx, *sy));
+ GD2_DBG(php_gd_error("Image is %dx%d\n", *sx, *sy));
/* Chunk Size (pixels, not bytes!) */
if (gdGetWord (cs, in) != 1)
{
goto fail1;
};
- GD2_DBG (printf ("ChunkSize: %d\n", *cs));
+ GD2_DBG(php_gd_error("ChunkSize: %d\n", *cs));
if ((*cs < GD2_CHUNKSIZE_MIN) || (*cs > GD2_CHUNKSIZE_MAX))
{
- GD2_DBG (printf ("Bad chunk size: %d\n", *cs));
+ GD2_DBG(php_gd_error("Bad chunk size: %d\n", *cs));
goto fail1;
};
{
goto fail1;
};
- GD2_DBG (printf ("Format: %d\n", *fmt));
+ GD2_DBG(php_gd_error("Format: %d\n", *fmt));
if ((*fmt != GD2_FMT_RAW) && (*fmt != GD2_FMT_COMPRESSED))
{
- GD2_DBG (printf ("Bad data format: %d\n", *fmt));
+ GD2_DBG(php_gd_error("Bad data format: %d\n", *fmt));
goto fail1;
};
{
goto fail1;
};
- GD2_DBG (printf ("%d Chunks Wide\n", *ncx));
+ GD2_DBG(php_gd_error("%d Chunks Wide\n", *ncx));
/* # of chunks high */
if (gdGetWord (ncy, in) != 1)
{
goto fail1;
};
- GD2_DBG (printf ("%d Chunks vertically\n", *ncy));
+ GD2_DBG(php_gd_error("%d Chunks vertically\n", *ncy));
if ((*fmt) == GD2_FMT_COMPRESSED)
{
nc = (*ncx) * (*ncy);
- GD2_DBG (printf ("Reading %d chunk index entries\n", nc));
+ GD2_DBG(php_gd_error("Reading %d chunk index entries\n", nc));
sidx = sizeof (t_chunk_info) * nc;
cidx = gdCalloc (sidx, 1);
for (i = 0; i < nc; i++)
*chunkIdx = cidx;
};
- GD2_DBG (printf ("gd2 header complete\n"));
+ GD2_DBG(php_gd_error("gd2 header complete\n"));
return 1;
if (_gd2GetHeader (in, sx, sy, cs, vers, fmt, ncx, ncy, cidx) != 1)
{
- GD2_DBG (printf ("Bad GD2 header\n"));
+ GD2_DBG(php_gd_error("Bad GD2 header\n"));
goto fail1;
}
im = gdImageCreate (*sx, *sy);
if (im == NULL)
{
- GD2_DBG (printf ("Could not create gdImage\n"));
+ GD2_DBG(php_gd_error("Could not create gdImage\n"));
goto fail1;
};
if (!_gdGetColors (in, im, (*vers) == 2))
{
- GD2_DBG (printf ("Could not read color palette\n"));
+ GD2_DBG(php_gd_error("Could not read color palette\n"));
goto fail2;
}
- GD2_DBG (printf ("Image palette completed: %d colours\n", im->colorsTotal));
+ GD2_DBG(php_gd_error("Image palette completed: %d colours\n", im->colorsTotal));
return im;
if (gdTell (in) != offset)
{
- GD2_DBG (printf ("Positioning in file to %d\n", offset));
+ GD2_DBG(php_gd_error("Positioning in file to %d\n", offset));
gdSeek (in, offset);
}
else
{
- GD2_DBG (printf ("Already Positioned in file to %d\n", offset));
+ GD2_DBG(php_gd_error("Already Positioned in file to %d\n", offset));
};
/* Read and uncompress an entire chunk. */
- GD2_DBG (printf ("Reading file\n"));
+ GD2_DBG(php_gd_error("Reading file\n"));
if (gdGetBuf (compBuf, compSize, in) != compSize)
{
return FALSE;
};
- GD2_DBG (printf ("Got %d bytes. Uncompressing into buffer of %d bytes\n", compSize, *chunkLen));
+ GD2_DBG(php_gd_error("Got %d bytes. Uncompressing into buffer of %d bytes\n", compSize, (int)*chunkLen));
zerr = uncompress ((unsigned char *) chunkBuf, chunkLen,
(unsigned char *) compBuf, compSize);
if (zerr != Z_OK)
{
- GD2_DBG (printf ("Error %d from uncompress\n", zerr));
+ GD2_DBG(php_gd_error("Error %d from uncompress\n", zerr));
return FALSE;
};
- GD2_DBG (printf ("Got chunk\n"));
+ GD2_DBG(php_gd_error("Got chunk\n"));
return TRUE;
}
chunkMax = cs * bytesPerPixel * cs;
chunkBuf = gdCalloc (chunkMax, 1);
compBuf = gdCalloc (compMax, 1);
- GD2_DBG (printf ("Largest compressed chunk is %d bytes\n", compMax));
+ GD2_DBG(php_gd_error("Largest compressed chunk is %d bytes\n", compMax));
};
/* if ( (ncx != sx / cs) || (ncy != sy / cs)) { */
yhi = im->sy;
};
- GD2_DBG (printf ("Processing Chunk %d (%d, %d), y from %d to %d\n", chunkNum, cx, cy, ylo, yhi));
+ GD2_DBG(php_gd_error("Processing Chunk %d (%d, %d), y from %d to %d\n", chunkNum, cx, cy, ylo, yhi));
if (fmt == GD2_FMT_COMPRESSED)
{
chunkIdx[chunkNum].size,
chunkBuf, &chunkLen, in))
{
- GD2_DBG (printf ("Error reading comproessed chunk\n"));
+ GD2_DBG(php_gd_error("Error reading comproessed chunk\n"));
goto fail2;
};
{
xhi = im->sx;
};
- /*GD2_DBG(printf("y=%d: ",y)); */
+ /*GD2_DBG(php_gd_error("y=%d: ",y)); */
if (fmt == GD2_FMT_RAW)
{
for (x = xlo; x < xhi; x++)
{
if (!gdGetInt (&im->tpixels[y][x], in))
{
- /*printf("EOF while reading\n"); */
+ /*php_gd_error("EOF while reading\n"); */
/*gdImageDestroy(im); */
/*return 0; */
im->tpixels[y][x] = 0;
int ch;
if (!gdGetByte (&ch, in))
{
- /*printf("EOF while reading\n"); */
+ /*php_gd_error("EOF while reading\n"); */
/*gdImageDestroy(im); */
/*return 0; */
ch = 0;
}
};
};
- /*GD2_DBG(printf("\n")); */
+ /*GD2_DBG(php_gd_error("\n")); */
};
chunkNum++;
};
};
- GD2_DBG (printf ("Freeing memory\n"));
+ GD2_DBG(php_gd_error("Freeing memory\n"));
gdFree (chunkBuf);
gdFree (compBuf);
gdFree (chunkIdx);
- GD2_DBG (printf ("Done\n"));
+ GD2_DBG(php_gd_error("Done\n"));
return im;
goto fail1;
}
- GD2_DBG (printf ("File size is %dx%d\n", fsx, fsy));
+ GD2_DBG(php_gd_error("File size is %dx%d\n", fsx, fsy));
/* This is the difference - make a file based on size of chunks. */
im = gdImageCreate (w, h);
{
goto fail2;
}
- GD2_DBG (printf ("Image palette completed: %d colours\n", im->colorsTotal));
+ GD2_DBG(php_gd_error("Image palette completed: %d colours\n", im->colorsTotal));
/* Process the header info */
nc = ncx * ncy;
/* Remember file position of image data. */
dstart = gdTell (in);
- GD2_DBG (printf ("Data starts at %d\n", dstart));
+ GD2_DBG(php_gd_error("Data starts at %d\n", dstart));
/* Loop through the chunks. */
for (cy = scy; (cy <= ecy); cy++)
xhi = fsx;
};
- GD2_DBG (printf ("Processing Chunk (%d, %d), from %d to %d\n", cx, cy, ylo, yhi));
+ GD2_DBG(php_gd_error("Processing Chunk (%d, %d), from %d to %d\n", cx, cy, ylo, yhi));
if (fmt == GD2_FMT_RAW)
{
- GD2_DBG (printf ("Using raw format data\n"));
+ GD2_DBG(php_gd_error("Using raw format data\n"));
if (im->trueColor)
{
dpos = (cy * (cs * fsx) + cx * cs * (yhi - ylo) * 4) + dstart;
if (gdSeek (in, dpos) != 0)
{
- printf ("Error from seek: %d\n", errno);
+ php_gd_error_ex(E_WARNING, "Error from seek: %d\n", errno);
goto fail2;
};
- GD2_DBG (printf ("Reading (%d, %d) from position %d\n", cx, cy, dpos - dstart));
+ GD2_DBG(php_gd_error("Reading (%d, %d) from position %d\n", cx, cy, dpos - dstart));
}
else
{
chunkIdx[chunkNum].size,
chunkBuf, &chunkLen, in))
{
- printf ("Error reading comproessed chunk\n");
+ php_gd_error("Error reading comproessed chunk\n");
goto fail2;
};
chunkPos = 0;
- GD2_DBG (printf ("Reading (%d, %d) from chunk %d\n", cx, cy, chunkNum));
+ GD2_DBG(php_gd_error("Reading (%d, %d) from chunk %d\n", cx, cy, chunkNum));
};
- GD2_DBG (printf (" into (%d, %d) - (%d, %d)\n", xlo, ylo, xhi, yhi));
+ GD2_DBG(php_gd_error(" into (%d, %d) - (%d, %d)\n", xlo, ylo, xhi, yhi));
for (y = ylo; (y < yhi); y++)
{
if (!gdGetInt (&ch, in))
{
ch = 0;
- /*printf("EOF while reading file\n"); */
+ /*php_gd_error("EOF while reading file\n"); */
/*goto fail2; */
}
}
if (ch == EOF)
{
ch = 0;
- /*printf("EOF while reading file\n"); */
+ /*php_gd_error("EOF while reading file\n"); */
/*goto fail2; */
}
}
int bytesPerPixel = im->trueColor ? 4 : 1;
int compMax = 0;
- /*printf("Trying to write GD2 file\n"); */
+ /*php_gd_error("Trying to write GD2 file\n"); */
/* */
/* Force fmt to a valid value since we don't return anything. */
/* */
idxPos = gdTell (out);
idxSize = ncx * ncy * sizeof (t_chunk_info);
- GD2_DBG (printf ("Index size is %d\n", idxSize));
+ GD2_DBG(php_gd_error("Index size is %d\n", idxSize));
gdSeek (out, idxPos + idxSize);
chunkIdx = gdCalloc (idxSize * sizeof (t_chunk_info), 1);
_gdPutColors (im, out);
- GD2_DBG (printf ("Size: %dx%d\n", im->sx, im->sy));
- GD2_DBG (printf ("Chunks: %dx%d\n", ncx, ncy));
+ GD2_DBG(php_gd_error("Size: %dx%d\n", im->sx, im->sy));
+ GD2_DBG(php_gd_error("Chunks: %dx%d\n", ncx, ncy));
for (cy = 0; (cy < ncy); cy++)
{
yhi = im->sy;
};
- GD2_DBG (printf ("Processing Chunk (%dx%d), y from %d to %d\n", cx, cy, ylo, yhi));
+ GD2_DBG(php_gd_error("Processing Chunk (%dx%d), y from %d to %d\n", cx, cy, ylo, yhi));
chunkLen = 0;
for (y = ylo; (y < yhi); y++)
{
- /*GD2_DBG(printf("y=%d: ",y)); */
+ GD2_DBG(php_gd_error("y=%d: ",y));
xlo = cx * cs;
xhi = xlo + cs;
for (x = xlo; x < xhi; x++)
{
int p = im->pixels[y][x];
- /*GD2_DBG(printf("%d...",x)); */
+ GD2_DBG(php_gd_error("%d...",x));
if (im->trueColor)
{
chunkData[chunkLen++] = gdTrueColorGetAlpha (p);
{
for (x = xlo; x < xhi; x++)
{
- /*GD2_DBG(printf("%d, ",x)); */
+ GD2_DBG(php_gd_error("%d, ",x));
if (im->trueColor)
{
}
};
};
- /*GD2_DBG(printf("y=%d done.\n",y)); */
+ GD2_DBG(php_gd_error("y=%d done.\n",y));
};
if (fmt == GD2_FMT_COMPRESSED)
{
(unsigned char *) &chunkData[0],
chunkLen) != Z_OK)
{
- printf ("Error from compressing\n");
+ php_gd_error ("Error from compressing\n");
}
else
{
chunkIdx[chunkNum].offset = gdTell (out);
chunkIdx[chunkNum++].size = compLen;
- GD2_DBG (printf ("Chunk %d size %d offset %d\n", chunkNum, chunkIdx[chunkNum - 1].size, chunkIdx[chunkNum - 1].offset));
+ GD2_DBG(php_gd_error("Chunk %d size %d offset %d\n", chunkNum, chunkIdx[chunkNum - 1].size, chunkIdx[chunkNum - 1].offset));
if (gdPutBuf (compData, compLen, out) <= 0)
{
/* Any alternate suggestions for handling this? */
- printf ("Error %d on write\n", errno);
+ php_gd_error_ex (E_WARNING, "Error %d on write\n", errno);
};
};
};
if (fmt == GD2_FMT_COMPRESSED)
{
/* Save the position, write the index, restore position (paranoia). */
- GD2_DBG (printf ("Seeking %d to write index\n", idxPos));
+ GD2_DBG(php_gd_error("Seeking %d to write index\n", idxPos));
posSave = gdTell (out);
gdSeek (out, idxPos);
- GD2_DBG (printf ("Writing index\n"));
+ GD2_DBG(php_gd_error("Writing index\n"));
for (x = 0; x < chunkNum; x++)
{
- GD2_DBG (printf ("Chunk %d size %d offset %d\n", x, chunkIdx[x].size, chunkIdx[x].offset));
+ GD2_DBG(php_gd_error("Chunk %d size %d offset %d\n", x, chunkIdx[x].size, chunkIdx[x].offset));
gdPutInt (chunkIdx[x].offset, out);
gdPutInt (chunkIdx[x].size, out);
};
gdSeek (out, posSave);
};
- GD2_DBG (printf ("Freeing memory\n"));
+ GD2_DBG(php_gd_error("Freeing memory\n"));
gdFree (chunkData);
gdFree (compData);
gdFree (chunkIdx);
- GD2_DBG (printf ("Done\n"));
+ GD2_DBG(php_gd_error("Done\n"));
- /*printf("Memory block size is %d\n",gdTell(out)); */
+ /*php_gd_error("Memory block size is %d\n",gdTell(out)); */
}
#include <stdlib.h>
#include "gd.h"
+#include "php.h"
+
/* Used only when debugging GIF compression code */
/* #define DEBUGGING_ENVARS */
static int
GetDataBlock(gdIOCtx *fd, unsigned char *buf)
{
- int rv;
- int i;
-
- rv = GetDataBlock_(fd,buf);
- if (VERBOSE)
- { printf("[GetDataBlock returning %d",rv);
- if (rv > 0)
- { printf(":");
- for (i=0;i<rv;i++) printf(" %02x",buf[i]);
- }
- printf("]\n");
- }
- return(rv);
+ int rv;
+ int i;
+ char *tmp = NULL;
+
+ rv = GetDataBlock_(fd,buf);
+ if (VERBOSE) {
+ if (rv > 0) {
+ tmp = emalloc((3*sizeof(char)*rv) + 1);
+ for (i=0;i<rv;i++) {
+ sprintf(&tmp[3*sizeof(char)*i], " %02x", buf[i]);
+ }
+ } else {
+ tmp = estrdup("");
+ }
+ php_gd_error_ex(E_NOTICE, "[GetDataBlock returning %d: %s]", rv, tmp);
+ efree(tmp);
+ }
+ return(rv);
}
static int
int rv;
rv = GetCode_(fd,code_size,flag);
- if (VERBOSE) printf("[GetCode(,%d,%d) returning %d]\n",code_size,flag,rv);
+ if (VERBOSE) php_gd_error_ex(E_NOTICE, "[GetCode(,%d,%d) returning %d]\n",code_size,flag,rv);
return(rv);
}
int rv;
rv = LWZReadByte_(fd,flag,input_code_size);
- if (VERBOSE) printf("[LWZReadByte(,%d,%d) returning %d]\n",flag,input_code_size,rv);
+ if (VERBOSE) php_gd_error_ex(E_NOTICE, "[LWZReadByte(,%d,%d) returning %d]\n",flag,input_code_size,rv);
return(rv);
}
{
jmpbuf_wrapper *jmpbufw;
- fprintf (stderr, "gd-jpeg: JPEG library reports unrecoverable error: ");
+ php_gd_error("gd-jpeg: JPEG library reports unrecoverable error: ");
(*cinfo->err->output_message) (cinfo);
- fflush (stderr);
jmpbufw = (jmpbuf_wrapper *) cinfo->client_data;
jpeg_destroy (cinfo);
if (jmpbufw != 0)
{
longjmp (jmpbufw->jmpbuf, 1);
- fprintf (stderr, "gd-jpeg: EXTREMELY fatal error: longjmp"
+ php_gd_error_ex(E_ERROR, "gd-jpeg: EXTREMELY fatal error: longjmp"
" returned control; terminating\n");
}
else
{
- fprintf (stderr, "gd-jpeg: EXTREMELY fatal error: jmpbuf"
+ php_gd_error_ex(E_ERROR, "gd-jpeg: EXTREMELY fatal error: jmpbuf"
" unrecoverable; terminating\n");
}
- fflush (stderr);
exit (99);
}
* sizeof (JSAMPLE));
if (row == 0)
{
- fprintf (stderr, "gd-jpeg: error: unable to allocate JPEG row "
+ php_gd_error("gd-jpeg: error: unable to allocate JPEG row "
"structure: gdCalloc returns NULL\n");
jpeg_destroy_compress (&cinfo);
return;
if (im->trueColor)
{
#if BITS_IN_JSAMPLE == 12
- fprintf (stderr, "gd-jpeg: error: jpeg library was compiled for 12-bit\n"
+ php_gd_error("gd-jpeg: error: jpeg library was compiled for 12-bit\n"
"precision. This is mostly useless, because JPEGs on the web are\n"
"8-bit and such versions of the jpeg library won't read or write\n"
"them. GD doesn't support these unusual images. Edit your\n"
nlines = jpeg_write_scanlines (&cinfo, rowptr, 1);
if (nlines != 1)
- fprintf (stderr, "gd_jpeg: warning: jpeg_write_scanlines"
+ php_gd_error_ex(E_WARNING, "gd_jpeg: warning: jpeg_write_scanlines"
" returns %u -- expected 1\n", nlines);
}
}
nlines = jpeg_write_scanlines (&cinfo, rowptr, 1);
if (nlines != 1)
- fprintf (stderr, "gd_jpeg: warning: jpeg_write_scanlines"
+ php_gd_error_ex(E_WARNING, "gd_jpeg: warning: jpeg_write_scanlines"
" returns %u -- expected 1\n", nlines);
}
}
retval = jpeg_read_header (&cinfo, TRUE);
if (retval != JPEG_HEADER_OK)
- fprintf (stderr, "gd-jpeg: warning: jpeg_read_header returns"
+ php_gd_error_ex(E_WARNING, "gd-jpeg: warning: jpeg_read_header returns"
" %d, expected %d\n", retval, JPEG_HEADER_OK);
if (cinfo.image_height > INT_MAX)
- fprintf (stderr, "gd-jpeg: warning: JPEG image height (%u) is"
+ php_gd_error_ex(E_WARNING, "gd-jpeg: warning: JPEG image height (%u) is"
" greater than INT_MAX (%d) (and thus greater than"
" gd can handle)", cinfo.image_height,
INT_MAX);
if (cinfo.image_width > INT_MAX)
- fprintf (stderr, "gd-jpeg: warning: JPEG image width (%u) is"
+ php_gd_error_ex(E_WARNING, "gd-jpeg: warning: JPEG image width (%u) is"
" greater than INT_MAX (%d) (and thus greater than"
" gd can handle)\n", cinfo.image_width, INT_MAX);
(int) cinfo.image_height);
if (im == 0)
{
- fprintf (stderr, "gd-jpeg error: cannot allocate gdImage"
+ php_gd_error("gd-jpeg error: cannot allocate gdImage"
" struct\n");
goto error;
}
cinfo.out_color_space = JCS_RGB;
if (jpeg_start_decompress (&cinfo) != TRUE)
- fprintf (stderr, "gd-jpeg: warning: jpeg_start_decompress"
+ php_gd_error("gd-jpeg: warning: jpeg_start_decompress"
" reports suspended data source\n");
#ifdef JPEG_DEBUG
#endif
if (cinfo.output_components != 3)
{
- fprintf (stderr, "gd-jpeg: error: JPEG color quantization"
+ php_gd_error_ex(E_WARNING, "gd-jpeg: error: JPEG color quantization"
" request resulted in output_components == %d"
" (expected 3)\n", cinfo.output_components);
goto error;
}
#if BITS_IN_JSAMPLE == 12
- fprintf (stderr, "gd-jpeg: error: jpeg library was compiled for 12-bit\n"
+ php_gd_error("gd-jpeg: error: jpeg library was compiled for 12-bit\n"
"precision. This is mostly useless, because JPEGs on the web are\n"
"8-bit and such versions of the jpeg library won't read or write\n"
"them. GD doesn't support these unusual images. Edit your\n"
row = gdCalloc (cinfo.output_width * 3, sizeof (JSAMPLE));
if (row == 0)
{
- fprintf (stderr, "gd-jpeg: error: unable to allocate row for"
+ php_gd_error("gd-jpeg: error: unable to allocate row for"
" JPEG scanline: gdCalloc returns NULL\n");
goto error;
}
nrows = jpeg_read_scanlines (&cinfo, rowptr, 1);
if (nrows != 1)
{
- fprintf (stderr, "gd-jpeg: error: jpeg_read_scanlines"
+ php_gd_error_ex(E_WARNING, "gd-jpeg: error: jpeg_read_scanlines"
" returns %u, expected 1\n", nrows);
goto error;
}
}
if (jpeg_finish_decompress (&cinfo) != TRUE)
- fprintf (stderr, "gd-jpeg: warning: jpeg_finish_decompress"
+ php_gd_error("gd-jpeg: warning: jpeg_finish_decompress"
" reports suspended data source\n");
* regardless of whether _BSD_SOURCE or anything else has (or has not)
* been defined. */
- fprintf (stderr, "gd-png: fatal libpng error: %s\n", msg);
- fflush (stderr);
+ php_gd_error_ex(E_ERROR, "gd-png: fatal libpng error: %s\n", msg);
jmpbuf_ptr = png_get_error_ptr (png_ptr);
if (jmpbuf_ptr == NULL)
{ /* we are completely hosed now */
- fprintf (stderr,
- "gd-png: EXTREMELY fatal error: jmpbuf unrecoverable; terminating.\n");
- fflush (stderr);
+ php_gd_error_ex(E_ERROR, "gd-png: EXTREMELY fatal error: jmpbuf unrecoverable; terminating.\n");
exit (99);
}
#endif
if (png_ptr == NULL)
{
- fprintf (stderr, "gd-png error: cannot allocate libpng main struct\n");
+ php_gd_error("gd-png error: cannot allocate libpng main struct\n");
return NULL;
}
info_ptr = png_create_info_struct (png_ptr);
if (info_ptr == NULL)
{
- fprintf (stderr, "gd-png error: cannot allocate libpng info struct\n");
+ php_gd_error("gd-png error: cannot allocate libpng info struct\n");
png_destroy_read_struct (&png_ptr, NULL, NULL);
return NULL;
}
#ifndef PNG_SETJMP_NOT_SUPPORTED
if (setjmp (gdPngJmpbufStruct.jmpbuf))
{
- fprintf (stderr, "gd-png error: setjmp returns error condition\n");
+ php_gd_error("gd-png error: setjmp returns error condition\n");
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
return NULL;
}
}
if (im == NULL)
{
- fprintf (stderr, "gd-png error: cannot allocate gdImage struct\n");
+ php_gd_error("gd-png error: cannot allocate gdImage struct\n");
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
gdFree (image_data);
gdFree (row_pointers);
case PNG_COLOR_TYPE_PALETTE:
png_get_PLTE (png_ptr, info_ptr, &palette, &num_palette);
#ifdef DEBUG
- fprintf (stderr, "gd-png color_type is palette, colors: %d\n",
+ php_gd_error("gd-png color_type is palette, colors: %d\n",
num_palette);
#endif /* DEBUG */
if (png_get_valid (png_ptr, info_ptr, PNG_INFO_tRNS))
/* create a fake palette and check for single-shade transparency */
if ((palette = (png_colorp) gdMalloc (256 * sizeof (png_color))) == NULL)
{
- fprintf (stderr, "gd-png error: cannot allocate gray palette\n");
+ php_gd_error("gd-png error: cannot allocate gray palette\n");
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
return NULL;
}
rowbytes = png_get_rowbytes (png_ptr, info_ptr);
if ((image_data = (png_bytep) gdMalloc (rowbytes * height)) == NULL)
{
- fprintf (stderr, "gd-png error: cannot allocate image data\n");
+ php_gd_error("gd-png error: cannot allocate image data\n");
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
return NULL;
}
if ((row_pointers = (png_bytepp) gdMalloc (height * sizeof (png_bytep))) == NULL)
{
- fprintf (stderr, "gd-png error: cannot allocate row pointers\n");
+ php_gd_error("gd-png error: cannot allocate row pointers\n");
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
gdFree (image_data);
return NULL;
{
if (!open[i])
{
- fprintf (stderr, "gd-png warning: image data references out-of-range"
+ php_gd_error("gd-png warning: image data references out-of-range"
" color index (%d)\n", i);
}
}
#endif
if (png_ptr == NULL)
{
- fprintf (stderr, "gd-png error: cannot allocate libpng main struct\n");
+ php_gd_error("gd-png error: cannot allocate libpng main struct\n");
return;
}
info_ptr = png_create_info_struct (png_ptr);
if (info_ptr == NULL)
{
- fprintf (stderr, "gd-png error: cannot allocate libpng info struct\n");
+ php_gd_error("gd-png error: cannot allocate libpng info struct\n");
png_destroy_write_struct (&png_ptr, (png_infopp) NULL);
return;
}
#ifndef PNG_SETJMP_NOT_SUPPORTED
if (setjmp (gdPngJmpbufStruct.jmpbuf))
{
- fprintf (stderr, "gd-png error: setjmp returns error condition\n");
+ php_gd_error("gd-png error: setjmp returns error condition\n");
png_destroy_write_struct (&png_ptr, &info_ptr);
return;
}
row_pointers = gdMalloc (sizeof (png_bytep) * height);
if (row_pointers == NULL)
{
- fprintf (stderr, "gd-png error: unable to allocate row_pointers\n");
+ php_gd_error("gd-png error: unable to allocate row_pointers\n");
}
for (j = 0; j < height; ++j)
{
int bo = 0;
if ((row_pointers[j] = (png_bytep) gdMalloc (width * channels)) == NULL)
{
- fprintf (stderr, "gd-png error: unable to allocate rows\n");
+ php_gd_error("gd-png error: unable to allocate rows\n");
for (i = 0; i < j; ++i)
gdFree (row_pointers[i]);
return;
row_pointers = gdMalloc (sizeof (png_bytep) * height);
if (row_pointers == NULL)
{
- fprintf (stderr, "gd-png error: unable to allocate row_pointers\n");
+ php_gd_error("gd-png error: unable to allocate row_pointers\n");
}
for (j = 0; j < height; ++j)
{
if ((row_pointers[j] = (png_bytep) gdMalloc (width)) == NULL)
{
- fprintf (stderr, "gd-png error: unable to allocate rows\n");
+ php_gd_error("gd-png error: unable to allocate rows\n");
for (i = 0; i < j; ++i)
gdFree (row_pointers[i]);
return;
void
gdImagePngToSink (gdImagePtr im, gdSinkPtr outSink)
{
- fprintf(stderr,"PNG support is not available\n");
+ php_gd_error("PNG support is not available\n");
}
gdImagePtr
gdImageCreateFromPngSource (gdSourcePtr inSource)
{
- fprintf(stderr,"PNG support is not available\n");
+ php_gd_error("PNG support is not available\n");
return NULL;
}
#endif /* HAVE_LIBPNG */
/* create the WBMP */
if ((wbmp = createwbmp (gdImageSX (image), gdImageSY (image), WBMP_WHITE)) == NULL)
- fprintf (stderr, "Could not create WBMP\n");
+ php_gd_error("Could not create WBMP\n");
/* fill up the WBMP structure */
pos = 0;
/* write the WBMP to a gd file descriptor */
if (writewbmp (wbmp, &gd_putout, out))
- fprintf (stderr, "Could not save WBMP\n");
+ php_gd_error("Could not save WBMP\n");
/* des submitted this bugfix: gdFree the memory. */
freewbmp (wbmp);
}
static void
error (const char *format,...)
{
- va_list args;
-
- va_start (args, format);
- fprintf (stderr, "%s: ", LIBNAME);
- vfprintf (stderr, format, args);
- fprintf (stderr, "\n");
- va_end (args);
+ va_list args;
+ char *tmp;
+ TSRMLS_FETCH();
+
+ va_start(args, format);
+ vspprintf(&tmp, 0, format, args);
+ va_end(args);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s: %s", LIBNAME, tmp);
+ efree(tmp);
}
/* DetectKanjiCode() derived from DetectCodeType() by Ken Lunde. */
colors[i] = gdImageColorResolve (im, red, green, blue);
if (colors[i] == -1)
- fprintf (stderr, "ARRRGH\n");
+ php_gd_error("ARRRGH\n");
}
apixel = (char *) gdMalloc (image.cpp + 1);