[PHP-CVS] cvs: php4 /ext/standard image.c

2003-02-14 Thread Marcus Boerger
helly   Fri Feb 14 14:43:07 2003 EDT

  Modified files:  
/php4/ext/standard  image.c 
  Log:
  a little bit slower but somewhat tricky and more flexible and it does not 
  allocate static buffers anymore
  
Index: php4/ext/standard/image.c
diff -u php4/ext/standard/image.c:1.90 php4/ext/standard/image.c:1.91
--- php4/ext/standard/image.c:1.90  Thu Feb 13 02:02:53 2003
+++ php4/ext/standard/image.c   Fri Feb 14 14:43:06 2003
@@ -17,7 +17,7 @@
+--+
  */
 
-/* $Id: image.c,v 1.90 2003/02/13 07:02:53 sniper Exp $ */
+/* $Id: image.c,v 1.91 2003/02/14 19:43:06 helly Exp $ */
 
 #include php.h
 #include stdio.h
@@ -956,11 +956,10 @@
 
 /* {{{ 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 *fline;
+char *iname;
 char *type;
 int value;
 unsigned int width = 0, height = 0;
@@ -971,12 +970,8 @@
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;
-   }
-   
+   while ((fline=php_stream_gets(stream, NULL, 0)) != NULL) {
+   iname = estrdup(fline); /* simple way to get necessary buffer of 
+required size */
if (sscanf(fline, #define %s %d, iname, value) == 2) {
if (!(type = strrchr(iname, '_'))) {
type = iname;
@@ -987,16 +982,23 @@
if (!strcmp(width, type)) {
width = (unsigned int) value;
if (height) {
+   efree(iname);
break;
}
}
if (!strcmp(height, type)) {
height = (unsigned int) value;
if (width) {
+   efree(iname);
break;
}
}
}
+   efree(fline);
+   efree(iname);
+   }
+   if (fline) {
+   efree(fline);
}
 
if (width  height) {



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-CVS] cvs: php4 /ext/standard image.c

2003-02-12 Thread Jani Taskinen
sniper  Thu Feb 13 02:02:53 2003 EDT

  Modified files:  
/php4/ext/standard  image.c 
  Log:
  ws fix
  
Index: php4/ext/standard/image.c
diff -u php4/ext/standard/image.c:1.89 php4/ext/standard/image.c:1.90
--- php4/ext/standard/image.c:1.89  Sun Feb  9 14:09:51 2003
+++ php4/ext/standard/image.c   Thu Feb 13 02:02:53 2003
@@ -17,7 +17,7 @@
+--+
  */
 
-/* $Id: image.c,v 1.89 2003/02/09 19:09:51 sniper Exp $ */
+/* $Id: image.c,v 1.90 2003/02/13 07:02:53 sniper Exp $ */
 
 #include php.h
 #include stdio.h
@@ -79,7 +79,7 @@
REGISTER_LONG_CONSTANT(IMAGETYPE_BMP, IMAGE_FILETYPE_BMP, CONST_CS | 
CONST_PERSISTENT);
REGISTER_LONG_CONSTANT(IMAGETYPE_TIFF_II, IMAGE_FILETYPE_TIFF_II, CONST_CS | 
CONST_PERSISTENT);
REGISTER_LONG_CONSTANT(IMAGETYPE_TIFF_MM, IMAGE_FILETYPE_TIFF_MM, CONST_CS | 
CONST_PERSISTENT);
-   REGISTER_LONG_CONSTANT(IMAGETYPE_JPC, IMAGE_FILETYPE_JPC ,CONST_CS | 
CONST_PERSISTENT);
+   REGISTER_LONG_CONSTANT(IMAGETYPE_JPC, IMAGE_FILETYPE_JPC, CONST_CS | 
+CONST_PERSISTENT);
REGISTER_LONG_CONSTANT(IMAGETYPE_JP2, IMAGE_FILETYPE_JP2, CONST_CS | 
CONST_PERSISTENT);
REGISTER_LONG_CONSTANT(IMAGETYPE_JPX, IMAGE_FILETYPE_JPX, CONST_CS | 
CONST_PERSISTENT);
REGISTER_LONG_CONSTANT(IMAGETYPE_JB2, IMAGE_FILETYPE_JB2, CONST_CS | 
CONST_PERSISTENT);
@@ -88,7 +88,7 @@
 #endif 
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_JPEG2000,IMAGE_FILETYPE_JPC, CONST_CS | 
+CONST_PERSISTENT); /* keep alias */
REGISTER_LONG_CONSTANT(IMAGETYPE_XBM, IMAGE_FILETYPE_XBM, CONST_CS | 
CONST_PERSISTENT);
return SUCCESS;
 }



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-CVS] cvs: php4 /ext/standard image.c php_image.h

