sniper Sat Mar 31 21:42:07 2001 EDT Modified files: /php4/ext/gd gd.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.c Sat 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(q<0||q>255) { + 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(q<0||q>255) { - 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(q<0||q>255) { + 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(q<0||q>255) { - 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_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_WBM, +"WBMP", gdImageWBMP); #endif -} -/* }}} */ - -/* {{{ _php_image_output_wbmp(gdImagePtr im, FILE *fp) - */ -static void _php_image_output_wbmp(gdImagePtr im, gdIOCtx *fp) -{ - int x, y; - int c, p, width, height; - - /* WBMP header, black and white, no compression */ - CTX_PUTC(0,fp); CTX_PUTC(0,fp); - - /* Width and height of image */ - c = 1; width = im->sx; - while(width & 0x7f << 7*c) c++; - while(c > 1) CTX_PUTC(0x80 | ((width >> 7*--c) & 0xff), fp); - CTX_PUTC(width & 0x7f,fp); - c = 1; height = im->sy; - while(height & 0x7f << 7*c) c++; - while(c > 1) CTX_PUTC(0x80 | ((height >> 7*--c) & 0xff), fp); - CTX_PUTC(height & 0x7f,fp); - - /* Actual image data */ - for(y = 0; y < im->sy; y++) { - p = c = 0; - for(x = 0; x < im->sx; x++) { -#if HAVE_GD_ANCIENT - if(im->pixels[x][y] == 0) c = c | (1 << (7-p)); -#else - if(im->pixels[y][x] == 0) c = c | (1 << (7-p)); -#endif - if(++p == 8) { - CTX_PUTC(c,fp); - p = c = 0; - } - } - if(p) CTX_PUTC(c,fp); - } +#else /* HAVE_GD_WBMP */ + php_error(E_WARNING, "ImageWBMP: No WBMP support in this PHP build"); + RETURN_FALSE; +#endif /* HAVE_GD_WBMP */ } /* }}} */ @@ -2690,7 +2665,7 @@ PHP_FUNCTION(image2wbmp) { #ifdef HAVE_GD_WBMP - _php_image_output (INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_WBM, "WBMP", _php_image_bw_convert); + _php_image_output (INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_CONVERT_WBM, +"WBMP", _php_image_bw_convert); #else /* HAVE_GD_WBMP */ php_error(E_WARNING, "Image2Wbmp: No WBMP support in this PHP build"); RETURN_FALSE; @@ -2738,7 +2713,8 @@ #ifdef HAVE_GD_WBMP /* It converts a gd Image to bw using a threshold value */ -static void _php_image_bw_convert( gdImagePtr im_org, int threshold, FILE *out) { +static void _php_image_bw_convert( gdImagePtr im_org, gdIOCtx *out, int threshold) +{ gdImagePtr im_dest; int white, black; int color, color_org, median; @@ -2776,10 +2752,13 @@ gdImageSetPixel (im_dest, x, y, color); } } - +#ifdef USE_GD_IOCTX + gdImageWBMPCtx (im_dest, black, out); +#else gdImageWBMP (im_dest, black, out); -} +#endif +} /* _php_image_convert converts jpeg/png images to wbmp and resizes them as needed */ static void _php_image_convert(INTERNAL_FUNCTION_PARAMETERS, int image_type ) { @@ -2792,8 +2771,6 @@ int dest_height = -1; int dest_width = -1; int org_height, org_width; - int output = 1; - int q = -1; int white, black; int color, color_org, median; int int_threshold; Index: php4/ext/gd/gd_ctx.c diff -u php4/ext/gd/gd_ctx.c:1.2 php4/ext/gd/gd_ctx.c:1.3 --- php4/ext/gd/gd_ctx.c:1.2 Thu Feb 15 06:48:56 2001 +++ php4/ext/gd/gd_ctx.c Sat Mar 31 21:42:07 2001 @@ -24,13 +24,12 @@ char *fn = NULL; FILE *fp = NULL; int argc = ZEND_NUM_ARGS(); - int q = -1; + int q = -1, i; gdIOCtx *ctx; 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() */ + if (argc < 1 || argc > 3 || zend_get_parameters_ex(argc, &imgind, &file, &quality) == FAILURE) { WRONG_PARAM_COUNT; @@ -75,14 +74,19 @@ } switch(image_type) { + case PHP_GDIMG_CONVERT_WBM: + if(q<0||q>255) { + 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, ctx, q); break; case PHP_GDIMG_TYPE_WBM: - if(q<0||q>255) { - php_error(E_WARNING, "%s: invalid threshold value '%d'. It must be between 0 and 255",get_active_function_name(), q); - } - /* break missing intentionally */ + for(i=0; i < im->colorsTotal; i++) { + if(im->red[i] == 0) break; + } + (*func_p)(im, i, ctx); + break; default: (*func_p)(im, ctx); break; Index: php4/ext/gd/php_gd.h diff -u php4/ext/gd/php_gd.h:1.24 php4/ext/gd/php_gd.h:1.25 --- php4/ext/gd/php_gd.h:1.24 Sun Feb 25 22:06:56 2001 +++ php4/ext/gd/php_gd.h Sat Mar 31 21:42:07 2001 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_gd.h,v 1.24 2001/02/26 06:06:56 andi Exp $ */ +/* $Id: php_gd.h,v 1.25 2001/04/01 05:42:07 sniper Exp $ */ #ifndef PHP_GD_H #define PHP_GD_H @@ -42,6 +42,7 @@ #define PHP_GDIMG_TYPE_WBM 4 #define PHP_GDIMG_TYPE_XBM 5 #define PHP_GDIMG_TYPE_XPM 6 +#define PHP_GDIMG_CONVERT_WBM 7 #ifdef PHP_WIN32 #define PHP_GD_API __declspec(dllexport) @@ -146,9 +147,7 @@ gdImagePtr _php_image_create_from_string ( zval **Data, char *tn, gdImagePtr (*ioctx_func_p)() ); static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, gdImagePtr (*func_p)(), gdImagePtr (*ioctx_func_p)()); static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, void (*func_p)()); -/* static void _php_image_output_wbmp(gdImagePtr im, FILE *fp); */ static int _php_image_type ( char data[8] ); -static void _php_image_bw_convert( gdImagePtr im_org, int threshold, FILE *out ); static void _php_image_convert(INTERNAL_FUNCTION_PARAMETERS, int image_type); PHPAPI int phpi_get_le_gd(void);
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]