Use custom error handler instead of fprintf(stderr, ...)

master
Ondřej Surý 2013-04-16 11:31:22 +02:00
parent 21efcc3092
commit 32b1307c62
33 changed files with 294 additions and 238 deletions

View File

@ -21,7 +21,7 @@ int main(int argc, char *argv[])
(void)argv;
/* 2.0.12 */
fprintf (stderr, "annotate is not useful without freetype.\n"
fprintf(stderr, "annotate is not useful without freetype.\n"
"Install freetype, then './configure; make clean; make install'\n"
"the gd library again.\n"
);

View File

@ -29,7 +29,7 @@ dosizes (gdImagePtr im, int color, char *fontfile,
buf);
#endif
if (cp)
fprintf (stderr, "%s\n", cp);
fprintf(stderr, "%s\n", cp);
y += cursize + 4;
/* render the same fontsize with antialiasing turned off */
@ -43,7 +43,7 @@ dosizes (gdImagePtr im, int color, char *fontfile,
y, buf);
#endif
if (cp)
fprintf (stderr, "%s\n", cp);
fprintf(stderr, "%s\n", cp);
y += cursize + 4;
}
}
@ -90,7 +90,7 @@ main (int argc, char **argv)
dotest ("arial", 400, 600, ".....Hello, there!", "fontsizetest3.jpeg");
dotest ("luximr", 400, 600, ".....Hello, there!", "fontsizetest4.jpeg");
#else
fprintf (stderr, "no PNG or JPEG support\n");
fprintf(stderr, "no PNG or JPEG support\n");
#endif
return 0;

View File

@ -135,7 +135,7 @@ main (int argc, char **argv)
dotest ("arial", 16, 90.0, 400, 400, "Hello\nthere!",
"fontwheeltest4.jpeg");
#else
fprintf (stderr, "no PNG or JPEG support\n");
fprintf(stderr, "no PNG or JPEG support\n");
#endif
return 0;

View File

@ -4,6 +4,7 @@
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -13,6 +14,7 @@
#include "gd.h"
#include "gdhelpers.h"
#include "gd_color.h"
#include "gd_errors.h"
/* 2.0.12: this now checks the clipping rectangle */
#define gdImageBoundsSafeMacro(im, x, y) (!((((y) < (im)->cy1) || ((y) > (im)->cy2)) || (((x) < (im)->cx1) || ((x) > (im)->cx2))))
@ -67,6 +69,65 @@ static const unsigned char gd_toascii[256] = {
extern const int gdCosT[];
extern const int gdSinT[];
void gd_stderr_error(int priority, const char *format, ...)
{
va_list args;
va_start(args, format);
switch (priority) {
case E_ERROR:
fputs("GD Error: ", stderr);
break;
case E_WARNING:
fputs("GD Warning: ", stderr);
break;
case E_NOTICE:
fputs("GD Notice: ", stderr);
break;
case E_INFO:
fputs("GD Info: ", stderr);
break;
case E_DEBUG:
fputs("GD Debug: ", stderr);
break;
}
va_start(args, format);
fprintf(stderr, format, args);
va_end(args);
fflush(stderr);
}
static gdErrorMethod gd_error_method = gd_stderr_error;
void gd_error(const char *format, ...)
{
va_list args;
va_start(args, format);
gd_error_ex(E_WARNING, format, args);
va_end(args);
}
void gd_error_ex(int priority, const char *format, ...)
{
va_list args;
va_start(args, format);
if (gd_error_method) {
gd_error_method(priority, format, args);
}
va_end(args);
}
BGD_DECLARE(void) gdSetErrorMethod(gdErrorMethod error_method)
{
gd_error_method = error_method;
}
BGD_DECLARE(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);
BGD_DECLARE(int) gdImageGetTrueColorPixel (gdImagePtr im, int x, int y);
@ -2840,7 +2901,7 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromXbm (FILE * fd)
}
}
/* Shouldn't happen */
fprintf (stderr, "Error: bug in gdImageCreateFromXbm!\n");
gd_error("Error: bug in gdImageCreateFromXbm!\n");
fail:
gdImageDestroy (im);
return 0;

View File

@ -335,6 +335,11 @@ gdFont;
/* Text functions take these. */
typedef gdFont *gdFontPtr;
typedef void(*gdErrorMethod)(int, const char *, ...);
BGD_DECLARE(void) gdSetErrorMethod(gdErrorMethod);
BGD_DECLARE(void) gdClearErrorMethod(void);
/* For backwards compatibility only. Use gdImageSetStyle()
for MUCH more flexible line drawing. Also see
gdImageSetBrush(). */

View File

@ -19,30 +19,30 @@ main (int argc, char **argv)
gdImagePtr pal;
FILE *in, *out;
if (argc != 3) {
fprintf (stderr, "Usage: gd2copypal palettefile.gd2 filename.gd2\n");
fprintf(stderr, "Usage: gd2copypal palettefile.gd2 filename.gd2\n");
exit (1);
}
in = fopen (argv[1], "rb");
if (!in) {
fprintf (stderr, "Palette file does not exist!\n");
fprintf(stderr, "Palette file does not exist!\n");
exit (1);
}
pal = gdImageCreateFromGd2 (in);
fclose (in);
if (!pal) {
fprintf (stderr, "Palette is not in GD2 format!\n");
fprintf(stderr, "Palette is not in GD2 format!\n");
exit (1);
}
in = fopen (argv[2], "rb");
if (!in) {
fprintf (stderr, "Input file does not exist!\n");
fprintf(stderr, "Input file does not exist!\n");
exit (1);
}
im = gdImageCreateFromGd2 (in);
fclose (in);
if (!im) {
fprintf (stderr, "Input is not in GD2 format!\n");
fprintf(stderr, "Input is not in GD2 format!\n");
exit (1);
}
@ -50,7 +50,7 @@ main (int argc, char **argv)
out = fopen (argv[2], "wb");
if (!out) {
fprintf (stderr, "Output file cannot be written to!\n");
fprintf(stderr, "Output file cannot be written to!\n");
gdImageDestroy (im);
exit (1);
}

View File

@ -23,7 +23,7 @@ main (int argc, char **argv)
int t0;
if (argc != 7) {
fprintf (stderr, "Usage: gd2time filename.gd count x y w h\n");
fprintf(stderr, "Usage: gd2time filename.gd count x y w h\n");
exit (1);
}
@ -40,7 +40,7 @@ main (int argc, char **argv)
for (i = 0; i < c; i++) {
in = fopen (argv[1], "rb");
if (!in) {
fprintf (stderr, "Input file does not exist!\n");
fprintf(stderr, "Input file does not exist!\n");
exit (1);
}
@ -48,7 +48,7 @@ main (int argc, char **argv)
fclose (in);
if (!im) {
fprintf (stderr, "Error reading source file!\n");
fprintf(stderr, "Error reading source file!\n");
exit (1);
}
gdImageDestroy (im);

View File

@ -33,7 +33,7 @@ main (int argc, char **argv)
}
in = fopen (argv[1], "rb");
if (!in) {
fprintf (stderr, "Input file does not exist!\n");
fprintf(stderr, "Input file does not exist!\n");
exit (1);
}
if (argc == 7) {
@ -43,19 +43,19 @@ main (int argc, char **argv)
}
fclose (in);
if (!im) {
fprintf (stderr, "Input is not in GD2 format!\n");
fprintf(stderr, "Input is not in GD2 format!\n");
exit (1);
}
out = fopen (argv[2], "wb");
if (!out) {
fprintf (stderr, "Output file cannot be written to!\n");
fprintf(stderr, "Output file cannot be written to!\n");
gdImageDestroy (im);
exit (1);
}
#ifdef HAVE_LIBPNG
gdImagePng (im, out);
#else
fprintf (stderr, "No PNG library support available.\n");
fprintf(stderr, "No PNG library support available.\n");
#endif
fclose (out);
gdImageDestroy (im);