2003-02-01 Thread Marcus Boerger
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-CVS] cvs: php4 /ext/standard image.c

2003-02-01 Thread Marcus Boerger
helly   Sat Feb  1 18:38:29 2003 EDT

  Modified files:  
/php4/ext/standard  image.c 
  Log:
  avoid warnings
  
Index: php4/ext/standard/image.c
diff -u php4/ext/standard/image.c:1.87 php4/ext/standard/image.c:1.88
--- php4/ext/standard/image.c:1.87  Sat Feb  1 18:14:13 2003
+++ php4/ext/standard/image.c   Sat Feb  1 18:38:29 2003
@@ -17,7 +17,7 @@
+--+
  */
 
-/* $Id: image.c,v 1.87 2003/02/01 23:14:13 helly Exp $ */
+/* $Id: image.c,v 1.88 2003/02/01 23:38:29 helly Exp $ */
 
 #include php.h
 #include stdio.h
@@ -962,7 +962,8 @@
 char fline[MAX_XBM_LINE_SIZE];
 char iname[MAX_XBM_LINE_SIZE];
 char *type;
-int value, width = 0, height = 0;
+int value;
+unsigned int width = 0, height = 0;
 
if (result) {
*result = NULL;



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-CVS] cvs: php4 /ext/standard image.c

2003-01-24 Thread Ilia Alshanetsky
iliaa   Fri Jan 24 19:23:03 2003 EDT

  Modified files:  
/php4/ext/standard  image.c 
  Log:
  Fixed compiler warning.
  
  
Index: php4/ext/standard/image.c
diff -u php4/ext/standard/image.c:1.85 php4/ext/standard/image.c:1.86
--- php4/ext/standard/image.c:1.85  Sat Jan 18 15:01:43 2003
+++ php4/ext/standard/image.c   Fri Jan 24 19:23:03 2003
@@ -17,7 +17,7 @@
+--+
  */
 
-/* $Id: image.c,v 1.85 2003/01/18 20:01:43 iliaa Exp $ */
+/* $Id: image.c,v 1.86 2003/01/25 00:23:03 iliaa Exp $ */
 
 #include php.h
 #include stdio.h
@@ -579,7 +579,7 @@
unsigned short dummy_short;
int dummy_int, highest_bit_depth, bit_depth;
unsigned char first_marker_id;
-   int i;
+   unsigned int i;
 
/* JPEG 2000 components can be vastly different from one another.
   Each component can be sampled at a different resolution, use



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-CVS] cvs: php4 /ext/standard image.c /ext/standard/tests/image image_type_to_mime_type.phpt test1pix.jp2

2003-01-17 Thread Marcus Boerger
helly   Fri Jan 17 13:51:31 2003 EDT

  Added files: 
/php4/ext/standard/tests/image  test1pix.jp2 

  Modified files:  
/php4/ext/standard  image.c 
/php4/ext/standard/tests/image  image_type_to_mime_type.phpt 
  Log:
  fix jp2 detection and add testfile
  
Index: php4/ext/standard/image.c
diff -u php4/ext/standard/image.c:1.83 php4/ext/standard/image.c:1.84
--- php4/ext/standard/image.c:1.83  Thu Jan 16 14:45:26 2003
+++ php4/ext/standard/image.c   Fri Jan 17 13:51:30 2003
@@ -17,7 +17,7 @@
+--+
  */
 
-/* $Id: image.c,v 1.83 2003/01/16 19:45:26 helly Exp $ */
+/* $Id: image.c,v 1.84 2003/01/17 18:51:30 helly Exp $ */
 
 #include php.h
 #include stdio.h
@@ -623,7 +623,7 @@
 
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 @@
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 @@
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 @@
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: php4/ext/standard/tests/image/image_type_to_mime_type.phpt
diff -u php4/ext/standard/tests/image/image_type_to_mime_type.phpt:1.4 
php4/ext/standard/tests/image/image_type_to_mime_type.phpt:1.5
--- php4/ext/standard/tests/image/image_type_to_mime_type.phpt:1.4  Thu Jan 16 
14:46:12 2003
+++ php4/ext/standard/tests/image/image_type_to_mime_type.phpt  Fri Jan 17 13:51:30 
+2003
@@ -25,9 +25,11 @@
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]=

Index: php4/ext/standard/tests/image/test1pix.jp2
+++ php4/ext/standard/tests/image/test1pix.jp2
jP  
‡
ftypjp2 jp2 
-jp2hihdrcolrjp2cÿOÿQ/ÿR
ÿ\#wwwvâoonâgLgLgdPPPEWÒWÒWaÿdKakadu-3.0.7ÿ
$ÿ“ßð‹€ÿÙ


