helly Sun Jun 15 16:00:09 2003 EDT Modified files: /php4/ext/gd gd.c gd_ctx.c php_gd.h /php4/ext/gd/libgd gd.h xbm.c Log: Add ImageXBM
Index: php4/ext/gd/gd.c diff -u php4/ext/gd/gd.c:1.273 php4/ext/gd/gd.c:1.274 --- php4/ext/gd/gd.c:1.273 Sun Jun 15 11:22:09 2003 +++ php4/ext/gd/gd.c Sun Jun 15 16:00:08 2003 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: gd.c,v 1.273 2003/06/15 15:22:09 andrey Exp $ */ +/* $Id: gd.c,v 1.274 2003/06/15 20:00:08 helly Exp $ */ /* gd 1.2 is copyright 1994, 1995, Quest Protein Database Center, Cold Spring Harbor Labs. */ @@ -306,6 +306,7 @@ #if HAVE_GD_BUNDLED PHP_FE(imagelayereffect, NULL) PHP_FE(imagecolormatch, NULL) + PHP_FE(imagexbm, NULL) #endif /* gd filters */ #ifdef HAVE_GD_BUNDLED @@ -1780,6 +1781,16 @@ } RETURN_TRUE; } +/* }}} */ + +/* {{{ proto int imagexbm(int im, string filename [, int foreground]) + Output XBM image to browser or file */ +#if HAVE_GD_BUNDLED +PHP_FUNCTION(imagexbm) +{ + _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_XBM, "XBM", gdImageXbmCtx); +} +#endif /* }}} */ #ifdef HAVE_GD_GIF_CREATE Index: php4/ext/gd/gd_ctx.c diff -u php4/ext/gd/gd_ctx.c:1.16 php4/ext/gd/gd_ctx.c:1.17 --- php4/ext/gd/gd_ctx.c:1.16 Tue Mar 11 23:15:28 2003 +++ php4/ext/gd/gd_ctx.c Sun Jun 15 16:00:08 2003 @@ -1,5 +1,24 @@ -#include "php_gd.h" +/* + +----------------------------------------------------------------------+ + | PHP Version 4 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2003 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.0 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_0.txt. | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | [EMAIL PROTECTED] so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Stanislav Malyshev <[EMAIL PROTECTED]> | + +----------------------------------------------------------------------+ + */ + +/* $Id: gd_ctx.c,v 1.17 2003/06/15 20:00:08 helly Exp $ */ +#include "php_gd.h" #define CTX_PUTC(c,ctx) ctx->putC(ctx, c) @@ -21,7 +40,8 @@ efree(ctx); } } - + +/* {{{ _php_image_output_ctx */ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, void (*func_p)()) { zval **imgind, **file, **quality; @@ -32,8 +52,14 @@ int q = -1, i; gdIOCtx *ctx; - /* The quality parameter for Wbmp stands for the threshold when called from image2wbmp() */ + /* The third (quality) parameter for Wbmp stands for the threshold when called from image2wbmp(). + * The third (quality) parameter for Wbmp and Xbm stands for the foreground color index when called + * from imagey<type>(). + */ + if (argc < 2 && image_type == PHP_GDIMG_TYPE_XBM) { + WRONG_PARAM_COUNT; + } if (argc < 1 || argc > 3 || zend_get_parameters_ex(argc, &imgind, &file, &quality) == FAILURE) { WRONG_PARAM_COUNT; @@ -46,7 +72,7 @@ fn = Z_STRVAL_PP(file); if (argc == 3) { convert_to_long_ex(quality); - q = Z_LVAL_PP(quality); + q = Z_LVAL_PP(quality);/* or colorindex for foreground of BW images (defaults to black) */ } } @@ -88,11 +114,19 @@ case PHP_GDIMG_TYPE_JPG: (*func_p)(im, ctx, q); break; + case PHP_GDIMG_TYPE_XBM: case PHP_GDIMG_TYPE_WBM: - for(i=0; i < gdImageColorsTotal(im); i++) { - if(gdImageRed(im, i) == 0) break; - } - (*func_p)(im, i, ctx); + if (argc < 3) { + for(i=0; i < gdImageColorsTotal(im); i++) { + if(!gdImageRed(im, i) && !gdImageGreen(im, i) && !gdImageBlue(im, i)) break; + } + q = i; + } + if (image_type == PHP_GDIMG_TYPE_XBM) { + (*func_p)(im, fn, q, ctx); + } else { + (*func_p)(im, q, ctx); + } break; default: (*func_p)(im, ctx); @@ -112,3 +146,13 @@ RETURN_TRUE; } +/* }}} */ + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: sw=4 ts=4 fdm=marker + * vim<600: sw=4 ts=4 + */ Index: php4/ext/gd/php_gd.h diff -u php4/ext/gd/php_gd.h:1.55 php4/ext/gd/php_gd.h:1.56 --- php4/ext/gd/php_gd.h:1.55 Tue Jun 10 16:03:29 2003 +++ php4/ext/gd/php_gd.h Sun Jun 15 16:00:08 2003 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_gd.h,v 1.55 2003/06/10 20:03:29 imajes Exp $ */ +/* $Id: php_gd.h,v 1.56 2003/06/15 20:00:08 helly Exp $ */ #ifndef PHP_GD_H #define PHP_GD_H @@ -175,6 +175,7 @@ PHP_FUNCTION(imagelayereffect); PHP_FUNCTION(imagecolormatch); PHP_FUNCTION(imagefilter); +PHP_FUNCTION(imagexbm); #endif PHP_GD_API int phpi_get_le_gd(void); Index: php4/ext/gd/libgd/gd.h diff -u php4/ext/gd/libgd/gd.h:1.17 php4/ext/gd/libgd/gd.h:1.18 --- php4/ext/gd/libgd/gd.h:1.17 Tue Apr 8 21:55:48 2003 +++ php4/ext/gd/libgd/gd.h Sun Jun 15 16:00:08 2003 @@ -256,6 +256,7 @@ gdImagePtr gdImageCreateFromGd2PartCtx(gdIOCtxPtr in, int srcx, int srcy, int w, int h); gdImagePtr gdImageCreateFromXbm(FILE *fd); +void gdImageXbmCtx(gdImagePtr image, char* file_name, int fg, gdIOCtx * out); gdImagePtr gdImageCreateFromXpm (char *filename); Index: php4/ext/gd/libgd/xbm.c diff -u php4/ext/gd/libgd/xbm.c:1.3 php4/ext/gd/libgd/xbm.c:1.4 --- php4/ext/gd/libgd/xbm.c:1.3 Tue Jun 10 16:03:29 2003 +++ php4/ext/gd/libgd/xbm.c Sun Jun 15 16:00:08 2003 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: xbm.c,v 1.3 2003/06/10 20:03:29 imajes Exp $ */ +/* $Id: xbm.c,v 1.4 2003/06/15 20:00:08 helly Exp $ */ #include <stdio.h> #include <math.h> @@ -29,8 +29,8 @@ #define MAX_XBM_LINE_SIZE 255 -gdImagePtr -gdImageCreateFromXbm (FILE * fd) +/* {{{ gdImagePtr gdImageCreateFromXbm */ +gdImagePtr gdImageCreateFromXbm(FILE * fd) { char fline[MAX_XBM_LINE_SIZE]; char iname[MAX_XBM_LINE_SIZE]; @@ -151,3 +151,89 @@ gdImageDestroy(im); return 0; } +/* }}} */ + +/* {{{ gdCtxPrintf */ +void gdCtxPrintf(gdIOCtx * out, const char *format, ...) +{ + char *buf; + int len; + va_list args; + + va_start(args, format); + len = vspprintf(&buf, 0, format, args); + va_end(args); + out->putBuf(out, buf, len); + efree(buf); +} +/* }}} */ + +/* {{{ gdImageXbmCtx */ +void gdImageXbmCtx(gdImagePtr image, char* file_name, int fg, gdIOCtx * out) +{ + int x, y, c, b, sx, sy, p; + char *name, *f; + size_t i, l; + + name = file_name; + if ((f = strrchr(name, '/')) != NULL) name = f+1; + if ((f = strrchr(name, '\\')) != NULL) name = f+1; + name = estrdup(name); + if ((f = strrchr(name, '.')) != NULL && !strcasecmp(f, ".XBM")) *f = '\0'; + if ((l = strlen(name)) == 0) { + efree(name); + name = estrdup("image"); + } else { + for (i=0; i<l; i++) { + /* only in C-locale isalnum() would work */ + if (!isupper(name[i]) && !islower(name[i]) && !isdigit(name[i])) { + name[i] = '_'; + } + } + } + + gdCtxPrintf(out, "#define %s_width %d\n", name, gdImageSX(image)); + gdCtxPrintf(out, "#define %s_height %d\n", name, gdImageSY(image)); + gdCtxPrintf(out, "static unsigned char %s_bits[] = {\n ", name); + + efree(name); + + b = 1; + p = 0; + c = 0; + sx = gdImageSX(image); + sy = gdImageSY(image); + for (y = 0; y < sy; y++) { + for (x = 0; x < sx; x++) { + if (gdImageGetPixel(image, x, y) == fg) { + c |= b; + } + if ((b == 128) || (x == sx && y == sy)) { + b = 1; + if (p) { + gdCtxPrintf(out, ", "); + if (!(p%12)) { + gdCtxPrintf(out, "\n "); + p = 12; + } + } + p++; + gdCtxPrintf(out, "0x%02X", c); + c = 0; + } else { + b <<= 1; + } + } + } + gdCtxPrintf(out, "};\n"); +} +/* }}} */ + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: sw=4 ts=4 fdm=marker + * vim<600: sw=4 ts=4 + */
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php