26
src/gd_errors.h Normal file
View File

@ -0,0 +1,26 @@
#ifndef GD_ERRORS_H
#define GD_ERRORS_H
#include <syslog.h>
/*
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 E_ERROR LOG_ERR
#define E_WARNING LOG_WARNING
#define E_NOTICE LOG_NOTICE
#define E_INFO LOG_INFO
#define E_DEBUG LOG_DEBUG
void gd_error(const char *format, ...);
void gd_error_ex(int priority, const char *format, ...);
#endif

View File

@ -602,7 +602,7 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromGd2PartCtx (gdIOCtx * in, int srcx, int
/* gd 2.0.11: gdSeek returns TRUE on success, not 0.
Longstanding bug. 01/16/03 */
if (!gdSeek (in, dpos)) {
fprintf (stderr, "Seek error\n");
gd_error("Seek error\n");
goto fail2;
};
GD2_DBG (printf
@ -875,7 +875,7 @@ _gdImageGd2 (gdImagePtr im, gdIOCtx * out, int cs, int fmt)
chunkIdx[chunkNum - 1].offset));
if (gdPutBuf (compData, compLen, out) <= 0) {
fprintf(stderr, "gd write error\n");
gd_error("gd write error\n");
};
};
};
@ -938,13 +938,13 @@ BGD_DECLARE(void *) gdImageGd2Ptr (gdImagePtr im, int cs, int fmt, int *size)
#else /* no HAVE_LIBZ */
BGD_DECLARE(gdImagePtr) gdImageCreateFromGd2 (FILE * inFile)
{
fprintf (stderr, "GD2 support is not available - no libz\n");
gd_error("GD2 support is not available - no libz\n");
return NULL;
}
BGD_DECLARE(gdImagePtr) gdImageCreateFromGd2Ctx (gdIOCtxPtr in)
{
fprintf (stderr, "GD2 support is not available - no libz\n");
gd_error("GD2 support is not available - no libz\n");
return NULL;
}
#endif /* HAVE_LIBZ */

View File