-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-CVS] cvs: php4 /ext/standard image.c php_image.h

2003-01-16 Thread Marcus Boerger
helly   Thu Jan 16 14:45:27 2003 EDT

  Modified files:  
/php4/ext/standard  image.c php_image.h 
  Log:
  - corrected error in file detection for very small files
  - JPEG 2000 support, mostly Adam Wright [EMAIL PROTECTED]
  @Enhanced jpeg 2000 support for GetImageSize(). (marcus, Adam Wright)
  
Index: php4/ext/standard/image.c
diff -u php4/ext/standard/image.c:1.82 php4/ext/standard/image.c:1.83
--- php4/ext/standard/image.c:1.82  Wed Jan  8 19:15:33 2003
+++ php4/ext/standard/image.c   Thu Jan 16 14:45:26 2003
@@ -17,7 +17,7 @@
+--+
  */
 
-/* $Id: image.c,v 1.82 2003/01/09 00:15:33 sniper Exp $ */
+/* $Id: image.c,v 1.83 2003/01/16 19:45:26 helly Exp $ */
 
 #include php.h
 #include stdio.h
@@ -46,10 +46,13 @@
 PHPAPI const char php_sig_swc[3] = {'C', 'W', 'S'};
 PHPAPI const char php_sig_jpg[3] = {(char) 0xff, (char) 0xd8, (char) 0xff};
 PHPAPI const char php_sig_png[8] = {(char) 0x89, (char) 0x50, (char) 0x4e, (char) 
0x47,
-(char) 0x0d, (char) 0x0a, (char) 0x1a, (char) 0x0a};
+(char) 0x0d, (char) 0x0a, (char) 0x1a, (char) 
+0x0a};
 PHPAPI const char php_sig_tif_ii[4] = {'I','I', (char)0x2A, (char)0x00};
 PHPAPI const char php_sig_tif_mm[4] = {'M','M', (char)0x00, (char)0x2A};
-PHPAPI const char php_sig_jpc[3] = {(char)0xFF, (char)0x4F, (char)0xff};
+PHPAPI const char php_sig_jpc[3]  = {(char)0xff, (char)0x4f, (char)0xff};
+PHPAPI const char php_sig_jp2[12] = {(char)0x00, (char)0x00, (char)0x00, (char)0x0c,
+ (char)0x6a, (char)0x50, (char)0x20, (char)0x20,
+ (char)0x0d, (char)0x0a, (char)0x87, (char)0x0a};
 PHPAPI const char php_sig_iff[4] = {'F','O','R','M'};
 
 /* REMEMBER TO ADD MIME-TYPE TO FUNCTION php_image_type_to_mime_type */
@@ -76,7 +79,7 @@
REGISTER_LONG_CONSTANT(IMAGETYPE_BMP, IMAGE_FILETYPE_BMP, CONST_CS | 
CONST_PERSISTENT);
REGISTER_LONG_CONSTANT(IMAGETYPE_TIFF_II, IMAGE_FILETYPE_TIFF_II, CONST_CS | 
CONST_PERSISTENT);
REGISTER_LONG_CONSTANT(IMAGETYPE_TIFF_MM, IMAGE_FILETYPE_TIFF_MM, CONST_CS | 
CONST_PERSISTENT);
-   REGISTER_LONG_CONSTANT(IMAGETYPE_JPC, IMAGE_FILETYPE_JPC, CONST_CS | 
CONST_PERSISTENT);
+   REGISTER_LONG_CONSTANT(IMAGETYPE_JPC, IMAGE_FILETYPE_JPC ,CONST_CS | 
+CONST_PERSISTENT);
REGISTER_LONG_CONSTANT(IMAGETYPE_JP2, IMAGE_FILETYPE_JP2, CONST_CS | 
CONST_PERSISTENT);
REGISTER_LONG_CONSTANT(IMAGETYPE_JPX, IMAGE_FILETYPE_JPX, CONST_CS | 
CONST_PERSISTENT);
REGISTER_LONG_CONSTANT(IMAGETYPE_JB2, IMAGE_FILETYPE_JB2, CONST_CS | 
CONST_PERSISTENT);
@@ -85,6 +88,7 @@
 #endif 
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 */
return SUCCESS;
 }
 /* }}} */
@@ -534,12 +538,6 @@
 }
 /* }}} */
 
-/* {{{ jpeg2000 constants
-  See ext/exif for more */
-#define JC_SOC   0x4F  /* Start of codestream */
-#define JC_SIZ   0x51  /* Image and tile size */
-/* }}} */
-
 /* {{{ php_read4
  */
 static unsigned int php_read4(php_stream * stream TSRMLS_DC)
@@ -556,37 +554,147 @@
 }
 /* }}} */
 
