]> granicus.if.org Git - php/commitdiff
fix jp2 detection and add testfile
authorMarcus Boerger <helly@php.net>
Fri, 17 Jan 2003 18:51:30 +0000 (18:51 +0000)
committerMarcus Boerger <helly@php.net>
Fri, 17 Jan 2003 18:51:30 +0000 (18:51 +0000)
ext/standard/image.c
ext/standard/tests/image/image_type_to_mime_type.phpt
ext/standard/tests/image/test1pix.jp2 [new file with mode: 0644]

index b19de960cadccc605d8b5b29a396045de2cb30a4..2b06e0ed39092b8244c6e4fff88ca5c258c83850 100644 (file)
@@ -623,7 +623,7 @@ static struct gfxinfo *php_handle_jpc(php_stream * stream TSRMLS_DC)
 
        result->channels = php_read2(stream TSRMLS_CC); /* Csiz */
 
-       /* Collect and average bit depth info */
+       /* Collect bit depth info */
        highest_bit_depth = bit_depth = 0;
        for (i = 0; i < result->channels; i++) {
                bit_depth = php_stream_getc(stream); /* Ssiz[i] */
@@ -665,11 +665,7 @@ static struct gfxinfo *php_handle_jp2(php_stream *stream TSRMLS_DC)
                box_length = php_read4(stream TSRMLS_CC); /* LBox */
                /* TBox */
                if (php_stream_read(stream, (void *)&box_type, sizeof(box_type)) != sizeof(box_type)) {
-                       break;
-               }
-
-               /* Safe to use the 0 return for EOF as neither of these can be 0 */ 
-               if (box_length == 0 || box_type == 0) {
+                       /* Use this as a general "out of stream" error */
                        break;
                }
 
@@ -1073,9 +1069,6 @@ PHPAPI int php_getimagetype(php_stream * stream, char *filetype TSRMLS_DC)
        if (!memcmp(filetype, php_sig_iff, 4)) {
                return IMAGE_FILETYPE_IFF;
        }
-       if (php_get_wbmp(stream, NULL, 1 TSRMLS_CC)) {
-               return IMAGE_FILETYPE_WBMP;
-       }
 
        if (php_stream_read(stream, filetype+4, 8) != 8) {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Read error!");
@@ -1086,6 +1079,10 @@ PHPAPI int php_getimagetype(php_stream * stream, char *filetype TSRMLS_DC)
                return IMAGE_FILETYPE_JP2;
        }
 
+/* AFTER ALL ABOVE FAILED */
+       if (php_get_wbmp(stream, NULL, 1 TSRMLS_CC)) {
+               return IMAGE_FILETYPE_WBMP;
+       }
        return IMAGE_FILETYPE_UNKNOWN;
 }
 /* }}} */
index da882aae8d806400ab5c514f0d5fa89990e6f6f8..94aabba0b99b10375c19bbc9fde957c7c4b6ebfc 100644 (file)
@@ -25,9 +25,11 @@ image_type_to_mime_type()
        var_dump($result);
 ?>
 --EXPECT--
-array(10) {
+array(11) {
   ["test1pix.bmp"]=>
   string(9) "image/bmp"
+  ["test1pix.jp2"]=>
+  string(9) "image/jp2"
   ["test1pix.jpc"]=>
   string(24) "application/octet-stream"
   ["test1pix.jpg"]=>
diff --git a/ext/standard/tests/image/test1pix.jp2 b/ext/standard/tests/image/test1pix.jp2
new file mode 100644 (file)
index 0000000..8a1172e
Binary files /dev/null and b/ext/standard/tests/image/test1pix.jp2 differ