]> granicus.if.org Git - php/commitdiff
@Added XBM support for GetImageSize(). (helly)
authorMarcus Boerger <helly@php.net>
Sat, 1 Feb 2003 23:14:13 +0000 (23:14 +0000)
committerMarcus Boerger <helly@php.net>
Sat, 1 Feb 2003 23:14:13 +0000 (23:14 +0000)
ext/standard/image.c
ext/standard/php_image.h

index d3335decdc922fc84e0f3f9cd44362dc40fc58be..9d810193f9ccca67da53c2219725a9e532e796e7 100644 (file)
@@ -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;
index 462479f97e78945963e36bb253c63d938c62929c..4d449b3d1416ee77f6ab5a4b15254217a37b4be1 100644 (file)
@@ -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;
 /* }}} */