-/* {{{ php_handle_tiff
-   main loop to parse TIFF structure */
+/* {{{ JPEG 2000 Marker Codes */
+#define JPEG2000_MARKER_PREFIX 0xFF /* All marker codes start with this */
+#define JPEG2000_MARKER_SOC 0x4F /* Start of Codestream */
+#define JPEG2000_MARKER_SOT 0x90 /* Start of Tile part */
+#define JPEG2000_MARKER_SOD 0x93 /* Start of Data */
+#define JPEG2000_MARKER_EOC 0xD9 /* End of Codestream */
+#define JPEG2000_MARKER_SIZ 0x51 /* Image and tile size */
+#define JPEG2000_MARKER_COD 0x52 /* Coding style default */ 
+#define JPEG2000_MARKER_COC 0x53 /* Coding style component */
+#define JPEG2000_MARKER_RGN 0x5E /* Region of interest */
+#define JPEG2000_MARKER_QCD 0x5C /* Quantization default */
+#define JPEG2000_MARKER_QCC 0x5D /* Quantization component */
+#define JPEG2000_MARKER_POC 0x5F /* Progression order change */
+#define JPEG2000_MARKER_TLM 0x55 /* Tile-part lengths */
+#define JPEG2000_MARKER_PLM 0x57 /* Packet length, main header */
+#define JPEG2000_MARKER_PLT 0x58 /* Packet length, tile-part header */
+#define JPEG2000_MARKER_PPM 0x60 /* Packed packet headers, main header */
+#define JPEG2000_MARKER_PPT 0x61 /* Packed packet headers, tile part header */
+#define JPEG2000_MARKER_SOP 0x91 /* Start of packet */
+#define JPEG2000_MARKER_EPH 0x92 /* End of packet header */
+#define JPEG2000_MARKER_CRG 0x63 /* Component registration */
+#define JPEG2000_MARKER_COM 0x64 /* Comment */
+/* }}} */
+
+/* {{{ php_handle_jpc
+   Main loop to parse JPEG2000 raw codestream structure */
 

[PHP-CVS] cvs: php4 /ext/standard image.c php_image.h

2003-01-08 Thread Ilia Alshanetsky
iliaa   Wed Jan  8 15:36:03 2003 EDT

  Modified files:  
/php4/ext/standard  image.c php_image.h 
  Log:
  Added support for WBMP images.
  
  
Index: php4/ext/standard/image.c
diff -u php4/ext/standard/image.c:1.80 php4/ext/standard/image.c:1.81
--- php4/ext/standard/image.c:1.80  Tue Dec 31 11:07:42 2002
+++ php4/ext/standard/image.c   Wed Jan  8 15:36:03 2003
@@ -17,7 +17,7 @@
+--+
  */
 
-/* $Id: image.c,v 1.80 2002/12/31 16:07:42 sebastian Exp $ */
+/* $Id: image.c,v 1.81 2003/01/08 20:36:03 iliaa Exp $ */
 
 #include php.h
 #include stdio.h
@@ -84,6 +84,7 @@
REGISTER_LONG_CONSTANT(IMAGETYPE_SWC, IMAGE_FILETYPE_SWC, CONST_CS | 
CONST_PERSISTENT);
 #endif 
REGISTER_LONG_CONSTANT(IMAGETYPE_IFF, IMAGE_FILETYPE_IFF, CONST_CS | 
CONST_PERSISTENT);
+   REGISTER_LONG_CONSTANT(IMAGETYPE_WBMP,IMAGE_FILETYPE_WBMP,CONST_CS | 
+CONST_PERSISTENT);
return SUCCESS;
 }
 /* }}} */
@@ -786,6 +787,78 @@
 }
 /* }}} */
 
