helly Sat Feb 1 18:14:13 2003 EDT Modified files: /php4/ext/standard image.c php_image.h Log: @Added XBM support for GetImageSize(). (helly) Index: php4/ext/standard/image.c diff -u php4/ext/standard/image.c:1.86 php4/ext/standard/image.c:1.87 --- php4/ext/standard/image.c:1.86 Fri Jan 24 19:23:03 2003 +++ php4/ext/standard/image.c Sat Feb 1 18:14:13 2003 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: image.c,v 1.86 2003/01/25 00:23:03 iliaa Exp $ */ +/* $Id: image.c,v 1.87 2003/02/01 23:14:13 helly Exp $ */ #include "php.h" #include <stdio.h> @@ -89,6 +89,7 @@ REGISTER_LONG_CONSTANT("IMAGETYPE_IFF", IMAGE_FILETYPE_IFF, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("IMAGETYPE_WBMP", IMAGE_FILETYPE_WBMP, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("IMAGETYPE_JPEG2000",IMAGE_FILETYPE_JPC ,CONST_CS | CONST_PERSISTENT);/* keep alias */ + REGISTER_LONG_CONSTANT("IMAGETYPE_XBM", IMAGE_FILETYPE_XBM, CONST_CS | +CONST_PERSISTENT); return SUCCESS; } /* }}} */ @@ -953,6 +954,73 @@ } /* }}} */ +/* {{{ php_get_xbm + */ +#define MAX_XBM_LINE_SIZE 255 +static int php_get_xbm(php_stream *stream, struct gfxinfo **result TSRMLS_DC) +{ + char fline[MAX_XBM_LINE_SIZE]; + char iname[MAX_XBM_LINE_SIZE]; + char *type; + int value, width = 0, height = 0; + + if (result) { + *result = NULL; + } + if (php_stream_rewind(stream)) { + return 0; + } + while (php_stream_gets(stream, fline, MAX_XBM_LINE_SIZE)) { + fline[MAX_XBM_LINE_SIZE-1] = '\0'; + if (strlen(fline) == MAX_XBM_LINE_SIZE-1) { + return 0; + } + + if (sscanf(fline, "#define %s %d", iname, &value) == 2) { + if (!(type = strrchr(iname, '_'))) { + type = iname; + } else { + type++; + } + + if (!strcmp("width", type)) { + width = (unsigned int) value; + if (height) { + break; + } + } + if (!strcmp("height", type)) { + height = (unsigned int) value; + if (width) { + break; + } + } + } + } + + if (width && height) { + if (result) { + *result = (struct gfxinfo *) ecalloc(1, sizeof(struct +gfxinfo)); + (*result)->width = width; + (*result)->height = height; + } + return IMAGE_FILETYPE_XBM; + } + + return 0; +} +/* }}} */ + +/* {{{ php_handle_xbm + */ +static struct gfxinfo *php_handle_xbm(php_stream * stream TSRMLS_DC) +{ + struct gfxinfo *result; + php_get_xbm(stream, &result TSRMLS_CC); + return result; +} +/* }}} */ + /* {{{ php_image_type_to_mime_type * Convert internal image_type to mime type */ PHPAPI const char * php_image_type_to_mime_type(int image_type) @@ -982,6 +1050,8 @@ return "application/octet-stream"; case IMAGE_FILETYPE_JP2: return "image/jp2"; + case IMAGE_FILETYPE_XBM: + return "image/xbm"; default: case IMAGE_FILETYPE_UNKNOWN: return "application/octet-stream"; /* suppose binary format */ @@ -1073,6 +1143,9 @@ if (php_get_wbmp(stream, NULL, 1 TSRMLS_CC)) { return IMAGE_FILETYPE_WBMP; } + if (php_get_xbm(stream, NULL TSRMLS_CC)) { + return IMAGE_FILETYPE_XBM; + } return IMAGE_FILETYPE_UNKNOWN; } /* }}} */ @@ -1166,6 +1239,9 @@ break; case IMAGE_FILETYPE_WBMP: result = php_handle_wbmp(stream TSRMLS_CC); + break; + case IMAGE_FILETYPE_XBM: + result = php_handle_xbm(stream TSRMLS_CC); break; default: case IMAGE_FILETYPE_UNKNOWN: Index: php4/ext/standard/php_image.h diff -u php4/ext/standard/php_image.h:1.22 php4/ext/standard/php_image.h:1.23 --- php4/ext/standard/php_image.h:1.22 Thu Jan 16 14:45:26 2003 +++ php4/ext/standard/php_image.h Sat Feb 1 18:14:13 2003 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_image.h,v 1.22 2003/01/16 19:45:26 helly Exp $ */ +/* $Id: php_image.h,v 1.23 2003/02/01 23:14:13 helly Exp $ */ #ifndef PHP_IMAGE_H #define PHP_IMAGE_H @@ -48,6 +48,7 @@ IMAGE_FILETYPE_IFF, IMAGE_FILETYPE_WBMP, /* IMAGE_FILETYPE_JPEG2000 is a userland alias for IMAGE_FILETYPE_JPC */ + IMAGE_FILETYPE_XBM, /* WHEN EXTENDING: PLEASE ALSO REGISTER IN image.c:PHP_MINIT_FUNCTION(imagetypes) */ } image_filetype; /* }}} */
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php