@ -33,6 +33,7 @@
#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
@ -64,7 +65,7 @@ static void fatal_jpeg_error(j_common_ptr cinfo)
{
jmpbuf_wrapper *jmpbufw;
fprintf(stderr, "gd-jpeg: JPEG library reports unrecoverable error: ");
gd_error("gd-jpeg: JPEG library reports unrecoverable error: ");
(*cinfo->err->output_message)(cinfo);
fflush(stderr);
@ -73,9 +74,9 @@ static void fatal_jpeg_error(j_common_ptr cinfo)
if(jmpbufw != 0) {
longjmp(jmpbufw->jmpbuf, 1);
fprintf(stderr, "gd-jpeg: EXTREMELY fatal error: longjmp returned control; terminating\n");
gd_error("gd-jpeg: EXTREMELY fatal error: longjmp returned control; terminating\n");
} else {
fprintf(stderr, "gd-jpeg: EXTREMELY fatal error: jmpbuf unrecoverable; terminating\n");
gd_error("gd-jpeg: EXTREMELY fatal error: jmpbuf unrecoverable; terminating\n");
}
fflush(stderr);
@ -181,7 +182,7 @@ BGD_DECLARE(void) gdImageJpegCtx(gdImagePtr im, gdIOCtx *outfile, int quality)
row = (JSAMPROW)gdCalloc(1, cinfo.image_width * cinfo.input_components * sizeof(JSAMPLE));
if(row == 0) {
fprintf (stderr, "gd-jpeg: error: unable to allocate JPEG row structure: gdCalloc returns NULL\n");
gd_error("gd-jpeg: error: unable to allocate JPEG row structure: gdCalloc returns NULL\n");
jpeg_destroy_compress(&cinfo);
return;
}
@ -202,7 +203,7 @@ BGD_DECLARE(void) gdImageJpegCtx(gdImagePtr im, gdIOCtx *outfile, int quality)
if(im->trueColor) {
#if BITS_IN_JSAMPLE == 12
fprintf(stderr,
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"
@ -223,7 +224,7 @@ BGD_DECLARE(void) gdImageJpegCtx(gdImagePtr im, gdIOCtx *outfile, int quality)
nlines = jpeg_write_scanlines(&cinfo, rowptr, 1);
if(nlines != 1) {
fprintf (stderr, "gd_jpeg: warning: jpeg_write_scanlines returns %u -- expected 1\n", nlines);
gd_error("gd_jpeg: warning: jpeg_write_scanlines returns %u -- expected 1\n", nlines);
}
}
} else {
@ -251,7 +252,7 @@ BGD_DECLARE(void) gdImageJpegCtx(gdImagePtr im, gdIOCtx *outfile, int quality)
nlines = jpeg_write_scanlines(&cinfo, rowptr, 1);
if(nlines != 1) {
fprintf (stderr, "gd_jpeg: warning: jpeg_write_scanlines"
gd_error("gd_jpeg: warning: jpeg_write_scanlines"
" returns %u -- expected 1\n", nlines);
}
}
@ -343,25 +344,25 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromJpegCtx(gdIOCtx *infile)
retval = jpeg_read_header(&cinfo, TRUE);
if(retval != JPEG_HEADER_OK) {
fprintf (stderr, "gd-jpeg: warning: jpeg_read_header returns"
gd_error("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"
gd_error("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"
gd_error("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);
}
im = gdImageCreateTrueColor((int)cinfo.image_width, (int)cinfo.image_height);
if(im == 0) {
fprintf (stderr, "gd-jpeg error: cannot allocate gdImage struct\n");
gd_error("gd-jpeg error: cannot allocate gdImage struct\n");
goto error;
}
@ -388,7 +389,7 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromJpegCtx(gdIOCtx *infile)
}
if(jpeg_start_decompress(&cinfo) != TRUE) {
fprintf(stderr, "gd-jpeg: warning: jpeg_start_decompress"
gd_error("gd-jpeg: warning: jpeg_start_decompress"
" reports suspended data source\n");
}
@ -452,7 +453,7 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromJpegCtx(gdIOCtx *infile)
#endif
if(cinfo.out_color_space == JCS_RGB) {
if(cinfo.output_components != 3) {
fprintf (stderr, "gd-jpeg: error: JPEG color quantization"
gd_error("gd-jpeg: error: JPEG color quantization"
" request resulted in output_components == %d"
" (expected 3 for RGB)\n", cinfo.output_components);
goto error;
@ -461,7 +462,7 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromJpegCtx(gdIOCtx *infile)
} else if(cinfo.out_color_space == JCS_CMYK) {
jpeg_saved_marker_ptr marker;
if(cinfo.output_components != 4) {
fprintf (stderr, "gd-jpeg: error: JPEG color quantization"
gd_error("gd-jpeg: error: JPEG color quantization"
" request resulted in output_components == %d"
" (expected 4 for CMYK)\n", cinfo.output_components);
goto error;
@ -479,22 +480,23 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromJpegCtx(gdIOCtx *infile)
marker = marker->next;
}
} else {
fprintf(stderr, "gd-jpeg: error: unexpected colorspace\n");
gd_error("gd-jpeg: error: unexpected colorspace\n");
goto error;
}
#if BITS_IN_JSAMPLE == 12
fprintf(stderr, "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"
"jmorecfg.h file to specify the correct precision and completely\n"
"'make clean' and 'make install' libjpeg again. Sorry.\n");
gd_error_ex(E_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"
"jmorecfg.h file to specify the correct precision and completely\n"
"'make clean' and 'make install' libjpeg again. Sorry.\n");
goto error;
#endif /* BITS_IN_JSAMPLE == 12 */
row = gdCalloc(cinfo.output_width *channels, sizeof(JSAMPLE));
if(row == 0) {
fprintf (stderr, "gd-jpeg: error: unable to allocate row for"
gd_error("gd-jpeg: error: unable to allocate row for"
" JPEG scanline: gdCalloc returns NULL\n");
goto error;
}
@ -505,7 +507,7 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromJpegCtx(gdIOCtx *infile)
register int *tpix = im->tpixels[i];
nrows = jpeg_read_scanlines(&cinfo, rowptr, 1);
if(nrows != 1) {
fprintf (stderr, "gd-jpeg: error: jpeg_read_scanlines"
gd_error("gd-jpeg: error: jpeg_read_scanlines"
" returns %u, expected 1\n", nrows);
goto error;
}
@ -519,7 +521,7 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromJpegCtx(gdIOCtx *infile)
register int *tpix = im->tpixels[i];
nrows = jpeg_read_scanlines(&cinfo, rowptr, 1);
if(nrows != 1) {
fprintf (stderr, "gd-jpeg: error: jpeg_read_scanlines"
gd_error("gd-jpeg: error: jpeg_read_scanlines"
" returns %u, expected 1\n", nrows);
goto error;
}
@ -530,8 +532,8 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromJpegCtx(gdIOCtx *infile)
}
if(jpeg_finish_decompress (&cinfo) != TRUE) {
fprintf(stderr, "gd-jpeg: warning: jpeg_finish_decompress"
" reports suspended data source\n");
gd_error("gd-jpeg: warning: jpeg_finish_decompress"
" reports suspended data source\n");
}
/* TBB 2.0.29: we should do our best to read whatever we can read, and a
* warning is a warning. A fatal error on warnings doesn't make sense. */

View File

@ -35,6 +35,7 @@
#include <string.h>
#include "gd.h"
#include "gdhelpers.h"
#include "gd_errors.h"
#include "gd_nnquant.h"
@ -466,7 +467,7 @@ int verbose;
for (i=0; i<rad; i++)
nnq->radpower[i] = alpha*(((rad*rad - i*i)*radbias)/(rad*rad));
if(verbose) fprintf(stderr,"beginning 1D learning: initial radius=%d\n", rad);
if (verbose) gd_error_ex(E_NOTICE, "beginning 1D learning: initial radius=%d\n", rad);
if ((nnq->lengthcount%prime1) != 0) step = 4*prime1;
else {
@ -501,7 +502,7 @@ int verbose;
nnq->radpower[j] = alpha*(((rad*rad - j*j)*radbias)/(rad*rad));
}
}
if(verbose) fprintf(stderr,"finished 1D learning: final alpha=%f !\n",((float)alpha)/initalpha);
if (verbose) gd_error_ex(E_NOTICE, "finished 1D learning: final alpha=%f !\n",((float)alpha)/initalpha);
}
BGD_DECLARE(gdImagePtr) gdImageNeuQuant(gdImagePtr im, const int max_color, int sample_factor)
@ -578,10 +579,8 @@ BGD_DECLARE(gdImagePtr) gdImageNeuQuant(gdImagePtr im, const int max_color, int
}
}
if (bot_idx != top_idx + 1) {
fprintf(stderr,
" internal logic error: remapped bot_idx = %d, top_idx = %d\n",
bot_idx, top_idx);
fflush(stderr);
gd_error(" internal logic error: remapped bot_idx = %d, top_idx = %d\n",
bot_idx, top_idx);
goto done;
}

View File

@ -61,12 +61,12 @@ gdPngErrorHandler (png_structp png_ptr, png_const_charp msg)
* regardless of whether _BSD_SOURCE or anything else has (or has not)
* been defined. */
fprintf (stderr, "gd-png: fatal libpng error: %s\n", msg);
gd_error("gd-png: fatal libpng error: %s\n", msg);
fflush (stderr);
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");
gd_error("gd-png: EXTREMELY fatal error: jmpbuf unrecoverable; terminating.\n");
fflush (stderr);
exit (99);
}
@ -163,13 +163,13 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromPngCtx (gdIOCtx * infile)
png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
#endif
if (png_ptr == NULL) {
fprintf (stderr, "gd-png error: cannot allocate libpng main struct\n");
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");
gd_error("gd-png error: cannot allocate libpng info struct\n");
png_destroy_read_struct (&png_ptr, NULL, NULL);
return NULL;
@ -184,7 +184,7 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromPngCtx (gdIOCtx * infile)
* PNG-reading libpng function */
#ifdef PNG_SETJMP_SUPPORTED
if (setjmp(jbw.jmpbuf)) {
fprintf (stderr, "gd-png error: setjmp returns error condition 1\n");
gd_error("gd-png error: setjmp returns error condition 1\n");
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
return NULL;
@ -204,7 +204,7 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromPngCtx (gdIOCtx * infile)
im = gdImageCreate ((int) width, (int) height);
}
if (im == NULL) {
fprintf (stderr, "gd-png error: cannot allocate gdImage struct\n");
gd_error("gd-png error: cannot allocate gdImage struct\n");
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
return NULL;
@ -221,7 +221,7 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromPngCtx (gdIOCtx * infile)
*/
#ifdef PNG_SETJMP_SUPPORTED
if (setjmp(jbw.jmpbuf)) {
fprintf(stderr, "gd-png error: setjmp returns error condition 2\n");
gd_error("gd-png error: setjmp returns error condition 2\n");
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
gdFree(image_data);
gdFree(row_pointers);
@ -250,7 +250,7 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromPngCtx (gdIOCtx * infile)
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", num_palette);
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)) {
/* gd 2.0: we support this rather thoroughly now. Grab the
@ -275,7 +275,7 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromPngCtx (gdIOCtx * infile)
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) {
fprintf (stderr, "gd-png error: cannot allocate gray palette\n");
gd_error("gd-png error: cannot allocate gray palette\n");
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
return NULL;
}
@ -345,7 +345,7 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromPngCtx (gdIOCtx * infile)
}
image_data = (png_bytep) gdMalloc (rowbytes * height);
if (!image_data) {
fprintf (stderr, "gd-png error: cannot allocate image data\n");
gd_error("gd-png error: cannot allocate image data\n");
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
if (im) {
gdImageDestroy(im);
@ -363,7 +363,7 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromPngCtx (gdIOCtx * infile)
row_pointers = (png_bytepp) gdMalloc (height * sizeof (png_bytep));
if (!row_pointers) {
fprintf (stderr, "gd-png error: cannot allocate row pointers\n");
gd_error("gd-png error: cannot allocate row pointers\n");
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
if (im) {
gdImageDestroy(im);
@ -544,20 +544,20 @@ BGD_DECLARE(void) gdImagePngCtxEx (gdImagePtr im, gdIOCtx * outfile, int level)
png_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
#endif
if (png_ptr == NULL) {
fprintf (stderr, "gd-png error: cannot allocate libpng main struct\n");
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");
gd_error("gd-png error: cannot allocate libpng info struct\n");
png_destroy_write_struct (&png_ptr, (png_infopp) NULL);
return;
}
#ifdef PNG_SETJMP_SUPPORTED
if (setjmp(jbw.jmpbuf)) {
fprintf (stderr, "gd-png error: setjmp returns error condition\n");
gd_error("gd-png error: setjmp returns error condition\n");
png_destroy_write_struct (&png_ptr, &info_ptr);
return;
}
@ -610,7 +610,7 @@ BGD_DECLARE(void) gdImagePngCtxEx (gdImagePtr im, gdIOCtx * outfile, int level)
}
}
if (colors == 0) {
fprintf(stderr, "gd-png error: no colors in palette\n");
gd_error("gd-png error: no colors in palette\n");
goto bail;
}
if (colors < im->colorsTotal) {
@ -746,14 +746,14 @@ BGD_DECLARE(void) gdImagePngCtxEx (gdImagePtr im, gdIOCtx * outfile, int level)
}
row_pointers = gdMalloc (sizeof (png_bytep) * height);
if (row_pointers == NULL) {
fprintf (stderr, "gd-png error: unable to allocate row_pointers\n");
gd_error("gd-png error: unable to allocate row_pointers\n");
goto bail;
}
prow_pointers = row_pointers;
for (j = 0; j < height; ++j) {
if (overflow2(width, channels) || ((*prow_pointers =
(png_bytep) gdMalloc (width * channels)) == NULL)) {
fprintf (stderr, "gd-png error: unable to allocate rows\n");
gd_error("gd-png error: unable to allocate rows\n");
for (i = 0; i < j; ++i)
gdFree (row_pointers[i]);
/* 2.0.29: memory leak TBB */
@ -795,12 +795,12 @@ BGD_DECLARE(void) gdImagePngCtxEx (gdImagePtr im, gdIOCtx * outfile, int level)
}
row_pointers = gdMalloc (sizeof (png_bytep) * height);
if (row_pointers == NULL) {
fprintf (stderr, "gd-png error: unable to allocate row_pointers\n");
gd_error("gd-png error: unable to allocate row_pointers\n");
goto bail;
}
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");
gd_error("gd-png error: unable to allocate rows\n");
for (i = 0; i < j; ++i)
gdFree (row_pointers[i]);
/* TBB: memory leak */

View File

@ -16,15 +16,16 @@
#include <stdlib.h>
#include <limits.h>
#include "gd.h"
#include "gd_errors.h"
int overflow2(int a, int b)
{
if(a <= 0 || b <= 0) {
fprintf(stderr, "gd warning: one parameter to a memory allocation multiplication is negative or zero, failing operation gracefully\n");
gd_error(E_WARNING, "one parameter to a memory allocation multiplication is negative or zero, failing operation gracefully\n");
return 1;
}
if(a > INT_MAX / b) {
fprintf(stderr, "gd warning: product of memory allocation multiplication would exceed INT_MAX, failing operation gracefully\n");
gd_error_ex(E_WARNING, "product of memory allocation multiplication would exceed INT_MAX, failing operation gracefully\n");
return 1;
}
return 0;

View File

@ -41,13 +41,13 @@ BGD_DECLARE(void) gdImagePngToSink (gdImagePtr im, gdSinkPtr outSink)
{
(void)im;
(void)outSink;
fprintf (stderr, "PNG support is not available\n");
gd_error("PNG support is not available\n");
}
BGD_DECLARE(gdImagePtr) gdImageCreateFromPngSource (gdSourcePtr inSource)
{
(void)inSource;
fprintf (stderr, "PNG support is not available\n");
gd_error("PNG support is not available\n");
return NULL;
}
#endif /* HAVE_LIBPNG */

View File

@ -132,7 +132,7 @@ int read_header_tga(gdIOCtx *ctx, oTga *tga)
unsigned char header[18];
if (gdGetBuf(header, sizeof(header), ctx) < 18) {
fprintf(stderr, "fail to read header");
gd_error("fail to read header");
return -1;
}
@ -165,7 +165,7 @@ int read_header_tga(gdIOCtx *ctx, oTga *tga)
case 32:
break;
default:
fprintf(stderr, "bps %i not supported", tga->bits);
gd_error("bps %i not supported", tga->bits);
return -1;
break;
}

View File

@ -91,13 +91,13 @@ tiff_handle * new_tiff_handle(gdIOCtx *g)
tiff_handle * t;
if (!g) {
fprintf(stderr, "Cannot create a new tiff handle, missing Ctx argument");
gd_error("Cannot create a new tiff handle, missing Ctx argument");
return NULL;
}
t = (tiff_handle *) gdMalloc(sizeof(tiff_handle));
if (!t) {
fprintf(stderr, "Failed to allocate a new tiff handle");
gd_error("Failed to allocate a new tiff handle");
return NULL;
}
@ -369,7 +369,7 @@ void tiffWriter(gdImagePtr image, gdIOCtx *out, int bitDepth)
/* Write the scan line to the tiff */
if(TIFFWriteEncodedStrip(tiff, y, scan, width * samplesPerPixel) == -1) {
/* error handler here */
fprintf(stderr, "Could not create TIFF\n");
gd_error("Could not create TIFF\n");
return;
}
}
@ -463,7 +463,7 @@ static int readTiffColorMap(gdImagePtr im, TIFF *tif, char is_bw, int photometri
return GD_SUCCESS;
} else if (!TIFFGetField(tif, TIFFTAG_COLORMAP, &redcmap, &greencmap, &bluecmap)) {
fprintf(stderr, "Cannot read the color map");
gd_error("Cannot read the color map");
return GD_FAILURE;
}
@ -670,12 +670,12 @@ static int createFromTiffLines(TIFF *tif, gdImagePtr im, uint16 bps, uint16 phot
}
if (!TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &im_height)) {
fprintf(stderr, "Can't fetch TIFF height\n");
gd_error("Can't fetch TIFF height\n");
return FALSE;
}
if (!TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &im_width)) {
fprintf(stderr, "Can't fetch TIFF width \n");
gd_error("Can't fetch TIFF width \n");
return FALSE;
}
@ -694,7 +694,7 @@ static int createFromTiffLines(TIFF *tif, gdImagePtr im, uint16 bps, uint16 phot
case 8:
for (y = 0; y < im_height; y++ ) {
if (!TIFFReadScanline (tif, buffer, y, 0)) {
fprintf(stderr, "Error while reading scanline %i", y);
gd_error("Error while reading scanline %i", y);
break;
}
/* reading one line at a time */
@ -706,7 +706,7 @@ static int createFromTiffLines(TIFF *tif, gdImagePtr im, uint16 bps, uint16 phot
if (is_bw) {
for (y = 0; y < im_height; y++ ) {
if (!TIFFReadScanline (tif, buffer, y, 0)) {
fprintf(stderr, "Error while reading scanline %i", y);
gd_error("Error while reading scanline %i", y);
break;
}
/* reading one line at a time */
@ -805,17 +805,17 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromTiffCtx(gdIOCtx *infile)
tiff_unmapproc);
if (!tif) {
fprintf(stderr, "Cannot open TIFF image");
gd_error("Cannot open TIFF image");
return NULL;
}
if (!TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &width)) {
fprintf(stderr, "TIFF error, Cannot read image width");
gd_error("TIFF error, Cannot read image width");
goto error;
}
if (!TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &height)) {
fprintf(stderr, "TIFF error, Cannot read image width");
gd_error("TIFF error, Cannot read image width");
goto error;
}
@ -839,11 +839,11 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromTiffCtx(gdIOCtx *infile)
compression == COMPRESSION_CCITTFAX4 ||
compression == COMPRESSION_CCITTRLE ||
compression == COMPRESSION_CCITTRLEW)) {
fprintf(stderr, "Could not get photometric. "
gd_error("Could not get photometric. "
"Image is CCITT compressed, assuming min-is-white");
photometric = PHOTOMETRIC_MINISWHITE;
} else {
fprintf(stderr, "Could not get photometric. "
gd_error("Could not get photometric. "
"Assuming min-is-black");
photometric = PHOTOMETRIC_MINISBLACK;
@ -862,7 +862,7 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromTiffCtx(gdIOCtx *infile)
--extra;
} else if (extra > 0 && (extra_types[0] == EXTRASAMPLE_UNSPECIFIED)) {
/* assuming unassociated alpha if unspecified */
fprintf(stderr, "alpha channel type not defined, assuming alpha is not premultiplied");
gd_error("alpha channel type not defined, assuming alpha is not premultiplied");
has_alpha = TRUE;
save_transparent = TRUE;
--extra;
@ -959,7 +959,7 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromTiffCtx(gdIOCtx *infile)
break;
default:
fprintf (stderr, "Orientation %d not handled yet!", orientation);
gd_error("Orientation %d not handled yet!", orientation);
break;
}
}

View File

@ -97,7 +97,7 @@ BGD_DECLARE(void) gdImageWBMPCtx(gdImagePtr image, int fg, gdIOCtx *out)
/* create the WBMP */
if((wbmp = createwbmp(gdImageSX(image), gdImageSY(image), WBMP_WHITE)) == NULL) {
fprintf(stderr, "Could not create WBMP\n");
gd_error("Could not create WBMP\n");
return;
}
@ -114,7 +114,7 @@ BGD_DECLARE(void) gdImageWBMPCtx(gdImagePtr image, int fg, gdIOCtx *out)
/* write the WBMP to a gd file descriptor */
if(writewbmp(wbmp, &gd_putout, out)) {
fprintf(stderr, "Could not save WBMP\n");
gd_error("Could not save WBMP\n");
}
/* des submitted this bugfix: gdFree the memory. */

View File

@ -50,7 +50,7 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromWebpPtr (int size, void *data)
if (Y) free(Y);
if (U) free(U);
if (V) free(V);
fprintf(stderr, "WebP decode: fail to decode input data");
gd_error("WebP decode: fail to decode input data");
return NULL;
}
im = gdImageCreateTrueColor(width, height);
@ -79,7 +79,7 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromWebpCtx (gdIOCtx * infile)
filedata = gdMalloc(size);
if (!filedata) {
fprintf(stderr, "WebP decode: alloc failed");
gd_error("WebP decode: alloc failed");
return NULL;
}
gdGetBuf(filedata, size, infile);
@ -89,7 +89,7 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromWebpCtx (gdIOCtx * infile)
if (Y) free(Y);
if (U) free(U);
if (V) free(V);
fprintf(stderr, "WebP decode: fail to decode input data");
gd_error("WebP decode: fail to decode input data");
return NULL;
}
im = gdImageCreateTrueColor(width, height);
@ -144,7 +144,7 @@ int mapQualityToVP8QP(int quality) {
const float vp8qp =
scale * (MAX_QUALITY - quality) / (MAX_QUALITY - MIN_QUALITY) + MIN_VP8QP;
if (quality < MIN_QUALITY || quality > MAX_QUALITY) {
fprintf(stderr, "Wrong quality value %d.", quality);
gd_error("Wrong quality value %d.", quality);
return -1;
}
@ -175,7 +175,7 @@ BGD_DECLARE(void) gdImageWebpCtx (gdImagePtr im, gdIOCtx * outfile, int quantiza
yuv_nbytes = width * height + 2 * yuv_width * yuv_height;
if ((Y = (unsigned char *)gdCalloc(yuv_nbytes, sizeof(unsigned char))) == NULL) {
fprintf(stderr, "gd-webp error: cannot allocate Y buffer");
gd_error("gd-webp error: cannot allocate Y buffer");
return;
}
vp8_quality = mapQualityToVP8QP(quantization);
@ -193,7 +193,7 @@ BGD_DECLARE(void) gdImageWebpCtx (gdImagePtr im, gdIOCtx * outfile, int quantiza
if (filedata) {
free(filedata);
}
fprintf(stderr, "gd-webp error: WebP Encoder failed");
gd_error("gd-webp error: WebP Encoder failed");
return;
}

View File

@ -57,9 +57,9 @@ main (void)
output image. */
in = fopen ("demoin.png", "rb");
if (!in) {
fprintf (stderr, "Can't load source image; this demo\n");
fprintf (stderr, "is much more impressive if demoin.png\n");
fprintf (stderr, "is available.\n");
fprintf(stderr, "Can't load source image; this demo\n");
fprintf(stderr, "is much more impressive if demoin.png\n");
fprintf(stderr, "is available.\n");
im_in = 0;
} else {
int a;
@ -182,7 +182,7 @@ main (void)
gdImageDestroy (im_in);
}
#else
fprintf (stderr, "No PNG library support.\n");
fprintf(stderr, "No PNG library support.\n");
#endif /* HAVE_LIBPNG */
return 0;
}

View File

@ -495,10 +495,6 @@ fontFetch (char **error, void *key)
return NULL;
}
#if 0
fprintf(stderr,"fontpathname=%s\n",fullname);
#endif
err = FT_New_Face(*b->library, a->fontpath, 0, &a->face);
/* Read kerning metrics for Postscript fonts. */
@ -1035,10 +1031,6 @@ BGD_DECLARE(char *) gdImageStringFTEx (gdImage * im, int *brect, int fg, char *f
}
#endif
#if 0
fprintf(stderr,"dpi=%d,%d metric_res=%d ptsize=%g\n",hdpi,vdpi,METRIC_RES,ptsize);
#endif
oldpenf.x = oldpenf.y = 0; /* for postscript xshow operator */
penf.x = penf.y = 0; /* running position of non-rotated glyphs */
previous = 0; /* index of previous glyph for kerning calculations */

View File

@ -231,7 +231,7 @@ main (int argc, char *argv[])
"bottom text", gdTrueColorAlpha (240, 240, 255, 32));
out = fopen ("gdfx.png", "wb");
if (!out) {
fprintf (stderr, "Can't create gdfx.png\n");
gd_error("Can't create gdfx.png\n");
return 1;
}
gdImagePng (im, out);

View File

@ -10,6 +10,7 @@
#include <string.h>
#include "gd.h"
#include "gdhelpers.h"
#include "gd_errors.h"
#ifdef HAVE_ERRNO_H
#include <errno.h>
@ -94,34 +95,6 @@ iconv_close (iconv_t cd)
#define ESC 27
#define SS2 142
static void
debug (const char *format, ...)
{
#ifdef DEBUG
va_list args;
va_start (args, format);
fprintf (stdout, "%s: ", LIBNAME);
vfprintf (stdout, format, args);
fprintf (stdout, "\n");
va_end (args);
#else
(void)format;
#endif
}
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);
}
/* DetectKanjiCode() derived from DetectCodeType() by Ken Lunde. */
static int
@ -200,11 +173,11 @@ DetectKanjiCode (unsigned char *str)
#ifdef DEBUG
if (whatcode == ASCII)
debug ("Kanji code not included.");
gd_error_ex(E_DEBUG, "Kanji code not included.");
else if (whatcode == EUCORSJIS)
debug ("Kanji code not detected.");
gd_error_ex(E_DEBUG, "Kanji code not detected.");
else
debug ("Kanji code detected at %d byte.", i);
gd_error_ex(E_DEBUG, "Kanji code detected at %d byte.", i);
#endif
if (whatcode == EUCORSJIS && oldcode != ASCII)
@ -367,7 +340,7 @@ do_convert (unsigned char **to_p, unsigned char **from_p, const char *code)
size_t from_len, to_len;
if ((cd = iconv_open (EUCSTR, code)) == (iconv_t) - 1) {
error ("iconv_open() error");
gd_error ("iconv_open() error");
#ifdef HAVE_ERRNO_H
if (errno == EINVAL)
error ("invalid code specification: \"%s\" or \"%s\"", EUCSTR, code);
@ -383,20 +356,20 @@ do_convert (unsigned char **to_p, unsigned char **from_p, const char *code)
== -1) {
#ifdef HAVE_ERRNO_H
if (errno == EINVAL)
error ("invalid end of input string");
gd_error ("invalid end of input string");
else if (errno == EILSEQ)
error ("invalid code in input string");
gd_error ("invalid code in input string");
else if (errno == E2BIG)
error ("output buffer overflow at do_convert()");
gd_error ("output buffer overflow at do_convert()");
else
#endif
error ("something happen");
gd_error ("something happen");
ustrcpy (to, from);
return;
}
if (iconv_close (cd) != 0) {
error ("iconv_close() error");
gd_error ("iconv_close() error");
}
#else
int p1, p2, i, j;
@ -447,12 +420,12 @@ do_convert (unsigned char **to_p, unsigned char **from_p, const char *code)
}
}
} else {
error ("invalid code specification: \"%s\"", code);
gd_error ("invalid code specification: \"%s\"", code);
return;
}
if (j >= BUFSIZ) {
error ("output buffer overflow at do_convert()");
gd_error ("output buffer overflow at do_convert()");
ustrcpy (to, from);
} else
to[j] = '\0';
@ -469,44 +442,43 @@ do_check_and_conv (unsigned char *to, unsigned char *from)
switch (DetectKanjiCode (from)) {
case NEW:
debug ("Kanji code is New JIS.");
gd_error_ex(E_DEBUG, "Kanji code is New JIS.");
do_convert (&tmp_p, &from, NEWJISSTR);
break;
case OLD:
debug ("Kanji code is Old JIS.");
gd_error_ex(E_DEBUG, "Kanji code is Old JIS.");
do_convert (&tmp_p, &from, OLDJISSTR);
break;
case ESCI:
debug
("This string includes Hankaku-Kana (jisx0201) escape sequence [ESC] + ( + I.");
gd_error_ex(E_DEBUG, "This string includes Hankaku-Kana (jisx0201) escape sequence [ESC] + ( + I.");
do_convert (&tmp_p, &from, NEWJISSTR);
break;
case NEC:
debug ("Kanji code is NEC Kanji.");
error ("cannot convert NEC Kanji.");
gd_error_ex(E_DEBUG, "Kanji code is NEC Kanji.");
gd_error("cannot convert NEC Kanji.");
ustrcpy (tmp, from);
kanji = FALSE;
break;
case EUC:
debug ("Kanji code is EUC.");
gd_error_ex(E_DEBUG, "Kanji code is EUC.");
ustrcpy (tmp, from);
break;
case SJIS:
debug ("Kanji code is SJIS.");
gd_error_ex(E_DEBUG, "Kanji code is SJIS.");
do_convert (&tmp_p, &from, SJISSTR);
break;
case EUCORSJIS:
debug ("Kanji code is EUC or SJIS.");
gd_error_ex(E_DEBUG, "Kanji code is EUC or SJIS.");
ustrcpy (tmp, from);
kanji = FALSE;
break;
case ASCII:
debug ("This is ASCII string.");
gd_error_ex(E_DEBUG, "This is ASCII string.");
ustrcpy (tmp, from);
kanji = FALSE;
break;
default:
debug ("This string includes unknown code.");
gd_error_ex(E_DEBUG, "This string includes unknown code.");
ustrcpy (tmp, from);
kanji = FALSE;
break;
@ -535,7 +507,7 @@ do_check_and_conv (unsigned char *to, unsigned char *from)
}
if (j >= BUFSIZ) {
error ("output buffer overflow at Hankaku --> Zenkaku");
gd_error("output buffer overflow at Hankaku --> Zenkaku");
ustrcpy (to, tmp);
} else
to[j] = '\0';
@ -552,7 +524,7 @@ any2eucjp (unsigned char *dest, unsigned char *src, unsigned int dest_max)
int ret;
if (strlen ((const char *) src) >= BUFSIZ) {
error ("input string too large");
gd_error("input string too large");
return -1;
}
if (dest_max > BUFSIZ) {
@ -563,7 +535,7 @@ any2eucjp (unsigned char *dest, unsigned char *src, unsigned int dest_max)
}
ret = do_check_and_conv (tmp_dest, src);
if (strlen ((const char *) tmp_dest) >= dest_max) {
error ("output buffer overflow");
gd_error("output buffer overflow");
ustrcpy (dest, src);
return -1;
}