+/* {{{ php_get_wbmp
+ * int WBMP file format type
+ * byte Header Type
+ * byte Extended Header
+ * byte Header Data (type 00 = multibyte)
+ * byte Header Data (type 11 = name/pairs)
+ * int Number of columns
+ * int Number of rows
+ */
+static int php_get_wbmp(php_stream *stream, struct gfxinfo **result, int check 
+TSRMLS_DC)
+{
+   int i, width = 0, height = 0;
+
+   if (php_stream_rewind(stream)) {
+   return 0;
+   }
+
+   /* get type */
+   if (php_stream_getc(stream) != 0) {
+   return 0;
+   }
+
+   /* skip header */
+   do {
+   i = php_stream_getc(stream);
+   if (i  0) {
+   return 0;
+   }
+   } while (i  0x80);
+
+   /* get width */
+   do {
+   i = php_stream_getc(stream);
+   if (i  0) {
+   return 0;
+   }
+   width = (width  7) | (i  0x7f);
+   } while (i  0x80);
+   
+   /* get height */
+   do {
+   i = php_stream_getc(stream);
+   if (i  0) {
+   return 0;
+   }
+   height = (height  7) | (i  0x7f);
+   } while (i  0x80);
+   
+   if (!check) {
+   (*result)-width = width;
+   (*result)-height = height;
+   }
+
+   return IMAGE_FILETYPE_WBMP;
+}
+/* }}} */
+
+/* {{{ php_handle_wbmp
+*/
+static struct gfxinfo *php_handle_wbmp(php_stream * stream TSRMLS_DC)
+{
+   struct gfxinfo *result = (struct gfxinfo *) ecalloc(1, sizeof(struct gfxinfo));
+
+   if (!php_get_wbmp(stream, result, 0 TSRMLS_CC)) {
+   efree(result);
+   return NULL;
+   }
+
+   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)
@@ -810,6 +883,8 @@
return image/tiff;
case IMAGE_FILETYPE_IFF:
return image/iff;
+   case IMAGE_FILETYPE_WBMP:
+   return image/vnd.wap.wbmp;
default:
case IMAGE_FILETYPE_UNKNOWN:
return application/octet-stream; /* suppose binary format */
@@ -878,6 +953,9 @@
if (!memcmp(filetype, php_sig_iff, 4)) {
return IMAGE_FILETYPE_IFF;
}
+   if (php_get_wbmp(stream, NULL, 1 TSRMLS_DC)) {
+   return IMAGE_FILETYPE_WBMP;
+   }
 
return IMAGE_FILETYPE_UNKNOWN;
 }
@@ -966,6 +1044,10 @@
break;
case IMAGE_FILETYPE_IFF:
result = php_handle_iff(stream TSRMLS_CC);
+   break;
+   case IMAGE_FILETYPE_WBMP:
+   result = php_handle_wbmp(stream TSRMLS_CC);
+   break;
default:
case IMAGE_FILETYPE_UNKNOWN:
break;
Index: php4/ext/standard/php_image.h
diff -u php4/ext/standard/php_image.h:1.20 php4/ext/standard/php_image.h:1.21
--- php4/ext/standard/php_image.h:1.20  Tue Dec 31 11:07:51 2002
+++ php4/ext/standard/php_image.h   Wed Jan  8 15:36:03 2003
@@ -17,7 +17,7 @@
+--+
 */
 
-/* $Id: php_image.h,v 1.20 2002/12/31 16:07:51 sebastian Exp $ */
+/* $Id: php_image.h,v 1.21 2003/01/08 20:36:03 iliaa Exp $ */
 
 #ifndef PHP_IMAGE_H
 #define PHP_IMAGE_H
@@ -46,6 +46,7 @@
   IMAGE_FILETYPE_JB2,
   IMAGE_FILETYPE_SWC,
   IMAGE_FILETYPE_IFF,
+  IMAGE_FILETYPE_WBMP,
 /* 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




[PHP-CVS] cvs: php4 /ext/standard image.c

2003-01-08 Thread Jani Taskinen
sniper  Wed Jan  8 19:15:34 2003 EDT

  Modified files:  
/php4/ext/standard  image.c 
  Log:
  Fix the ZTS build.
  
Index: php4/ext/standard/image.c
diff -u php4/ext/standard/image.c:1.81 php4/ext/standard/image.c:1.82
--- php4/ext/standard/image.c:1.81  Wed Jan  8 15:36:03 2003
+++ php4/ext/standard/image.c   Wed Jan  8 19:15:33 2003
@@ -17,7 +17,7 @@
+--+
  */
 
-/* $Id: image.c,v 1.81 2003/01/08 20:36:03 iliaa Exp $ */
+/* $Id: image.c,v 1.82 2003/01/09 00:15:33 sniper Exp $ */
 
 #include php.h
 #include stdio.h
@@ -953,7 +953,7 @@
if (!memcmp(filetype, php_sig_iff, 4)) {
return IMAGE_FILETYPE_IFF;
}
-   if (php_get_wbmp(stream, NULL, 1 TSRMLS_DC)) {
+   if (php_get_wbmp(stream, NULL, 1 TSRMLS_CC)) {
return IMAGE_FILETYPE_WBMP;
}
 



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-CVS] cvs: php4 /ext/standard image.c

2002-12-05 Thread Marcus Boerger
helly   Thu Dec  5 07:39:01 2002 EDT

  Modified files:  
/php4/ext/standard  image.c 
  Log:
  Return FALSE on error as mentioned by John Coggeshall.
  See Bug #20822
  
  
Index: php4/ext/standard/image.c
diff -u php4/ext/standard/image.c:1.77 php4/ext/standard/image.c:1.78
--- php4/ext/standard/image.c:1.77  Tue Nov 19 16:24:47 2002
+++ php4/ext/standard/image.c   Thu Dec  5 07:39:00 2002
@@ -17,7 +17,7 @@
+--+
  */
 
