pajoye          Sat Apr 16 08:12:27 2005 EDT

  Modified files:              
    /php-src/ext/gd     gd.c php_gd.h 
  Log:
  - export imageconvolution to userland, making people happy to do not
    use the predefined ones :)
  
  
http://cvs.php.net/diff.php/php-src/ext/gd/gd.c?r1=1.308&r2=1.309&ty=u
Index: php-src/ext/gd/gd.c
diff -u php-src/ext/gd/gd.c:1.308 php-src/ext/gd/gd.c:1.309
--- php-src/ext/gd/gd.c:1.308   Sun Apr 10 17:37:16 2005
+++ php-src/ext/gd/gd.c Sat Apr 16 08:12:24 2005
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: gd.c,v 1.308 2005/04/10 21:37:16 andrey Exp $ */
+/* $Id: gd.c,v 1.309 2005/04/16 12:12:24 pajoye Exp $ */
 
 /* gd 1.2 is copyright 1994, 1995, Quest Protein Database Center,
    Cold Spring Harbor Labs. */
@@ -324,6 +324,7 @@
 /* gd filters */
 #ifdef HAVE_GD_BUNDLED
        PHP_FE(imagefilter,                                                     
NULL)
+       PHP_FE(imageconvolution,                                                
NULL)
 #endif
 
        {NULL, NULL, NULL}
@@ -4188,6 +4189,60 @@
        }
 }
 /* }}} */
+
+/* {{{ proto resource imageconvolution(resource src_im, array matrix3x3, 
double div, double offset)
+   Apply a 3x3 convolution matrix, using coefficient div and offset */
+PHP_FUNCTION(imageconvolution)
+{
+       zval *SIM, *hash_matrix;
+       pval **var = NULL, **var2 = NULL;
+       gdImagePtr im_src = NULL;
+       float div, offset;
+       int nelem, i, j, res;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "radd", &SIM, 
&hash_matrix, &div, &offset) == FAILURE) {
+               RETURN_FALSE;
+       }
+
+       ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
+
+       nelem = zend_hash_num_elements(Z_ARRVAL_P(hash_matrix));
+       if (nelem != 3) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "You must have 3x3 
array");
+               RETURN_FALSE;
+       }
+
+       float matrix[3][3] = {{0,0,0}, {0,0,0}, {0,0,0}};
+
+       for (i=0; i<3; i++) {
+               if (zend_hash_index_find(Z_ARRVAL_P(hash_matrix), (i), (void 
**) &var) == SUCCESS) {
+                       if (Z_TYPE_PP(var) != IS_ARRAY || 
zend_hash_num_elements(Z_ARRVAL_PP(var)) != 3 ) {
+                               php_error_docref(NULL TSRMLS_CC, E_WARNING, 
"You must have 3x3 array");
+                               RETURN_FALSE;
+                       }
+
+                       for (j=0; j<3; j++) {
+                               if (zend_hash_index_find(Z_ARRVAL_PP(var), (j), 
(void **) &var2) == SUCCESS) {
+                                       SEPARATE_ZVAL(var2);
+                                       convert_to_double(*var2);
+                                       matrix[i][j] = Z_DVAL_PP(var2);
+                               } else {
+                                       php_error_docref(NULL TSRMLS_CC, 
E_WARNING, "You must have a 3x3 matrix");
+                                       RETURN_FALSE;
+                               }
+                       }
+               }
+       }
+       res = gdImageConvolution(im_src, matrix, div, offset);
+
+       if (res) {
+               RETURN_TRUE;
+       } else {
+               RETURN_FALSE;
+       }
+}
+/* }}} */
+
 /* End section: Filters */
 
 /* {{{ proto bool imageantialias(resource im, bool on)
http://cvs.php.net/diff.php/php-src/ext/gd/php_gd.h?r1=1.57&r2=1.58&ty=u
Index: php-src/ext/gd/php_gd.h
diff -u php-src/ext/gd/php_gd.h:1.57 php-src/ext/gd/php_gd.h:1.58
--- php-src/ext/gd/php_gd.h:1.57        Thu Jan  8 12:32:08 2004
+++ php-src/ext/gd/php_gd.h     Sat Apr 16 08:12:24 2005
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: php_gd.h,v 1.57 2004/01/08 17:32:08 sniper Exp $ */
+/* $Id: php_gd.h,v 1.58 2005/04/16 12:12:24 pajoye Exp $ */
 
 #ifndef PHP_GD_H
 #define PHP_GD_H
@@ -175,6 +175,7 @@
 PHP_FUNCTION(imagelayereffect);
 PHP_FUNCTION(imagecolormatch);
 PHP_FUNCTION(imagefilter);
+PHP_FUNCTION(imageconvolution);
 PHP_FUNCTION(imagexbm);
 #endif
 

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

Reply via email to