View File

@ -26,7 +26,7 @@ main (int argc, char **argv)
}
in = fopen (argv[1], "rb");
if (!in) {
fprintf (stderr, "Input file does not exist!\n");
fprintf(stderr, "Input file does not exist!\n");
exit (1);
}
@ -40,19 +40,19 @@ main (int argc, char **argv)
im = gdImageCreateFromGd2Part (in, x, y, w, h);
fclose (in);
if (!im) {
fprintf (stderr, "Input is not in GD2 format!\n");
fprintf(stderr, "Input is not in GD2 format!\n");
exit (1);
}
out = fopen (argv[2], "wb");
if (!out) {
fprintf (stderr, "Output file cannot be written to!\n");
fprintf(stderr, "Output file cannot be written to!\n");
gdImageDestroy (im);
exit (1);
}
#ifdef HAVE_LIBPNG
gdImagePng (im, out);
#else
fprintf (stderr, "No PNG library support.\n");
fprintf(stderr, "No PNG library support.\n");
#endif
fclose (out);
gdImageDestroy (im);

View File

@ -1,4 +1,3 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@ -37,12 +36,12 @@ main (int argc, char **argv)
int foreground;
int i;
if (argc != 2) {
fprintf (stderr, "Usage: gdtest filename.png\n");
fprintf(stderr, "Usage: gdtest filename.png\n");
exit (1);
}
in = fopen (argv[1], "rb");
if (!in) {
fprintf (stderr, "Input file does not exist!\n");
fprintf(stderr, "Input file does not exist!\n");
exit (1);
}
im = gdImageCreateFromPng (in);
@ -71,7 +70,7 @@ main (int argc, char **argv)
in = fopen (of, "rb");
if (!in) {
fprintf (stderr, "PNG Output file does not exist!\n");
fprintf(stderr, "PNG Output file does not exist!\n");
exit (1);
}
im2 = gdImageCreateFromPng (in);
@ -104,7 +103,7 @@ main (int argc, char **argv)
in = fopen (of, "rb");
if (!in) {
fprintf (stderr, "GD2 Output file does not exist!\n");
fprintf(stderr, "GD2 Output file does not exist!\n");
exit (1);
}
im2 = gdImageCreateFromGd2 (in);
@ -139,7 +138,7 @@ main (int argc, char **argv)
in = fopen (of, "rb");
if (!in) {
fprintf (stderr, "GD Output file does not exist!\n");
fprintf(stderr, "GD Output file does not exist!\n");
exit (1);
}
im2 = gdImageCreateFromGd (in);
@ -212,7 +211,7 @@ main (int argc, char **argv)
/* */
in = fopen ("test/gdtest_200_300_150_100.png", "rb");
if (!in) {
fprintf (stderr, "gdtest_200_300_150_100.png does not exist!\n");
fprintf(stderr, "gdtest_200_300_150_100.png does not exist!\n");
exit (1);
}
im2 = gdImageCreateFromPng (in);
@ -221,7 +220,7 @@ main (int argc, char **argv)
in = fopen ("test/gdtest.gd2", "rb");
if (!in) {
fprintf (stderr, "gdtest.gd2 does not exist!\n");
fprintf(stderr, "gdtest.gd2 does not exist!\n");
exit (1);
}
im3 = gdImageCreateFromGd2Part (in, 200, 300, 150, 100);
@ -238,7 +237,7 @@ main (int argc, char **argv)
/* */
in = fopen ("test/gdtest.png", "rb");
if (!in) {
fprintf (stderr, "gdtest.png does not exist!\n");
fprintf(stderr, "gdtest.png does not exist!\n");
exit (1);
}
im2 = gdImageCreateFromPng (in);
@ -260,7 +259,7 @@ main (int argc, char **argv)
in = fopen ("test/gdtest_merge.png", "rb");
if (!in) {
fprintf (stderr, "gdtest_merge.png does not exist!\n");
fprintf(stderr, "gdtest_merge.png does not exist!\n");
exit (1);
}
im3 = gdImageCreateFromPng (in);
@ -275,20 +274,20 @@ main (int argc, char **argv)
#ifdef HAVE_LIBJPEG
out = fopen ("test/gdtest.jpg", "wb");
if (!out) {
fprintf (stderr, "Can't create file test/gdtest.jpg.\n");
fprintf(stderr, "Can't create file test/gdtest.jpg.\n");
exit (1);
}
gdImageJpeg (im, out, -1);
fclose (out);
in = fopen ("test/gdtest.jpg", "rb");
if (!in) {
fprintf (stderr, "Can't open file test/gdtest.jpg.\n");
fprintf(stderr, "Can't open file test/gdtest.jpg.\n");
exit (1);
}
im2 = gdImageCreateFromJpeg (in);
fclose (in);
if (!im2) {
fprintf (stderr, "gdImageCreateFromJpeg failed.\n");
fprintf(stderr, "gdImageCreateFromJpeg failed.\n");
exit (1);
}
gdImageDestroy (im2);
@ -302,33 +301,33 @@ main (int argc, char **argv)
"NOTE: the WBMP output image will NOT match the original unless the original\n"
"is also black and white. This is OK!\n");
foreground = gdImageColorClosest (im, 0, 0, 0);
fprintf (stderr, "Foreground index is %d\n", foreground);
fprintf(stderr, "Foreground index is %d\n", foreground);
if (foreground == -1) {
fprintf (stderr, "Source image has no colors, skipping wbmp test.\n");
fprintf(stderr, "Source image has no colors, skipping wbmp test.\n");
} else {
out = fopen ("test/gdtest.wbmp", "wb");
if (!out) {
fprintf (stderr, "Can't create file test/gdtest.wbmp.\n");
fprintf(stderr, "Can't create file test/gdtest.wbmp.\n");
exit (1);
}
gdImageWBMP (im, foreground, out);
fclose (out);
in = fopen ("test/gdtest.wbmp", "rb");
if (!in) {
fprintf (stderr, "Can't open file test/gdtest.wbmp.\n");
fprintf(stderr, "Can't open file test/gdtest.wbmp.\n");
exit (1);
}
im2 = gdImageCreateFromWBMP (in);
fprintf (stderr, "WBMP has %d colors\n", gdImageColorsTotal (im2));
fprintf (stderr, "WBMP colors are:\n");
fprintf(stderr, "WBMP has %d colors\n", gdImageColorsTotal (im2));
fprintf(stderr, "WBMP colors are:\n");
for (i = 0; (i < gdImageColorsTotal (im2)); i++) {
fprintf (stderr, "%02X%02X%02X\n",
fprintf(stderr, "%02X%02X%02X\n",
gdImageRed (im2, i),
gdImageGreen (im2, i), gdImageBlue (im2, i));
}
fclose (in);
if (!im2) {
fprintf (stderr, "gdImageCreateFromWBMP failed.\n");
fprintf(stderr, "gdImageCreateFromWBMP failed.\n");
exit (1);
}
CompareImages ("WBMP test (gdtest.png, gdtest.wbmp)", ref, im2);
@ -345,7 +344,7 @@ main (int argc, char **argv)
gdImageDestroy (im);
gdImageDestroy (ref);
#else
fprintf (stderr, "No PNG library support.\n");
fprintf(stderr, "No PNG library support.\n");
#endif /* HAVE_LIBPNG */
return 0;

View File

@ -27,10 +27,10 @@ int
main (int argc, char *argv[])
{
#ifndef HAVE_LIBFREETYPE
fprintf (stderr, "gd was not compiled with HAVE_LIBFREETYPE defined.\n");
fprintf (stderr, "Install the FreeType library, including the\n");
fprintf (stderr, "header files. Then edit the gd Makefile, type\n");
fprintf (stderr, "make clean, and type make again.\n");
fprintf(stderr, "gd was not compiled with HAVE_LIBFREETYPE defined.\n");
fprintf(stderr, "Install the FreeType library, including the\n");
fprintf(stderr, "header files. Then edit the gd Makefile, type\n");
fprintf(stderr, "make clean, and type make again.\n");
return 1;
#else
gdImagePtr im;
@ -60,9 +60,8 @@ main (int argc, char *argv[])
} else {
/* 2.02: usage message. Defaulting to Times wasn't working well for the
many people with no /usr/share/fonts/truetype. */
fprintf (stderr, "Usage: gdtestft fontfilename\n");
fprintf (stderr,
"If fontfilename is not a full or relative path, GDFONTPATH is searched for\n"
fprintf(stderr, "Usage: gdtestft fontfilename\n"
"If fontfilename is not a full or relative path, GDFONTPATH is searched for\n"
"it. If GDFONTPATH is not set, /usr/share/fonts/truetype is searched.\n");
exit (1);
}
@ -70,7 +69,7 @@ main (int argc, char *argv[])
err =
gdImageStringFT ((gdImagePtr) NULL, &brect[0], 0, f, sz, angle, 0, 0, s);
if (err) {
fprintf (stderr, "%s\n", err);
fprintf(stderr, "%s\n", err);
return 1;
}
@ -99,10 +98,10 @@ main (int argc, char *argv[])
#ifdef HAVE_LIBJPEG
imb = gdImageCreateFromJpeg (in);
#else
fprintf (stderr, "No JPEG library support.\n");
fprintf(stderr, "No JPEG library support.\n");
#endif
if (!imb) {
fprintf (stderr, "gdImageCreateFromJpeg failed\n");
fprintf(stderr, "gdImageCreateFromJpeg failed\n");
exit (1);
}
if (!im->trueColor) {
@ -136,50 +135,50 @@ main (int argc, char *argv[])
/* With antialiasing (positive color value) */
err = gdImageStringFT (im, NULL, blue, f, sz, angle, x, y, s);
if (err) {
fprintf (stderr, "%s\n", err);
fprintf(stderr, "%s\n", err);
return 1;
}
/* Without antialiasing (negative color value) */
err = gdImageStringFT (im, NULL, -blue, f, sz, angle, sx + x, y, s);
if (err) {
fprintf (stderr, "%s\n", err);
fprintf(stderr, "%s\n", err);
return 1;
}
/* With antialiasing, and 50% alpha blending (truecolor only) */
err = gdImageStringFT (im, NULL, blueAlpha, f, sz, angle, sx * 2 + x, y, s);
if (err) {
fprintf (stderr, "%s\n", err);
fprintf(stderr, "%s\n", err);
return 1;
}
/* TBB: Write img to test/fttest.jpg or test/fttest.png */
if (im->trueColor) {
out = fopen ("test/fttest.jpg", "wb");
if (!out) {
fprintf (stderr, "Can't create test/fttest.jpg\n");
fprintf(stderr, "Can't create test/fttest.jpg\n");
exit (1);
}
/* Fairly high JPEG quality setting */
#ifdef HAVE_LIBJPEG
gdImageJpeg (im, out, 90);
#else
fprintf (stderr, "No JPEG library support.\n");
fprintf(stderr, "No JPEG library support.\n");
#endif
fclose (out);
fprintf (stderr, "Test image written to test/fttest.jpg\n");
fprintf(stderr, "Test image written to test/fttest.jpg\n");
} else {
out = fopen ("test/fttest.png", "wb");
if (!out) {
fprintf (stderr, "Can't create test/fttest.png\n");
fprintf(stderr, "Can't create test/fttest.png\n");
exit (1);
}
/* 2.0.10: correct ifdef, thanks to Gabriele Verzeletti */
#ifdef HAVE_LIBPNG
gdImagePng (im, out);
#else
fprintf (stderr, "No PNG library support.\n");
fprintf(stderr, "No PNG library support.\n");
#endif
fclose (out);
fprintf (stderr, "Test image written to test/fttest.png\n");
fprintf(stderr, "Test image written to test/fttest.png\n");
}
/* Destroy it */
gdImageDestroy (im);

View File

@ -18,30 +18,30 @@ main (int argc, char **argv)
gdImagePtr im;
FILE *in, *out;
if (argc != 3) {
fprintf (stderr, "Usage: gdtopng filename.gd filename.png\n");
fprintf(stderr, "Usage: gdtopng filename.gd filename.png\n");
exit (1);
}
in = fopen (argv[1], "rb");
if (!in) {
fprintf (stderr, "Input file does not exist!\n");
fprintf(stderr, "Input file does not exist!\n");
exit (1);
}
im = gdImageCreateFromGd (in);
fclose (in);
if (!im) {
fprintf (stderr, "Input is not in GD format!\n");
fprintf(stderr, "Input is not in GD format!\n");
exit (1);
}
out = fopen (argv[2], "wb");
if (!out) {
fprintf (stderr, "Output file cannot be written to!\n");
fprintf(stderr, "Output file cannot be written to!\n");
gdImageDestroy (im);
exit (1);
}
#ifdef HAVE_LIBPNG
gdImagePng (im, out);
#else
fprintf (stderr, "No PNG library support.\n");
fprintf(stderr, "No PNG library support.\n");
#endif
fclose (out);
gdImageDestroy (im);

View File

@ -15,12 +15,13 @@
#include "gd.h"
#include "gdhelpers.h"
#include "gd_color_map.h"
#include "gd_errors.h"
#ifndef HAVE_LIBXPM
BGD_DECLARE(gdImagePtr) gdImageCreateFromXpm(char *filename)
{
(void)filename;
fprintf(stderr, "libgd was not built with xpm support\n");
gd_error_ex(E_ERROR, "libgd was not built with xpm support\n");
return NULL;
}
#else

View File

@ -1,4 +1,3 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

View File

@ -20,30 +20,30 @@ main (int argc, char **argv)
int cs, fmt;
if (argc != 5) {
fprintf (stderr, "Usage: pngtogd2 filename.png filename.gd2 cs fmt\n");
fprintf (stderr, " where cs is the chunk size\n");
fprintf (stderr, " fmt is 1 for raw, 2 for compressed\n");
fprintf(stderr, "Usage: pngtogd2 filename.png filename.gd2 cs fmt\n");
fprintf(stderr, " where cs is the chunk size\n");
fprintf(stderr, " fmt is 1 for raw, 2 for compressed\n");
exit (1);
}
in = fopen (argv[1], "rb");
if (!in) {
fprintf (stderr, "Input file does not exist!\n");
fprintf(stderr, "Input file does not exist!\n");
exit (1);
}
#ifdef HAVE_LIBPNG
im = gdImageCreateFromPng (in);
#else
im = NULL;
fprintf (stderr, "No PNG library support available.\n");
fprintf(stderr, "No PNG library support available.\n");
#endif
fclose (in);
if (!im) {
fprintf (stderr, "Input is not in PNG format!\n");
fprintf(stderr, "Input is not in PNG format!\n");
exit (1);
}
out = fopen (argv[2], "wb");
if (!out) {
fprintf (stderr, "Output file cannot be written to!\n");
fprintf(stderr, "Output file cannot be written to!\n");
gdImageDestroy (im);
exit (1);
}

View File

@ -41,13 +41,13 @@ main (int argc, char *argv[])
gdImagePng (im, out);
fclose (out);
#else
fprintf(stderr, "Compiled without libpng support\n");
gd_error("Compiled without libpng support\n");
#endif /* HAVE_LIBPNG */
gdImageDestroy (im);
return 0;
#else
fprintf(stderr, "Compiled without freetype support\n");
gd_error("Compiled without freetype support\n");
return 0;
#endif /* HAVE_LIBFREETYPE */
}

View File

@ -555,7 +555,7 @@ void gd_RGBAToYUV420(gdImagePtr im2,
palette image. */
im = gdImageCreateTrueColor(im2->sx, im2->sy);
if (!im) {
fprintf(stderr, "gd-webp error: cannot convert palette input to truecolor");
gd_error("gd-webp error: cannot convert palette input to truecolor");
return;
}
gdImageCopy(im, im2, 0, 0, 0, 0, im->sx, im->sy);

View File

@ -53,14 +53,14 @@ main (int argc, char **argv)
in = fopen (argv[argc - 1], "rb");
}
if (!in) {
fprintf (stderr, "Error: can't open file %s.\n", argv[argc - 1]);
fprintf(stderr, "can't open file %s.\n", argv[argc - 1]);
exit (1);
}
/* Now load the image. */
#ifdef HAVE_LIBPNG
im = gdImageCreateFromPng (in);
#else
fprintf (stderr, "No PNG library support.\n");
fprintf(stderr, "No PNG library support.\n");
#endif
fclose (in);
/* If the load failed, it must not be a PNG file. */
@ -78,7 +78,7 @@ main (int argc, char **argv)
goto usage;
} else if (!strcmp (argv[i], "-i")) {
if (i == (argc - 2)) {
fprintf (stderr, "Error: -i specified without y or n.\n");
fprintf(stderr, "-i specified without y or n.\n");
no = 1;
goto usage;
}
@ -89,7 +89,7 @@ main (int argc, char **argv)
/* Clear interlace. */
gdImageInterlace (im, 0);
} else {
fprintf (stderr, "Error: -i specified without y or n.\n");
fprintf(stderr, "Error: -i specified without y or n.\n");
no = 1;
goto usage;
}
@ -184,7 +184,7 @@ main (int argc, char **argv)
printf ("%d alpha channels\n", nalpha);
} else {
fprintf (stderr, "Unknown argument: %s\n", argv[i]);
fprintf(stderr, "Unknown argument: %s\n", argv[i]);
break;
}
}
@ -212,7 +212,7 @@ usage:
out = fopen (outFn, "wb");
if (!out) {
fprintf (stderr, "Unable to write to %s -- exiting\n", outFn);
fprintf(stderr, "Unable to write to %s -- exiting\n", outFn);
exit (1);
}
}
@ -221,7 +221,7 @@ usage:
#ifdef HAVE_LIBPNG
gdImagePng (im, out);
#else
fprintf (stderr, "No PNG library support.\n");
fprintf(stderr, "No PNG library support.\n");
#endif
if (!useStdinStdout) {
fclose (out);