summaryrefslogtreecommitdiff
path: root/ext/standard
diff options
context:
space:
mode:
authorMarcus Boerger <helly@php.net>2003-02-01 23:14:13 +0000
committerMarcus Boerger <helly@php.net>2003-02-01 23:14:13 +0000
commit27ccc665181fa0b034a94e80a5fbe1440df2aabe (patch)
treeee7e273226574e68a85895541cb6489eb57589ab /ext/standard
parent895c27d3fceea9a193eeaf5dffbf011daf6d3cb9 (diff)
downloadphp-git-27ccc665181fa0b034a94e80a5fbe1440df2aabe.tar.gz
@Added XBM support for GetImageSize(). (helly)
Diffstat (limited to 'ext/standard')
-rw-r--r--ext/standard/image.c76
-rw-r--r--ext/standard/php_image.h1
2 files changed, 77 insertions, 0 deletions
diff --git a/ext/standard/image.c b/ext/standard/image.c
index d3335decdc..9d810193f9 100644
--- a/ext/standard/image.c
+++ b/ext/standard/image.c
@@ -89,6 +89,7 @@ PHP_MINIT_FUNCTION(imagetypes)
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 @@ static struct gfxinfo *php_handle_wbmp(php_stream * stream TSRMLS_DC)
}
/* }}} */
+/* {{{ 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 @@ PHPAPI const char * php_image_type_to_mime_type(int image_type)
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 @@ PHPAPI int php_getimagetype(php_stream * stream, char *filetype TSRMLS_DC)
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;
}
/* }}} */
@@ -1167,6 +1240,9 @@ PHP_FUNCTION(getimagesize)
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:
break;
diff --git a/ext/standard/php_image.h b/ext/standard/php_image.h
index 462479f97e..4d449b3d14 100644
--- a/ext/standard/php_image.h
+++ b/ext/standard/php_image.h
@@ -48,6 +48,7 @@ typedef enum
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;
/* }}} */