hholzgra                Sun Mar  5 18:23:48 2006 UTC

  Modified files:              
    /php-src    NEWS 
    /php-src/ext/gd     gd.c php_gd.h 
  Log:
  added ImageColorHistogram function
  
  
http://cvs.php.net/viewcvs.cgi/php-src/NEWS?r1=1.2091&r2=1.2092&diff_format=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.2091 php-src/NEWS:1.2092
--- php-src/NEWS:1.2091 Fri Mar  3 13:09:13 2006
+++ php-src/NEWS        Sun Mar  5 18:23:47 2006
@@ -30,3 +30,4 @@
 - Added possibility to check in which extension an internal function was
   defined using reflection API. (Johannes)
 - Fixed bug #34286 (__toString() behavior is inconsistent). (Marcus)
+- Added ImageColorHistogram() to gd extension. (Hartmut)
http://cvs.php.net/viewcvs.cgi/php-src/ext/gd/gd.c?r1=1.345&r2=1.346&diff_format=u
Index: php-src/ext/gd/gd.c
diff -u php-src/ext/gd/gd.c:1.345 php-src/ext/gd/gd.c:1.346
--- php-src/ext/gd/gd.c:1.345   Sun Feb 19 04:29:40 2006
+++ php-src/ext/gd/gd.c Sun Mar  5 18:23:47 2006
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: gd.c,v 1.345 2006/02/19 04:29:40 andi Exp $ */
+/* $Id: gd.c,v 1.346 2006/03/05 18:23:47 hholzgra Exp $ */
 
 /* gd 1.2 is copyright 1994, 1995, Quest Protein Database Center,
    Cold Spring Harbor Labs. */
@@ -144,6 +144,7 @@
        PHP_FE(imagechar,                                                       
        NULL)
        PHP_FE(imagecharup,                                                     
        NULL)
        PHP_FE(imagecolorat,                                                    
NULL)
+       PHP_FE(imagecolorhistogram,                     NULL)
        PHP_FE(imagecolorallocate,                                              
NULL)
        PHP_FE(imagepalettecopy,                                                
NULL)
        PHP_FE(imagecreatefromstring,                                   NULL)
@@ -2349,6 +2350,53 @@
 }
 /* }}} */
 
+/* {{{ proto array imagecolorhistogram(resource im)
+   Return color histogram for an image */
+PHP_FUNCTION(imagecolorhistogram)
+{
+       zval **IM;
+       gdImagePtr im;
+       int num_colors, x, y, n;
+       long *color_count;
+
+       if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &IM) == FAILURE) {
+               ZEND_WRONG_PARAM_COUNT();
+       }
+
+       ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
+
+       if (!im->pixels) {
+               RETURN_FALSE;
+       }
+       
+       num_colors = gdImageColorsTotal(im);
+
+       if (num_colors <= 0) {
+               RETURN_FALSE;
+       }
+
+       color_count = (long *)calloc(num_colors, sizeof(long));
+       
+       for (x = 0; x < gdImageSX(im); x++) {
+               for (y = 0; y < gdImageSY(im); y++) {
+#if HAVE_LIBGD13
+                       color_count[im->pixels[y][x]]++;
+#else
+                       color_count[im->pixels[x][y]]++;
+#endif
+               }
+       }
+
+       array_init(return_value);
+
+       for (n = 0; n < num_colors; n++) {
+               add_index_long(return_value, n, color_count[n]);
+       }
+
+       efree(color_count);
+}
+/* }}} */
+
 /* {{{ proto int imagecolortransparent(resource im [, int col])
    Define a color as transparent */
 PHP_FUNCTION(imagecolortransparent)
http://cvs.php.net/viewcvs.cgi/php-src/ext/gd/php_gd.h?r1=1.66&r2=1.67&diff_format=u
Index: php-src/ext/gd/php_gd.h
diff -u php-src/ext/gd/php_gd.h:1.66 php-src/ext/gd/php_gd.h:1.67
--- php-src/ext/gd/php_gd.h:1.66        Sun Feb 19 05:05:42 2006
+++ php-src/ext/gd/php_gd.h     Sun Mar  5 18:23:47 2006
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: php_gd.h,v 1.66 2006/02/19 05:05:42 andi Exp $ */
+/* $Id: php_gd.h,v 1.67 2006/03/05 18:23:47 hholzgra Exp $ */
 
 #ifndef PHP_GD_H
 #define PHP_GD_H
@@ -86,6 +86,7 @@
 PHP_FUNCTION(imagecolorset);
 PHP_FUNCTION(imagecolorstotal);
 PHP_FUNCTION(imagecolorsforindex);
+PHP_FUNCTION(imagecolorhistogram);
 PHP_FUNCTION(imagecolortransparent);
 PHP_FUNCTION(imagecopy);
 PHP_FUNCTION(imagecopymerge);


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

Reply via email to