static int le_gd, le_gd_font;
#include <gd.h>
-#ifndef HAVE_GD_BUNDLED
-# include <gd_errors.h>
-#endif
+#include <gd_errors.h>
#include <gdfontt.h> /* 1 Tiny font */
#include <gdfonts.h> /* 2 Small font */
#include <gdfontmb.h> /* 3 Medium bold font */
}
/* }}} */
-#ifndef HAVE_GD_BUNDLED
/* {{{ php_gd_error_method
*/
void php_gd_error_method(int type, const char *format, va_list args)
php_verror(NULL, "", type, format, args TSRMLS_CC);
}
/* }}} */
-#endif
/* {{{ PHP_MINIT_FUNCTION
*/
#if HAVE_GD_BUNDLED && HAVE_LIBFREETYPE
gdFontCacheMutexSetup();
#endif
-#ifndef HAVE_GD_BUNDLED
gdSetErrorMethod(php_gd_error_method);
-#endif
+
REGISTER_INI_ENTRIES();
REGISTER_LONG_CONSTANT("IMG_GIF", 1, CONST_CS | CONST_PERSISTENT);
#include <stdlib.h>
#include "gd.h"
#include "gdhelpers.h"
+#include "gd_errors.h"
#include "php.h"
extern int gdCosT[];
extern int gdSinT[];
-static void gdImageBrushApply(gdImagePtr im, int x, int y);
-static void gdImageTileApply(gdImagePtr im, int x, int y);
-static int gdAlphaOverlayColor(int src, int dst, int max);
-int gdImageGetTrueColorPixel(gdImagePtr im, int x, int y);
+/**
+ * Group: Error Handling
+ */
-void php_gd_error_ex(int type, const char *format, ...)
+void gd_stderr_error(int priority, const char *format, va_list args)
{
- va_list args;
+ switch (priority) {
+ case GD_ERROR:
+ fputs("GD Error: ", stderr);
+ break;
+ case GD_WARNING:
+ fputs("GD Warning: ", stderr);
+ break;
+ case GD_NOTICE:
+ fputs("GD Notice: ", stderr);
+ break;
+ case GD_INFO:
+ fputs("GD Info: ", stderr);
+ break;
+ case GD_DEBUG:
+ fputs("GD Debug: ", stderr);
+ break;
+ }
+ vfprintf(stderr, format, args);
+ fflush(stderr);
+}
+static gdErrorMethod gd_error_method = gd_stderr_error;
- va_start(args, format);
- php_verror(NULL, "", type, format, args);
- va_end(args);
+static void _gd_error_ex(int priority, const char *format, va_list args)
+{
+ if (gd_error_method) {
+ gd_error_method(priority, format, args);
+ }
}
-void php_gd_error(const char *format, ...)
+void gd_error(const char *format, ...)
{
va_list args;
+ va_start(args, format);
+ _gd_error_ex(GD_WARNING, format, args);
+ va_end(args);
+}
+void gd_error_ex(int priority, const char *format, ...)
+{
+ va_list args;
va_start(args, format);
- php_verror(NULL, "", E_WARNING, format, args);
+ _gd_error_ex(priority, format, args);
va_end(args);
}
+/*
+ Function: gdSetErrorMethod
+*/
+void gdSetErrorMethod(gdErrorMethod error_method)
+{
+ gd_error_method = error_method;
+}
+
+/*
+ Function: gdClearErrorMethod
+*/
+void gdClearErrorMethod(void)
+{
+ gd_error_method = gd_stderr_error;
+}
+
+static void gdImageBrushApply(gdImagePtr im, int x, int y);
+static void gdImageTileApply(gdImagePtr im, int x, int y);
+static int gdAlphaOverlayColor(int src, int dst, int max);
+int gdImageGetTrueColorPixel(gdImagePtr im, int x, int y);
+
gdImagePtr gdImageCreate (int sx, int sy)
{
int i;
#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
/* Text functions take these. */
typedef gdFont *gdFontPtr;
+typedef void(*gdErrorMethod)(int, const char *, va_list);
+
+void gdSetErrorMethod(gdErrorMethod);
+void gdClearErrorMethod(void);
/**
* Group: Types
--- /dev/null
+#ifndef GD_ERRORS_H
+#define GD_ERRORS_H
+
+#ifndef _WIN32
+# include <syslog.h>
+#else
+/*
+ * priorities/facilities are encoded into a single 32-bit quantity, where the
+ * bottom 3 bits are the priority (0-7) and the top 28 bits are the facility
+ * (0-big number). Both the priorities and the facilities map roughly
+ * one-to-one to strings in the syslogd(8) source code. This mapping is
+ * included in this file.
+ *
+ * priorities (these are ordered)
+ */
+# define LOG_EMERG 0 /* system is unusable */
+# define LOG_ALERT 1 /* action must be taken immediately */
+# define LOG_CRIT 2 /* critical conditions */
+# define LOG_ERR 3 /* error conditions */
+# define LOG_WARNING 4 /* warning conditions */
+# define LOG_NOTICE 5 /* normal but significant condition */
+# define LOG_INFO 6 /* informational */
+# define LOG_DEBUG 7 /* debug-level messages */
+#endif
+
+/*
+LOG_EMERG system is unusable
+LOG_ALERT action must be taken immediately
+LOG_CRIT critical conditions
+LOG_ERR error conditions
+LOG_WARNING warning conditions
+LOG_NOTICE normal, but significant, condition
+LOG_INFO informational message
+LOG_DEBUG debug-level message
+*/
+
+#define GD_ERROR LOG_ERR
+#define GD_WARNING LOG_WARNING
+#define GD_NOTICE LOG_NOTICE
+#define GD_INFO LOG_INFO
+#define GD_DEBUG LOG_DEBUG
+
+void gd_error(const char *format, ...);
+void gd_error_ex(int priority, const char *format, ...);
+
+#endif
#include <string.h>
#include <stdlib.h>
#include "gd.h"
+#include "gd_errors.h"
#include "gdhelpers.h"
#include <zlib.h>
int sidx;
int nc;
- GD2_DBG(php_gd_error("Reading gd2 header info"));
+ GD2_DBG(gd_error("Reading gd2 header info"));
for (i = 0; i < 4; i++) {
ch = gdGetC(in);
}
id[4] = 0;
- GD2_DBG(php_gd_error("Got file code: %s", id));
+ GD2_DBG(gd_error("Got file code: %s", id));
/* Equiv. of 'magick'. */
if (strcmp(id, GD2_ID) != 0) {
- GD2_DBG(php_gd_error("Not a valid gd2 file"));
+ GD2_DBG(gd_error("Not a valid gd2 file"));
goto fail1;
}
if (gdGetWord(vers, in) != 1) {
goto fail1;
}
- GD2_DBG(php_gd_error("Version: %d", *vers));
+ GD2_DBG(gd_error("Version: %d", *vers));
if ((*vers != 1) && (*vers != 2)) {
- GD2_DBG(php_gd_error("Bad version: %d", *vers));
+ GD2_DBG(gd_error("Bad version: %d", *vers));
goto fail1;
}
/* Image Size */
if (!gdGetWord(sx, in)) {
- GD2_DBG(php_gd_error("Could not get x-size"));
+ GD2_DBG(gd_error("Could not get x-size"));
goto fail1;
}
if (!gdGetWord(sy, in)) {
- GD2_DBG(php_gd_error("Could not get y-size"));
+ GD2_DBG(gd_error("Could not get y-size"));
goto fail1;
}
- GD2_DBG(php_gd_error("Image is %dx%d", *sx, *sy));
+ GD2_DBG(gd_error("Image is %dx%d", *sx, *sy));
/* Chunk Size (pixels, not bytes!) */
if (gdGetWord(cs, in) != 1) {
goto fail1;
}
- GD2_DBG(php_gd_error("ChunkSize: %d", *cs));
+ GD2_DBG(gd_error("ChunkSize: %d", *cs));
if ((*cs < GD2_CHUNKSIZE_MIN) || (*cs > GD2_CHUNKSIZE_MAX)) {
- GD2_DBG(php_gd_error("Bad chunk size: %d", *cs));
+ GD2_DBG(gd_error("Bad chunk size: %d", *cs));
goto fail1;
}
if (gdGetWord(fmt, in) != 1) {
goto fail1;
}
- GD2_DBG(php_gd_error("Format: %d", *fmt));
+ GD2_DBG(gd_error("Format: %d", *fmt));
if ((*fmt != GD2_FMT_RAW) && (*fmt != GD2_FMT_COMPRESSED) && (*fmt != GD2_FMT_TRUECOLOR_RAW) && (*fmt != GD2_FMT_TRUECOLOR_COMPRESSED)) {
- GD2_DBG(php_gd_error("Bad data format: %d", *fmt));
+ GD2_DBG(gd_error("Bad data format: %d", *fmt));
goto fail1;
}
if (gdGetWord(ncx, in) != 1) {
goto fail1;
}
- GD2_DBG(php_gd_error("%d Chunks Wide", *ncx));
+ GD2_DBG(gd_error("%d Chunks Wide", *ncx));
/* # of chunks high */
if (gdGetWord(ncy, in) != 1) {
goto fail1;
}
- GD2_DBG(php_gd_error("%d Chunks vertically", *ncy));
+ GD2_DBG(gd_error("%d Chunks vertically", *ncy));
if (gd2_compressed(*fmt)) {
nc = (*ncx) * (*ncy);
- GD2_DBG(php_gd_error("Reading %d chunk index entries", nc));
+ GD2_DBG(gd_error("Reading %d chunk index entries", nc));
if (overflow2(sizeof(t_chunk_info), nc)) {
goto fail1;
}
*chunkIdx = cidx;
}
- GD2_DBG(php_gd_error("gd2 header complete"));
+ GD2_DBG(gd_error("gd2 header complete"));
return 1;
gdImagePtr im;
if (_gd2GetHeader (in, sx, sy, cs, vers, fmt, ncx, ncy, cidx) != 1) {
- GD2_DBG(php_gd_error("Bad GD2 header"));
+ GD2_DBG(gd_error("Bad GD2 header"));
goto fail1;
}
im = gdImageCreate(*sx, *sy);
}
if (im == NULL) {
- GD2_DBG(php_gd_error("Could not create gdImage"));
+ GD2_DBG(gd_error("Could not create gdImage"));
goto fail2;
}
if (!_gdGetColors(in, im, (*vers) == 2)) {
- GD2_DBG(php_gd_error("Could not read color palette"));
+ GD2_DBG(gd_error("Could not read color palette"));
goto fail3;
}
- GD2_DBG(php_gd_error("Image palette completed: %d colours", im->colorsTotal));
+ GD2_DBG(gd_error("Image palette completed: %d colours", im->colorsTotal));
return im;
int zerr;
if (gdTell(in) != offset) {
- GD2_DBG(php_gd_error("Positioning in file to %d", offset));
+ GD2_DBG(gd_error("Positioning in file to %d", offset));
gdSeek(in, offset);
} else {
- GD2_DBG(php_gd_error("Already Positioned in file to %d", offset));
+ GD2_DBG(gd_error("Already Positioned in file to %d", offset));
}
/* Read and uncompress an entire chunk. */
- GD2_DBG(php_gd_error("Reading file"));
+ GD2_DBG(gd_error("Reading file"));
if (gdGetBuf(compBuf, compSize, in) != compSize) {
return FALSE;
}
- GD2_DBG(php_gd_error("Got %d bytes. Uncompressing into buffer of %d bytes", compSize, (int)*chunkLen));
+ GD2_DBG(gd_error("Got %d bytes. Uncompressing into buffer of %d bytes", compSize, (int)*chunkLen));
zerr = uncompress((unsigned char *) chunkBuf, chunkLen, (unsigned char *) compBuf, compSize);
if (zerr != Z_OK) {
- GD2_DBG(php_gd_error("Error %d from uncompress", zerr));
+ GD2_DBG(gd_error("Error %d from uncompress", zerr));
return FALSE;
}
- GD2_DBG(php_gd_error("Got chunk"));
+ GD2_DBG(gd_error("Got chunk"));
return TRUE;
}
chunkBuf = gdCalloc(chunkMax, 1);
compBuf = gdCalloc(compMax, 1);
- GD2_DBG(php_gd_error("Largest compressed chunk is %d bytes", compMax));
+ GD2_DBG(gd_error("Largest compressed chunk is %d bytes", compMax));
}
/* Read the data... */
yhi = im->sy;
}
- GD2_DBG(php_gd_error("Processing Chunk %d (%d, %d), y from %d to %d", chunkNum, cx, cy, ylo, yhi));
+ GD2_DBG(gd_error("Processing Chunk %d (%d, %d), y from %d to %d", chunkNum, cx, cy, ylo, yhi));
if (gd2_compressed(fmt)) {
chunkLen = chunkMax;
if (!_gd2ReadChunk(chunkIdx[chunkNum].offset, compBuf, chunkIdx[chunkNum].size, (char *) chunkBuf, &chunkLen, in)) {
- GD2_DBG(php_gd_error("Error reading comproessed chunk"));
+ GD2_DBG(gd_error("Error reading comproessed chunk"));
goto fail2;
}
}
}
- GD2_DBG(php_gd_error("Freeing memory"));
+ GD2_DBG(gd_error("Freeing memory"));
if (chunkBuf) {
gdFree(chunkBuf);
gdFree(chunkIdx);
}
- GD2_DBG(php_gd_error("Done"));
+ GD2_DBG(gd_error("Done"));
return im;
goto fail1;
}
- GD2_DBG(php_gd_error("File size is %dx%d", fsx, fsy));
+ GD2_DBG(gd_error("File size is %dx%d", fsx, fsy));
/* This is the difference - make a file based on size of chunks. */
if (gd2_truecolor(fmt)) {
if (!_gdGetColors(in, im, vers == 2)) {
goto fail2;
}
- GD2_DBG(php_gd_error("Image palette completed: %d colours", im->colorsTotal));
+ GD2_DBG(gd_error("Image palette completed: %d colours", im->colorsTotal));
/* Process the header info */
nc = ncx * ncy;
/* Remember file position of image data. */
dstart = gdTell(in);
- GD2_DBG(php_gd_error("Data starts at %d", dstart));
+ GD2_DBG(gd_error("Data starts at %d", dstart));
/* Loop through the chunks. */
for (cy = scy; (cy <= ecy); cy++) {
xhi = fsx;
}
- GD2_DBG(php_gd_error("Processing Chunk (%d, %d), from %d to %d", cx, cy, ylo, yhi));
+ GD2_DBG(gd_error("Processing Chunk (%d, %d), from %d to %d", cx, cy, ylo, yhi));
if (!gd2_compressed(fmt)) {
- GD2_DBG(php_gd_error("Using raw format data"));
+ GD2_DBG(gd_error("Using raw format data"));
if (im->trueColor) {
dpos = (cy * (cs * fsx) * 4 + cx * cs * (yhi - ylo) * 4) + dstart;
} else {
/* gd 2.0.11: gdSeek returns TRUE on success, not 0. Longstanding bug. 01/16/03 */
if (!gdSeek(in, dpos)) {
- php_gd_error_ex(E_WARNING, "Error from seek: %d", errno);
+ gd_error_ex(E_WARNING, "Error from seek: %d", errno);
goto fail2;
}
- GD2_DBG(php_gd_error("Reading (%d, %d) from position %d", cx, cy, dpos - dstart));
+ GD2_DBG(gd_error("Reading (%d, %d) from position %d", cx, cy, dpos - dstart));
} else {
chunkNum = cx + cy * ncx;
chunkLen = chunkMax;
if (!_gd2ReadChunk (chunkIdx[chunkNum].offset, compBuf, chunkIdx[chunkNum].size, (char *)chunkBuf, &chunkLen, in)) {
- php_gd_error("Error reading comproessed chunk");
+ gd_error("Error reading comproessed chunk");
goto fail2;
}
chunkPos = 0;
- GD2_DBG(php_gd_error("Reading (%d, %d) from chunk %d", cx, cy, chunkNum));
+ GD2_DBG(gd_error("Reading (%d, %d) from chunk %d", cx, cy, chunkNum));
}
- GD2_DBG(php_gd_error(" into (%d, %d) - (%d, %d)", xlo, ylo, xhi, yhi));
+ GD2_DBG(gd_error(" into (%d, %d) - (%d, %d)", xlo, ylo, xhi, yhi));
for (y = ylo; (y < yhi); y++) {
for (x = xlo; x < xhi; x++) {
*/
idxPos = gdTell(out);
idxSize = ncx * ncy * sizeof(t_chunk_info);
- GD2_DBG(php_gd_error("Index size is %d", idxSize));
+ GD2_DBG(gd_error("Index size is %d", idxSize));
gdSeek(out, idxPos + idxSize);
chunkIdx = safe_emalloc(idxSize, sizeof(t_chunk_info), 0);
_gdPutColors (im, out);
- GD2_DBG(php_gd_error("Size: %dx%d", im->sx, im->sy));
- GD2_DBG(php_gd_error("Chunks: %dx%d", ncx, ncy));
+ GD2_DBG(gd_error("Size: %dx%d", im->sx, im->sy));
+ GD2_DBG(gd_error("Chunks: %dx%d", ncx, ncy));
for (cy = 0; (cy < ncy); cy++) {
for (cx = 0; (cx < ncx); cx++) {
yhi = im->sy;
}
- GD2_DBG(php_gd_error("Processing Chunk (%dx%d), y from %d to %d", cx, cy, ylo, yhi));
+ GD2_DBG(gd_error("Processing Chunk (%dx%d), y from %d to %d", cx, cy, ylo, yhi));
chunkLen = 0;
for (y = ylo; (y < yhi); y++) {
- GD2_DBG(php_gd_error("y=%d: ",y));
+ GD2_DBG(gd_error("y=%d: ",y));
xlo = cx * cs;
xhi = xlo + cs;
if (xhi > im->sx) {
if (gd2_compressed(fmt)) {
for (x = xlo; x < xhi; x++) {
- GD2_DBG(php_gd_error("%d...",x));
+ GD2_DBG(gd_error("%d...",x));
if (im->trueColor) {
int p = im->tpixels[y][x];
chunkData[chunkLen++] = gdTrueColorGetAlpha(p);
}
} else {
for (x = xlo; x < xhi; x++) {
- GD2_DBG(php_gd_error("%d, ",x));
+ GD2_DBG(gd_error("%d, ",x));
if (im->trueColor) {
gdPutInt(im->tpixels[y][x], out);
}
}
}
- GD2_DBG(php_gd_error("y=%d done.",y));
+ GD2_DBG(gd_error("y=%d done.",y));
}
if (gd2_compressed(fmt)) {
compLen = compMax;
if (compress((unsigned char *) &compData[0], &compLen, (unsigned char *) &chunkData[0], chunkLen) != Z_OK) {
- php_gd_error("Error from compressing");
+ gd_error("Error from compressing");
} else {
chunkIdx[chunkNum].offset = gdTell(out);
chunkIdx[chunkNum++].size = compLen;
- GD2_DBG(php_gd_error("Chunk %d size %d offset %d", chunkNum, chunkIdx[chunkNum - 1].size, chunkIdx[chunkNum - 1].offset));
+ GD2_DBG(gd_error("Chunk %d size %d offset %d", chunkNum, chunkIdx[chunkNum - 1].size, chunkIdx[chunkNum - 1].offset));
if (gdPutBuf (compData, compLen, out) <= 0) {
/* Any alternate suggestions for handling this? */
- php_gd_error_ex(E_WARNING, "Error %d on write", errno);
+ gd_error_ex(E_WARNING, "Error %d on write", errno);
}
}
}
if (gd2_compressed(fmt)) {
/* Save the position, write the index, restore position (paranoia). */
- GD2_DBG(php_gd_error("Seeking %d to write index", idxPos));
+ GD2_DBG(gd_error("Seeking %d to write index", idxPos));
posSave = gdTell(out);
gdSeek(out, idxPos);
- GD2_DBG(php_gd_error("Writing index"));
+ GD2_DBG(gd_error("Writing index"));
for (x = 0; x < chunkNum; x++) {
- GD2_DBG(php_gd_error("Chunk %d size %d offset %d", x, chunkIdx[x].size, chunkIdx[x].offset));
+ GD2_DBG(gd_error("Chunk %d size %d offset %d", x, chunkIdx[x].size, chunkIdx[x].offset));
gdPutInt(chunkIdx[x].offset, out);
gdPutInt(chunkIdx[x].size, out);
}
gdSeek(out, posSave);
}
fail:
- GD2_DBG(php_gd_error("Freeing memory"));
+ GD2_DBG(gd_error("Freeing memory"));
if (chunkData) {
gdFree(chunkData);
}
if (chunkIdx) {
gdFree(chunkIdx);
}
- GD2_DBG(php_gd_error("Done"));
+ GD2_DBG(gd_error("Done"));
}
void gdImageGd2 (gdImagePtr im, FILE * outFile, int cs, int fmt)
#include <string.h>
#include <stdlib.h>
#include "gd.h"
+#include "gd_errors.h"
#include "php.h"
} else {
tmp = estrdup("");
}
- php_gd_error_ex(E_NOTICE, "[GetDataBlock returning %d: %s]", rv, tmp);
+ gd_error_ex(GD_NOTICE, "[GetDataBlock returning %d: %s]", rv, tmp);
efree(tmp);
}
return(rv);
void gdPutWord (int w, gdIOCtx * ctx)
{
- IO_DBG (php_gd_error("Putting word..."));
+ IO_DBG (gd_error("Putting word..."));
(ctx->putC) (ctx, (unsigned char) (w >> 8));
(ctx->putC) (ctx, (unsigned char) (w & 0xFF));
- IO_DBG (php_gd_error("put."));
+ IO_DBG (gd_error("put."));
}
void gdPutInt (int w, gdIOCtx * ctx)
{
- IO_DBG (php_gd_error("Putting int..."));
+ IO_DBG (gd_error("Putting int..."));
(ctx->putC) (ctx, (unsigned char) (w >> 24));
(ctx->putC) (ctx, (unsigned char) ((w >> 16) & 0xFF));
(ctx->putC) (ctx, (unsigned char) ((w >> 8) & 0xFF));
(ctx->putC) (ctx, (unsigned char) (w & 0xFF));
- IO_DBG (php_gd_error("put."));
+ IO_DBG (gd_error("put."));
}
int gdGetC (gdIOCtx * ctx)
int gdPutBuf (const void *buf, int size, gdIOCtx * ctx)
{
- IO_DBG (php_gd_error("Putting buf..."));
+ IO_DBG (gd_error("Putting buf..."));
return (ctx->putBuf) (ctx, buf, size);
- IO_DBG (php_gd_error("put."));
+ IO_DBG (gd_error("put."));
}
int gdGetBuf (void *buf, int size, gdIOCtx * ctx)
int gdSeek (gdIOCtx * ctx, const int pos)
{
- IO_DBG (php_gd_error("Seeking..."));
+ IO_DBG (gd_error("Seeking..."));
return ((ctx->seek) (ctx, pos));
- IO_DBG (php_gd_error("Done."));
+ IO_DBG (gd_error("Done."));
}
long gdTell (gdIOCtx * ctx)
{
- IO_DBG (php_gd_error("Telling..."));
+ IO_DBG (gd_error("Telling..."));
return ((ctx->tell) (ctx));
- IO_DBG (php_gd_error ("told."));
+ IO_DBG (gd_error ("told."));
}
#include <string.h>
#include "gd.h"
+#include "gd_errors.h"
/* TBB: move this up so include files are not brought in */
/* JCE: arrange HAVE_LIBJPEG so that it can be set in gd.h */
#ifdef HAVE_LIBJPEG
* unless strace_level >= 3
*/
if ((jpeg_info->err->num_warnings == 0) || (jpeg_info->err->trace_level >= 3)) {
- php_gd_error_ex(ignore_warning ? E_NOTICE : E_WARNING, "gd-jpeg, libjpeg: recoverable error: %s\n", message);
+ gd_error_ex(ignore_warning ? GD_NOTICE : GD_WARNING, "gd-jpeg, libjpeg: recoverable error: %s\n", message);
}
jpeg_info->err->num_warnings++;
} else {
/* strace msg, Show it if trace_level >= level. */
if (jpeg_info->err->trace_level >= level) {
- php_gd_error_ex(E_NOTICE, "gd-jpeg, libjpeg: strace message: %s\n", message);
+ gd_error_ex(GD_NOTICE, "gd-jpeg, libjpeg: strace message: %s\n", message);
}
}
return 1;
{
jmpbuf_wrapper *jmpbufw;
- php_gd_error("gd-jpeg: JPEG library reports unrecoverable error: ");
+ gd_error("gd-jpeg: JPEG library reports unrecoverable error: ");
(*cinfo->err->output_message) (cinfo);
jmpbufw = (jmpbuf_wrapper *) cinfo->client_data;
if (jmpbufw != 0) {
longjmp (jmpbufw->jmpbuf, 1);
- php_gd_error_ex(E_ERROR, "gd-jpeg: EXTREMELY fatal error: longjmp returned control; terminating");
+ gd_error_ex(GD_ERROR, "gd-jpeg: EXTREMELY fatal error: longjmp returned control; terminating");
} else {
- php_gd_error_ex(E_ERROR, "gd-jpeg: EXTREMELY fatal error: jmpbuf unrecoverable; terminating");
+ gd_error_ex(GD_ERROR, "gd-jpeg: EXTREMELY fatal error: jmpbuf unrecoverable; terminating");
}
exit (99);
if (im->trueColor) {
#if BITS_IN_JSAMPLE == 12
- php_gd_error("gd-jpeg: error: jpeg library was compiled for 12-bit precision. This is mostly useless, because JPEGs on the web are 8-bit and such versions of the jpeg library won't read or write them. GD doesn't support these unusual images. Edit your jmorecfg.h file to specify the correct precision and completely 'make clean' and 'make install' libjpeg again. Sorry");
+ gd_error("gd-jpeg: error: jpeg library was compiled for 12-bit precision. This is mostly useless, because JPEGs on the web are 8-bit and such versions of the jpeg library won't read or write them. GD doesn't support these unusual images. Edit your jmorecfg.h file to specify the correct precision and completely 'make clean' and 'make install' libjpeg again. Sorry");
goto error;
#endif /* BITS_IN_JSAMPLE == 12 */
nlines = jpeg_write_scanlines (&cinfo, rowptr, 1);
if (nlines != 1) {
- php_gd_error_ex(E_WARNING, "gd_jpeg: warning: jpeg_write_scanlines returns %u -- expected 1", nlines);
+ gd_error_ex(GD_WARNING, "gd_jpeg: warning: jpeg_write_scanlines returns %u -- expected 1", nlines);
}
}
} else {
nlines = jpeg_write_scanlines (&cinfo, rowptr, 1);
if (nlines != 1) {
- php_gd_error_ex(E_WARNING, "gd_jpeg: warning: jpeg_write_scanlines returns %u -- expected 1", nlines);
+ gd_error_ex(GD_WARNING, "gd_jpeg: warning: jpeg_write_scanlines returns %u -- expected 1", nlines);
}
}
}
retval = jpeg_read_header (&cinfo, TRUE);
if (retval != JPEG_HEADER_OK) {
- php_gd_error_ex(E_WARNING, "gd-jpeg: warning: jpeg_read_header returned %d, expected %d", retval, JPEG_HEADER_OK);
+ gd_error_ex(GD_WARNING, "gd-jpeg: warning: jpeg_read_header returned %d, expected %d", retval, JPEG_HEADER_OK);
}
if (cinfo.image_height > INT_MAX) {
- 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);
+ gd_error_ex(GD_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) {
- 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)", cinfo.image_width, INT_MAX);
+ gd_error_ex(GD_WARNING, "gd-jpeg: warning: JPEG image width (%u) is greater than INT_MAX (%d) (and thus greater than gd can handle)", cinfo.image_width, INT_MAX);
}
im = gdImageCreateTrueColor ((int) cinfo.image_width, (int) cinfo.image_height);
if (im == 0) {
- php_gd_error("gd-jpeg error: cannot allocate gdImage struct");
+ gd_error("gd-jpeg error: cannot allocate gdImage struct");
goto error;
}
}
if (jpeg_start_decompress (&cinfo) != TRUE) {
- php_gd_error("gd-jpeg: warning: jpeg_start_decompress reports suspended data source");
+ gd_error("gd-jpeg: warning: jpeg_start_decompress reports suspended data source");
}
/* REMOVED by TBB 2/12/01. This field of the structure is
if (cinfo.out_color_space == JCS_RGB) {
if (cinfo.output_components != 3) {
- php_gd_error_ex(E_WARNING, "gd-jpeg: error: JPEG color quantization request resulted in output_components == %d (expected 3 for RGB)", cinfo.output_components);
+ gd_error_ex(GD_WARNING, "gd-jpeg: error: JPEG color quantization request resulted in output_components == %d (expected 3 for RGB)", cinfo.output_components);
goto error;
}
channels = 3;
} else if (cinfo.out_color_space == JCS_CMYK) {
jpeg_saved_marker_ptr marker;
if (cinfo.output_components != 4) {
- php_gd_error_ex(E_WARNING, "gd-jpeg: error: JPEG color quantization request resulted in output_components == %d (expected 4 for CMYK)", cinfo.output_components);
+ gd_error_ex(GD_WARNING, "gd-jpeg: error: JPEG color quantization request resulted in output_components == %d (expected 4 for CMYK)", cinfo.output_components);
goto error;
}
channels = 4;
marker = marker->next;
}
} else {
- php_gd_error_ex(E_WARNING, "gd-jpeg: error: unexpected colorspace.");
+ gd_error_ex(GD_WARNING, "gd-jpeg: error: unexpected colorspace.");
goto error;
}
#if BITS_IN_JSAMPLE == 12
- php_gd_error("gd-jpeg: error: jpeg library was compiled for 12-bit precision. This is mostly useless, because JPEGs on the web are 8-bit and such versions of the jpeg library won't read or write them. GD doesn't support these unusual images. Edit your jmorecfg.h file to specify the correct precision and completely 'make clean' and 'make install' libjpeg again. Sorry.");
+ gd_error("gd-jpeg: error: jpeg library was compiled for 12-bit precision. This is mostly useless, because JPEGs on the web are 8-bit and such versions of the jpeg library won't read or write them. GD doesn't support these unusual images. Edit your jmorecfg.h file to specify the correct precision and completely 'make clean' and 'make install' libjpeg again. Sorry.");
goto error;
#endif /* BITS_IN_JSAMPLE == 12 */
register int *tpix = im->tpixels[i];
nrows = jpeg_read_scanlines (&cinfo, rowptr, 1);
if (nrows != 1) {
- php_gd_error_ex(E_WARNING, "gd-jpeg: error: jpeg_read_scanlines returns %u, expected 1", nrows);
+ gd_error_ex(GD_WARNING, "gd-jpeg: error: jpeg_read_scanlines returns %u, expected 1", nrows);
goto error;
}
for (j = 0; j < cinfo.output_width; j++, currow += 4, tpix++) {
register int *tpix = im->tpixels[i];
nrows = jpeg_read_scanlines (&cinfo, rowptr, 1);
if (nrows != 1) {
- php_gd_error_ex(E_WARNING, "gd-jpeg: error: jpeg_read_scanlines returns %u, expected 1", nrows);
+ gd_error_ex(GD_WARNING, "gd-jpeg: error: jpeg_read_scanlines returns %u, expected 1", nrows);
goto error;
}
for (j = 0; j < cinfo.output_width; j++, currow += 3, tpix++) {
}
if (jpeg_finish_decompress (&cinfo) != TRUE) {
- php_gd_error("gd-jpeg: warning: jpeg_finish_decompress reports suspended data source");
+ gd_error("gd-jpeg: warning: jpeg_finish_decompress reports suspended data source");
}
if (!ignore_warning) {
if (cinfo.err->num_warnings > 0) {
#include <string.h>
#include <stdlib.h>
#include "gd.h"
+#include "gd_errors.h"
/* JCE: Arrange HAVE_LIBPNG so that it can be set in gd.h */
#ifdef HAVE_LIBPNG
* been defined.
*/
- php_gd_error_ex(E_WARNING, "gd-png: fatal libpng error: %s", msg);
+ gd_error_ex(GD_WARNING, "gd-png: fatal libpng error: %s", msg);
jmpbuf_ptr = png_get_error_ptr (png_ptr);
if (jmpbuf_ptr == NULL) { /* we are completely hosed now */
- php_gd_error_ex(E_ERROR, "gd-png: EXTREMELY fatal error: jmpbuf unrecoverable; terminating.");
+ gd_error_ex(GD_ERROR, "gd-png: EXTREMELY fatal error: jmpbuf unrecoverable; terminating.");
}
longjmp (jmpbuf_ptr->jmpbuf, 1);
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
#endif
if (png_ptr == NULL) {
- php_gd_error("gd-png error: cannot allocate libpng main struct");
+ gd_error("gd-png error: cannot allocate libpng main struct");
return NULL;
}
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL) {
- php_gd_error("gd-png error: cannot allocate libpng info struct");
+ gd_error("gd-png error: cannot allocate libpng info struct");
png_destroy_read_struct (&png_ptr, NULL, NULL);
return NULL;
*/
#ifdef PNG_SETJMP_SUPPORTED
if (setjmp(jbw.jmpbuf)) {
- php_gd_error("gd-png error: setjmp returns error condition");
+ gd_error("gd-png error: setjmp returns error condition");
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return NULL;
im = gdImageCreate((int) width, (int) height);
}
if (im == NULL) {
- php_gd_error("gd-png error: cannot allocate gdImage struct");
+ gd_error("gd-png error: cannot allocate gdImage struct");
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return NULL;
*/
#ifdef PNG_SETJMP_SUPPORTED
if (setjmp(jbw.jmpbuf)) {
- php_gd_error("gd-png error: setjmp returns error condition");
+ gd_error("gd-png error: setjmp returns error condition");
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
- php_gd_error("gd-png color_type is palette, colors: %d", num_palette);
+ gd_error("gd-png color_type is palette, colors: %d", num_palette);
#endif /* DEBUG */
if (png_get_valid (png_ptr, info_ptr, PNG_INFO_tRNS)) {
/* gd 2.0: we support this rather thoroughly now. Grab the
case PNG_COLOR_TYPE_GRAY:
/* create a fake palette and check for single-shade transparency */
if ((palette = (png_colorp) gdMalloc (256 * sizeof (png_color))) == NULL) {
- php_gd_error("gd-png error: cannot allocate gray palette");
+ gd_error("gd-png error: cannot allocate gray palette");
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return NULL;
if (!im->trueColor) {
for (i = num_palette; i < gdMaxColors; ++i) {
if (!open[i]) {
- php_gd_error("gd-png warning: image data references out-of-range color index (%d)", i);
+ gd_error("gd-png warning: image data references out-of-range color index (%d)", i);
}
}
}
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
#endif
if (png_ptr == NULL) {
- php_gd_error("gd-png error: cannot allocate libpng main struct");
+ gd_error("gd-png error: cannot allocate libpng main struct");
return;
}
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL) {
- php_gd_error("gd-png error: cannot allocate libpng info struct");
+ gd_error("gd-png error: cannot allocate libpng info struct");
png_destroy_write_struct (&png_ptr, (png_infopp) NULL);
return;
#ifdef PNG_SETJMP_SUPPORTED
if (setjmp(jbw.jmpbuf)) {
- php_gd_error("gd-png error: setjmp returns error condition");
+ gd_error("gd-png error: setjmp returns error condition");
png_destroy_write_struct (&png_ptr, &info_ptr);
return;
/* 2.0.12: this is finally a parameter */
if (level != -1 && (level < 0 || level > 9)) {
- php_gd_error("gd-png error: compression level must be 0 through 9");
+ gd_error("gd-png error: compression level must be 0 through 9");
return;
}
png_set_compression_level(png_ptr, level);
}
}
if (colors == 0) {
- php_gd_error("gd-png error: no colors in palette");
+ gd_error("gd-png error: no colors in palette");
goto bail;
}
if (colors < im->colorsTotal) {
int overflow2(int a, int b)
{
if(a <= 0 || b <= 0) {
- php_gd_error("gd warning: one parameter to a memory allocation multiplication is negative or zero, failing operation gracefully\n");
+ gd_error("gd warning: one parameter to a memory allocation multiplication is negative or zero, failing operation gracefully\n");
return 1;
}
if(a > INT_MAX / b) {
- php_gd_error("gd warning: product of memory allocation multiplication would exceed INT_MAX, failing operation gracefully\n");
+ gd_error("gd warning: product of memory allocation multiplication would exceed INT_MAX, failing operation gracefully\n");
return 1;
}
return 0;
#else /* no HAVE_LIBPNG */
void gdImagePngToSink (gdImagePtr im, gdSinkPtr outSink)
{
- php_gd_error("PNG support is not available");
+ gd_error("PNG support is not available");
}
gdImagePtr gdImageCreateFromPngSource (gdSourcePtr inSource)
{
- php_gd_error("PNG support is not available");
+ gd_error("PNG support is not available");
return NULL;
}
#endif /* HAVE_LIBPNG */
/* create the WBMP */
if ((wbmp = createwbmp (gdImageSX (image), gdImageSY (image), WBMP_WHITE)) == NULL) {
- php_gd_error("Could not create WBMP");
+ gd_error("Could not create WBMP");
}
/* fill up the WBMP structure */
/* write the WBMP to a gd file descriptor */
if (writewbmp (wbmp, &gd_putout, out)) {
- php_gd_error("Could not save WBMP");
+ gd_error("Could not save WBMP");
}
/* des submitted this bugfix: gdFree the memory. */
freewbmp(wbmp);
}
}
- php_gd_error("EOF before image was complete");
+ gd_error("EOF before image was complete");
gdImageDestroy(im);
return 0;
}