-/* $Id: image.c,v 1.77 2002/11/19 21:24:47 iliaa Exp $ */
+/* $Id: image.c,v 1.78 2002/12/05 12:39:00 helly Exp $ */
 
 #include php.h
 #include stdio.h
@@ -825,6 +825,7 @@
int arg_c = ZEND_NUM_ARGS();
 
if ((arg_c!=1) || zend_get_parameters_ex(arg_c, p_image_type) == FAILURE) {
+   RETVAL_FALSE;
WRONG_PARAM_COUNT;
}
convert_to_long_ex(p_image_type);
@@ -896,6 +897,7 @@
 
case 1:
if (zend_get_parameters_ex(1, arg1) == FAILURE) {
+   RETVAL_FALSE;
WRONG_PARAM_COUNT;
}
convert_to_string_ex(arg1);
@@ -903,20 +905,21 @@
 
case 2:
if (zend_get_parameters_ex(2, arg1, info) == FAILURE) {
+   RETVAL_FALSE;
WRONG_PARAM_COUNT;
}
zval_dtor(*info);
 
if (array_init(*info) == FAILURE) {
-   return;
+   RETURN_FALSE;
}
 
convert_to_string_ex(arg1);
break;
 
default:
+   RETVAL_FALSE;
WRONG_PARAM_COUNT;
-   break;
}
 
stream = php_stream_open_wrapper(Z_STRVAL_PP(arg1), rb, 
REPORT_ERRORS|IGNORE_PATH|ENFORCE_SAFE_MODE, NULL);
@@ -976,7 +979,7 @@
if (array_init(return_value) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, Unable to 
initialize array);
efree(result);
-   return;
+   RETURN_FALSE;
}
add_index_long(return_value, 0, result-width);
add_index_long(return_value, 1, result-height);



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-CVS] cvs: php4 /ext/standard image.c

2002-11-18 Thread Derick Rethans
On Mon, 18 Nov 2002, Marcus Boerger wrote:

 helly Mon Nov 18 10:49:06 2002 EDT
 
   Modified files:  
 /php4/ext/standardimage.c 
   Log:
   Fixing unsigned/signed problems (and i thought about it before...)
   

Maybe we can add rasmus images to our test suite, or something similar 
that triggers this error?

Derick


-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-CVS] cvs: php4 /ext/standard image.c

2002-11-18 Thread Marcus Börger
Yes i thought also i think we should have one that has
the bit 7 set for width and height and it should have one
bit more set in the second byte. And width and height
should be different. This would lead us to an image of
(256+128) * (256+128+1) = 384 * 385 pixels in size.
As most images are detected the same way only one
image is needed so we can look for a very small image.

marcus

At 17:01 18.11.2002, Derick Rethans wrote:

On Mon, 18 Nov 2002, Marcus Boerger wrote:

 helly Mon Nov 18 10:49:06 2002 EDT

   Modified files:
 /php4/ext/standardimage.c
   Log:
   Fixing unsigned/signed problems (and i thought about it before...)


Maybe we can add rasmus images to our test suite, or something similar
that triggers this error?

Derick



--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-CVS] cvs: php4 /ext/standard image.c

2002-11-18 Thread Marcus Boerger
helly   Mon Nov 18 11:50:10 2002 EDT

  Modified files:  
/php4/ext/standard  image.c 
  Log:
  Added colordepth for png
  
  
Index: php4/ext/standard/image.c
diff -u php4/ext/standard/image.c:1.75 php4/ext/standard/image.c:1.76
--- php4/ext/standard/image.c:1.75  Mon Nov 18 10:49:06 2002
+++ php4/ext/standard/image.c   Mon Nov 18 11:50:10 2002
@@ -17,7 +17,7 @@
+--+
  */
 
-/* $Id: image.c,v 1.75 2002/11/18 15:49:06 helly Exp $ */
+/* $Id: image.c,v 1.76 2002/11/18 16:50:10 helly Exp $ */
 
 #include php.h
 #include stdio.h
@@ -276,7 +276,15 @@
 static struct gfxinfo *php_handle_png (php_stream * stream TSRMLS_DC)
 {
struct gfxinfo *result = NULL;
-   unsigned char dim[8];
+   unsigned char dim[9];
+/* Width:  4 bytes
+ * Height: 4 bytes
+ * Bit depth:  1 byte
+ * Color type: 1 byte
+ * Compression method: 1 byte
+ * Filter method:  1 byte
+ * Interlace method:   1 byte
+ */
 
if (php_stream_seek(stream, 8, SEEK_CUR))
return NULL;
@@ -287,6 +295,7 @@
result = (struct gfxinfo *) ecalloc(1, sizeof(struct gfxinfo));
result-width  = (((unsigned int)dim[0])  24) + (((unsigned int)dim[1])  
16) + (((unsigned int)dim[2])  8) + ((unsigned int)dim[3]);
result-height = (((unsigned int)dim[4])  24) + (((unsigned int)dim[5])  
16) + (((unsigned int)dim[6])  8) + ((unsigned int)dim[7]);
+   result-bits   = (unsigned int)dim[8];
return result;
 }
 /* }}} */



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-CVS] cvs: php4 /ext/standard image.c

