[PHP-CVS] cvs: php4 /ext/gd gd.c gd_ctx.c php_gd.h
sniper Sat Mar 31 21:42:07 2001 EDT Modified files: /php4/ext/gdgd.c gd_ctx.c php_gd.h Log: Fixed bug #8137 and killed some compile warnings. Index: php4/ext/gd/gd.c diff -u php4/ext/gd/gd.c:1.118 php4/ext/gd/gd.c:1.119 --- php4/ext/gd/gd.c:1.118 Mon Mar 12 05:57:53 2001 +++ php4/ext/gd/gd.cSat Mar 31 21:42:07 2001 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: gd.c,v 1.118 2001/03/12 13:57:53 sasha Exp $ */ +/* $Id: gd.c,v 1.119 2001/04/01 05:42:07 sniper Exp $ */ /* gd 1.2 is copyright 1994, 1995, Quest Protein Database Center, Cold Spring Harbor Labs. */ @@ -92,7 +92,7 @@ #define CTX_PUTC(c,fp) fputc(c, fp) #endif -static void _php_image_output_wbmp(gdImagePtr im, gdIOCtx *fp); +static void _php_image_bw_convert(gdImagePtr im_org, gdIOCtx *out, int threshold); #ifdef THREAD_SAFE DWORD GDlibTls; @@ -644,6 +644,7 @@ } /* }}} */ +size_t php_fread_all(char **buf, int socket, FILE *fp, int issock); static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, gdImagePtr (*func_p)(), gdImagePtr (*ioctx_func_p)()) { zval **file; @@ -685,7 +686,7 @@ if(issock socketd) { #ifdef USE_GD_IOCTX gdIOCtx* io_ctx; - int buff_size; + size_t buff_size; char *buff,*buff_em; buff_size = php_fread_all(buff_em, socketd, fp, issock); @@ -811,11 +812,11 @@ char *fn = NULL; FILE *fp; int argc = ZEND_NUM_ARGS(); - int output = 1, q = -1; + int q = -1, i; GDLS_FETCH(); - /* The quality parameter for Wbmp stands for the threshold - So the q variable */ + /* The quality parameter for Wbmp stands for the threshold when called from +image2wbmp() */ + /* When called from imagewbmp() the quality parameter stands for the +foreground color. Default: black. */ if (argc 1 || argc 3 || zend_get_parameters_ex(argc, imgind, file, quality) == FAILURE) { @@ -846,14 +847,18 @@ } switch(image_type) { + case PHP_GDIMG_CONVERT_WBM: + if(q0||q255) { + php_error(E_WARNING, "%s: invalid threshold +value '%d'. It must be between 0 and 255",get_active_function_name(), q); + } case PHP_GDIMG_TYPE_JPG: (*func_p)(im, fp, q); break; case PHP_GDIMG_TYPE_WBM: - if(q0||q255) { - php_error(E_WARNING, "%s: invalid threshold value '%d'. It must be between 0 and 255",get_active_function_name(), q); + for(i=0; i im-colorsTotal; i++) { + if(im-red[i] == 0) break; } - (*func_p)(im, q, fp); + (*func_p)(im, i, fp); break; default: (*func_p)(im, fp); @@ -873,12 +878,16 @@ } switch(image_type) { + case PHP_GDIMG_CONVERT_WBM: + if(q0||q255) { + php_error(E_WARNING, "%s: invalid threshold +value '%d'. It must be between 0 and 255",get_active_function_name(), q); + } case PHP_GDIMG_TYPE_JPG: (*func_p)(im, tmp, q); break; case PHP_GDIMG_TYPE_WBM: - if(q0||q255) { - php_error(E_WARNING, "%s: invalid threshold value '%d'. It must be between 0 and 255",get_active_function_name(), q); + for(i=0; i im-colorsTotal; i++) { + if(im-red[i] == 0) break; } (*func_p)(im, q, tmp); break; @@ -958,54 +967,20 @@ } /* }}} */ -/* {{{ proto int imagewbmp(int im [, string filename]) +/* {{{ proto int imagewbmp(int im [, string filename, [, int foreground]]) Output WBMP image to browser or file */ PHP_FUNCTION(imagewbmp) { +#ifdef HAVE_GD_WBMP #ifdef USE_GD_IOCTX - _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_WBM, "WBMP", _php_image_output_wbmp); + _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_WBM, +"WBMP", gdImageWBMPCtx); #else - _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_WBM, "WBMP", _php_image_output_wbmp); +
[PHP-CVS] cvs: php4 /ext/gd gd.c gd_ctx.c php_gd.h
stasThu Feb 1 07:40:35 2001 EDT Added files: /php4/ext/gdgd_ctx.c Modified files: /php4/ext/gdgd.c php_gd.h Log: Allow usage of GD contexts and not tempfiles in output functions Index: php4/ext/gd/gd.c diff -u php4/ext/gd/gd.c:1.111 php4/ext/gd/gd.c:1.112 --- php4/ext/gd/gd.c:1.111 Sat Jan 27 06:20:06 2001 +++ php4/ext/gd/gd.cThu Feb 1 07:40:34 2001 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: gd.c,v 1.111 2001/01/27 14:20:06 eschmid Exp $ */ +/* $Id: gd.c,v 1.112 2001/02/01 15:40:34 stas Exp $ */ /* gd 1.2 is copyright 1994, 1995, Quest Protein Database Center, Cold Spring Harbor Labs. */ @@ -30,7 +30,6 @@ #include math.h #include "SAPI.h" #include "php_gd.h" -#include "ext/standard/fsock.h" #include "ext/standard/info.h" #if HAVE_SYS_WAIT_H @@ -69,20 +68,26 @@ static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int); #endif -#ifdef GD2_VERS +#if HAVE_LIBGD15 /* it's = 1.5, i.e. has IOCtx */ #define USE_GD_IOCTX 1 #else #undef USE_GD_IOCTX #endif -#ifndef USE_GD_IOCTX +#ifdef USE_GD_IOCTX +#include "gd_ctx.c" +#else #define gdImageCreateFromGifCtx NULL #define gdImageCreateFromJpegCtx NULL #define gdImageCreateFromPngCtx NULL #define gdImageCreateFromWBMPCtx NULL +typedef FILE gdIOCtx; +#define CTX_PUTC(c,fp) fputc(c, fp) #endif +static void _php_image_output_wbmp(gdImagePtr im, gdIOCtx *fp); + #ifdef THREAD_SAFE DWORD GDlibTls; static int numthreads=0; @@ -662,26 +667,24 @@ if(issock socketd) { #ifdef USE_GD_IOCTX gdIOCtx* io_ctx; -#define CHUNK_SIZE 8192 - int read_len=0,buff_len=0,buff_size=5*CHUNK_SIZE; - char *buff,*buff_cur; + int buff_size; + char *buff,*buff_em; - buff = malloc(buff_size); /* Should be malloc! GD uses free */ - buff_cur = buff; + buff_size = php_fread_all(buff_em, socketd, fp, issock); - do { - if(buff_len buff_size - CHUNK_SIZE) { - buff_size += CHUNK_SIZE; - buff = realloc(buff, buff_size); - } - read_len = SOCK_FREAD(buff_cur, CHUNK_SIZE, socketd); - buff_len += read_len; - buff_cur += read_len; - } while(read_len0); + if(!buff_size) { + php_error(E_WARNING,"%s: Cannot read image +data",get_active_function_name()); + RETURN_FALSE; + } + + buff = malloc(buff_size); /* Should be malloc! GD uses free */ + memcpy(buff, buff_em, buff_size); + efree(buff_em); - io_ctx = gdNewDynamicCtx(buff_len,buff); + io_ctx = gdNewDynamicCtx(buff_size,buff); if(!io_ctx) { php_error(E_WARNING,"%s: Cannot allocate GD IO context",get_active_function_name()); + RETURN_FALSE; } im = (*ioctx_func_p)(io_ctx); io_ctx-free(io_ctx); @@ -888,7 +891,11 @@ PHP_FUNCTION(imagegif) { #ifdef HAVE_GD_GIF +#ifdef USE_GD_IOCTX + _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GIF, +"GIF", gdImageGifCtx); +#else _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GIF, "GIF", gdImageGif); +#endif #else /* HAVE_GD_GIF */ php_error(E_WARNING, "ImageGif: No GIF support in this PHP build"); RETURN_FALSE; @@ -901,7 +908,11 @@ PHP_FUNCTION(imagepng) { #ifdef HAVE_GD_PNG +#ifdef USE_GD_IOCTX + _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_PNG, +"PNG", gdImagePngCtx); +#else _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_PNG, "PNG", gdImagePng); +#endif #else /* HAVE_GD_PNG */ php_error(E_WARNING, "ImagePng: No PNG support in this PHP build"); RETURN_FALSE; @@ -915,7 +926,11 @@ PHP_FUNCTION(imagejpeg) { #ifdef HAVE_GD_JPG +#ifdef USE_GD_IOCTX + _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_JPG, +"JPEG", gdImageJpegCtx); +#else _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_JPG, "JPEG", gdImageJpeg); +#endif #else /* HAVE_GD_JPG */ php_error(E_WARNING, "ImageJpeg: No JPG support in this PHP build"); RETURN_FALSE; @@ -927,29 +942,33 @@ Output WBMP image to browser or file */ PHP_FUNCTION(imagewbmp) { +#ifdef USE_GD_IOCTX + _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_WBM, +"WBMP", _php_image_output_wbmp); +#else _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_WBM, "WBMP", _php_image_output_wbmp); +#endif } /* }}} */ /* {{{