2002-11-16 Thread Marcus Boerger
helly   Sat Nov 16 12:02:07 2002 EDT

  Modified files:  
/php4/ext/standard  image.c 
  Log:
  Make getimagesize more robust against corrupt files
  
  
Index: php4/ext/standard/image.c
diff -u php4/ext/standard/image.c:1.72 php4/ext/standard/image.c:1.73
--- php4/ext/standard/image.c:1.72  Tue Nov 12 11:14:18 2002
+++ php4/ext/standard/image.c   Sat Nov 16 12:02:07 2002
@@ -16,7 +16,7 @@
|  Marcus Boerger [EMAIL PROTECTED]  |
+--+
  */
-/* $Id: image.c,v 1.72 2002/11/12 16:14:18 iliaa Exp $ */
+/* $Id: image.c,v 1.73 2002/11/16 17:02:07 helly Exp $ */
 /*
  * Based on Daniel Schmitt's imageinfo.c which carried the following
  * Copyright notice.
@@ -109,21 +109,18 @@
 static struct gfxinfo *php_handle_gif (php_stream * stream TSRMLS_DC)
 {
struct gfxinfo *result = NULL;
-   unsigned char a[2];
-
-   result = (struct gfxinfo *) ecalloc(1, sizeof(struct gfxinfo));
-
-   php_stream_seek(stream, 3, SEEK_CUR);
+   char dim[5];
 
-   php_stream_read(stream, a, sizeof(a)); /*   fread(a, sizeof(a), 1, fp); */
-   result-width = (unsigned short)a[0] | (((unsigned short)a[1])8);
-
-   php_stream_read(stream, a, sizeof(a)); /*   fread(a, sizeof(a), 1, fp); */
-   result-height = (unsigned short)a[0] | (((unsigned short)a[1])8);
+   if (php_stream_seek(stream, 3, SEEK_CUR))
+   return NULL;
 
-   php_stream_read(stream, a, 1);
+   if (php_stream_read(stream, dim, sizeof(dim)) != sizeof(dim))
+   return NULL;
 
-   result-bits = a[0]0x80 ? ((a[0]0x07) + 1) : 0;
+   result = (struct gfxinfo *) ecalloc(1, sizeof(struct gfxinfo));
+   result-width= (unsigned int)dim[0] | (((unsigned int)dim[1])8);
+   result-height   = (unsigned int)dim[2] | (((unsigned int)dim[3])8);
+   result-bits = dim[4]0x80 ? unsigned int)dim[4])0x07) + 1) : 0;
result-channels = 3; /* allways */
 
return result;
@@ -135,25 +132,17 @@
 static struct gfxinfo *php_handle_psd (php_stream * stream TSRMLS_DC)
 {
struct gfxinfo *result = NULL;
-   unsigned char a[8];
-   char temp[11];
-   unsigned long in_width, in_height;
+   char dim[8];
 
-   result = (struct gfxinfo *) ecalloc(1, sizeof(struct gfxinfo));
-   php_stream_read(stream, temp, sizeof(temp));
+   if (php_stream_seek(stream, 11, SEEK_CUR))
+   return NULL;
 
-   if((php_stream_read(stream, a, sizeof(a))) = 0) {
-   in_height = 0;
-   in_width  = 0;
-   } else {
-   in_height =  (((unsigned long) a[ 0 ])  24) + (((unsigned long) a[ 1 
])  16) + (((unsigned long) a[ 2 ])  8) + ((unsigned long) a[ 3 ]);
-   in_width  =  (((unsigned long) a[ 4 ])  24) + (((unsigned long) a[ 5 
])  16) + (((unsigned long) a[ 6 ])  8) + ((unsigned long) a[ 7 ]);
-   }
+   if (php_stream_read(stream, dim, sizeof(dim)) != sizeof(dim))
+   return NULL;
 
-   result-width= (unsigned int) in_width;
-   result-height   = (unsigned int) in_height;
-   result-bits = 0;
-   result-channels = 0;
+   result = (struct gfxinfo *) ecalloc(1, sizeof(struct gfxinfo));
+   result-height   =  (((unsigned int)dim[0])  24) + (((unsigned int)dim[1]) 
+ 16) + (((unsigned int)dim[2])  8) + ((unsigned int)dim[3]);
+   result-width=  (((unsigned int)dim[4])  24) + (((unsigned int)dim[5]) 
+ 16) + (((unsigned int)dim[6])  8) + ((unsigned int)dim[7]);
 
return result;
 }
@@ -164,28 +153,18 @@
 static struct gfxinfo *php_handle_bmp (php_stream * stream TSRMLS_DC)
 {
struct gfxinfo *result = NULL;
-   char temp[15];
+   char dim[12];
 
-   struct {
-   unsigned long in_width, in_height;
-   unsigned short trash, bits;
-   } dim;
-
-   result = (struct gfxinfo *) ecalloc (1, sizeof(struct gfxinfo));
+   if (php_stream_seek(stream, 15, SEEK_CUR))
+   return NULL;
 
-   php_stream_read(stream, temp, sizeof(temp));
-   php_stream_read(stream, (char*) dim, sizeof(dim));
+   if (php_stream_read(stream, dim, sizeof(dim)) != sizeof(dim))
+   return NULL;
 
-#ifdef WORDS_BIGENDIAN
-   dim.in_width = (dim.in_width  0x00FF)  24 | (dim.in_width  0xFF00) 
 8 | (dim.in_width  0x00FF)  8 | (dim.in_width  0xFF00)  24;
-   dim.in_height = (dim.in_height  0x00FF)  24 | (dim.in_height  
0xFF00)  8 | (dim.in_height  0x00FF)  8 | (dim.in_height  0xFF00)  
24;
-   dim.bits = (dim.bits  0x00FF)  8 | (dim.bits  0xFF00)  8;
-#endif 
-   
-   result-width= dim.in_width;
-   result-height   = dim.in_height;
-   result-bits = dim.bits;
-   result-channels = 0;
+   result = (struct gfxinfo *) ecalloc (1, sizeof(struct gfxinfo));
+   result-width=  

[PHP-CVS] cvs: php4 /ext/standard image.c

2002-11-07 Thread Ilia Alshanetsky
iliaa   Thu Nov  7 11:37:48 2002 EDT

  Modified files:  
/php4/ext/standard  image.c 
  Log:
  Fixed a crash in image_type_to_mime_type(), when a non integer value is 
  passed to the function.
  Fixed Width/Height detection of bmp files on big endian systems.
  Added bit depth detection for bmp files.
  
  
Index: php4/ext/standard/image.c
diff -u php4/ext/standard/image.c:1.69 php4/ext/standard/image.c:1.70
--- php4/ext/standard/image.c:1.69  Wed Sep 18 16:37:24 2002
+++ php4/ext/standard/image.c   Thu Nov  7 11:37:46 2002
@@ -16,7 +16,7 @@
|  Marcus Boerger [EMAIL PROTECTED]  |
+--+
  */
-/* $Id: image.c,v 1.69 2002/09/18 20:37:24 iliaa Exp $ */
+/* $Id: image.c,v 1.70 2002/11/07 16:37:46 iliaa Exp $ */
 /*
  * Based on Daniel Schmitt's imageinfo.c which carried the following
  * Copyright notice.
@@ -168,15 +168,23 @@
 
struct {
unsigned long in_width, in_height;
+   unsigned short trash, bits;
} dim;
 
result = (struct gfxinfo *) ecalloc (1, sizeof(struct gfxinfo));
 
php_stream_read(stream, temp, sizeof(temp));
+   
+#ifdef WORDS_BIGENDIAN
+   dim.in_width = (dim.in_width  0x00FF)  24 | (dim.in_width  0xFF00) 
+ 8 | (dim.in_width  0x00FF)  8 | (dim.in_width  0xFF00)  24;
+   dim.in_height = (dim.in_height  0x00FF)  24 | (dim.in_height  
+0xFF00)  8 | (dim.in_height  0x00FF)  8 | (dim.in_height  0xFF00) 
+ 24;
+   dim.bits = (dim.bits  0x00FF)  8 | (dim.bits  0xFF00)  8;
+#endif 
+   
php_stream_read(stream, (char*) dim, sizeof(dim));
result-width= dim.in_width;
result-height   = dim.in_height;
-   result-bits = 0;
+   result-bits = dim.bits;
result-channels = 0;
 
return result;
@@ -836,7 +844,7 @@
if ((arg_c!=1) || zend_get_parameters_ex(arg_c, p_image_type) == FAILURE) {
WRONG_PARAM_COUNT;
}
-   zval_dtor(*p_image_type);
+   convert_to_long_ex(p_image_type);
ZVAL_STRING(return_value, 
(char*)php_image_type_to_mime_type(Z_LVAL_PP(p_image_type)), 1);
 }
 /* }}} */



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php