Browse Source

Add php binding for functions: pipi_render_histogram, pipi_get_image_histogram

Add a sample program: examples/histogram.php


git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@3080 92316355-f0b4-4df1-b90c-862c8a59935f
remotes/tiles
nico 16 years ago
parent
commit
caa887df8c
2 changed files with 74 additions and 82 deletions
  1. +11
    -0
      pipi-php/examples/histogram.php
  2. +63
    -82
      pipi-php/php_pipi.c

+ 11
- 0
pipi-php/examples/histogram.php View File

@@ -0,0 +1,11 @@
<?
$img = pipi_load_stock("random:128x128");
$img = pipi_gaussian_blur($img, 10);
$img = pipi_contrast($img, 0.98);

$histogram = pipi_new_histogram();
$histogram_img = pipi_new(320, 200);
echo pipi_get_image_histogram($img, $histogram, 1);
echo pipi_render_histogram($img_histogram, $histogram, 1);

pipi_save($histogram_img, "out.png");

+ 63
- 82
pipi-php/php_pipi.c View File

@@ -231,9 +231,8 @@ PHP_FUNCTION(pipi_new) {
}

PHP_FUNCTION(pipi_copy) {
pipi_image_t *src;
pipi_image_t *src, *result;
FETCH_IMG(src);
pipi_image_t *result;
result = pipi_copy(src);
ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
}
@@ -309,10 +308,9 @@ PHP_FUNCTION(pipi_resize) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &width, &height) == FAILURE) {
RETURN_FALSE;
}
pipi_image_t *src;
pipi_image_t *src, *result;
ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);

pipi_image_t *result;
result = pipi_resize(src, width, height);
ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
}
@@ -353,116 +351,102 @@ PHP_FUNCTION(pipi_rgb) {
RETURN_FALSE;
}

pipi_image_t *img_r, *img_g, *img_b;
pipi_image_t *img_r, *img_g, *img_b, *result;
ZEND_FETCH_RESOURCE(img_r, pipi_image_t*, &_zval1, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
ZEND_FETCH_RESOURCE(img_g, pipi_image_t*, &_zval2, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
ZEND_FETCH_RESOURCE(img_b, pipi_image_t*, &_zval3, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);

pipi_image_t *result;
result = pipi_rgb(img_r, img_g, img_b);
ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
}

PHP_FUNCTION(pipi_red) {
pipi_image_t *src;
pipi_image_t *src, *result;
FETCH_IMG(src);
pipi_image_t *result;
result = pipi_red(src);
ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
}

PHP_FUNCTION(pipi_green) {
pipi_image_t *src;
pipi_image_t *src, *result;
FETCH_IMG(src);
pipi_image_t *result;
result = pipi_green(src);
ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
}

PHP_FUNCTION(pipi_blue) {
pipi_image_t *src;
pipi_image_t *src, *result;
FETCH_IMG(src);
pipi_image_t *result;
result = pipi_blue(src);
ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
}

PHP_FUNCTION(pipi_mean) {
pipi_image_t *img1, *img2;
pipi_image_t *img1, *img2, *result;
FETCH_IMG_IMG(img1, img2);
pipi_image_t *result;
result = pipi_mean(img1, img2);
ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
}

PHP_FUNCTION(pipi_min) {
pipi_image_t *img1, *img2;
pipi_image_t *img1, *img2, *result;
FETCH_IMG_IMG(img1, img2);
pipi_image_t *result;
result = pipi_min(img1, img2);
ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
}

PHP_FUNCTION(pipi_max) {
pipi_image_t *img1, *img2;
pipi_image_t *img1, *img2, *result;
FETCH_IMG_IMG(img1, img2);
pipi_image_t *result;
result = pipi_max(img1, img2);
ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
}

PHP_FUNCTION(pipi_add) {
pipi_image_t *img1, *img2;
pipi_image_t *img1, *img2, *result;
FETCH_IMG_IMG(img1, img2);
pipi_image_t *result;
result = pipi_add(img1, img2);
ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
}

PHP_FUNCTION(pipi_sub) {
pipi_image_t *img1, *img2;
pipi_image_t *img1, *img2, *result;
FETCH_IMG_IMG(img1, img2);
pipi_image_t *result;
result = pipi_sub(img1, img2);
ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
}

PHP_FUNCTION(pipi_difference) {
pipi_image_t *img1, *img2;
pipi_image_t *img1, *img2, *result;
FETCH_IMG_IMG(img1, img2);
pipi_image_t *result;
result = pipi_difference(img1, img2);
ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
}

PHP_FUNCTION(pipi_multiply) {
pipi_image_t *img1, *img2;
pipi_image_t *img1, *img2, *result;
FETCH_IMG_IMG(img1, img2);
pipi_image_t *result;
result = pipi_multiply(img1, img2);
ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
}

PHP_FUNCTION(pipi_divide) {
pipi_image_t *img1, *img2;
pipi_image_t *img1, *img2, *result;
FETCH_IMG_IMG(img1, img2);
pipi_image_t *result;
result = pipi_divide(img1, img2);
ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
}

PHP_FUNCTION(pipi_screen) {
pipi_image_t *img1, *img2;
pipi_image_t *img1, *img2, *result;
FETCH_IMG_IMG(img1, img2);
pipi_image_t *result;
result = pipi_screen(img1, img2);
ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
}

PHP_FUNCTION(pipi_overlay) {
pipi_image_t *img1, *img2;
pipi_image_t *img1, *img2, *result;
FETCH_IMG_IMG(img1, img2);
pipi_image_t *result;
result = pipi_overlay(img1, img2);
ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
}
@@ -476,10 +460,9 @@ PHP_FUNCTION(pipi_gaussian_blur) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rd", &_zval, &value) == FAILURE) {
RETURN_FALSE;
}
pipi_image_t *src;
pipi_image_t *src, *result;
ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);

pipi_image_t *result;
result = pipi_gaussian_blur(src, value);
ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
}
@@ -490,10 +473,9 @@ PHP_FUNCTION(pipi_gaussian_blur_ext) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rddddd", &_zval, &v1, &v2, &v3, &v4, &v5) == FAILURE) {
RETURN_FALSE;
}
pipi_image_t *src;
pipi_image_t *src, *result;
ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);

pipi_image_t *result;
result = pipi_gaussian_blur_ext(src, v1, v2, v3, v4, v5);
ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
}
@@ -504,10 +486,9 @@ PHP_FUNCTION(pipi_box_blur) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &_zval, &value) == FAILURE) {
RETURN_FALSE;
}
pipi_image_t *src;
pipi_image_t *src, *result;
ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);

pipi_image_t *result;
result = pipi_box_blur(src, value);
ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
}
@@ -518,10 +499,9 @@ PHP_FUNCTION(pipi_box_blur_ext) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &m, &n) == FAILURE) {
RETURN_FALSE;
}
pipi_image_t *src;
pipi_image_t *src, *result;
ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);

pipi_image_t *result;
result = pipi_box_blur_ext(src, m, n);
ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
}
@@ -532,10 +512,9 @@ PHP_FUNCTION(pipi_brightness) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rd", &_zval, &value) == FAILURE) {
RETURN_FALSE;
}
pipi_image_t *src;
pipi_image_t *src, *result;
ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);

pipi_image_t *result;
result = pipi_brightness(src, value);
ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
}
@@ -546,26 +525,23 @@ PHP_FUNCTION(pipi_contrast) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rd", &_zval, &value) == FAILURE) {
RETURN_FALSE;
}
pipi_image_t *src;
pipi_image_t *src, *result;
ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);

pipi_image_t *result;
result = pipi_contrast(src, value);
ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
}

PHP_FUNCTION(pipi_autocontrast) {
pipi_image_t *src;
pipi_image_t *src, *result;
FETCH_IMG(src);
pipi_image_t *result;
result = pipi_autocontrast(src);
ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
}

PHP_FUNCTION(pipi_invert) {
pipi_image_t *src;
pipi_image_t *src, *result;
FETCH_IMG(src);
pipi_image_t *result;
result = pipi_invert(src);
ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
}
@@ -576,50 +552,44 @@ PHP_FUNCTION(pipi_threshold) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rd", &_zval, &value) == FAILURE) {
RETURN_FALSE;
}
pipi_image_t *src;
pipi_image_t *src, *result;
ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);

pipi_image_t *result;
result = pipi_threshold(src, value);
ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
}

PHP_FUNCTION(pipi_hflip) {
pipi_image_t *src;
pipi_image_t *src, *result;
FETCH_IMG(src);
pipi_image_t *result;
result = pipi_hflip(src);
ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
}

PHP_FUNCTION(pipi_vflip) {
pipi_image_t *src;
pipi_image_t *src, *result;
FETCH_IMG(src);
pipi_image_t *result;
result = pipi_vflip(src);
ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
}

PHP_FUNCTION(pipi_rotate90) {
pipi_image_t *src;
pipi_image_t *src, *result;
FETCH_IMG(src);
pipi_image_t *result;
result = pipi_rotate90(src);
ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
}

PHP_FUNCTION(pipi_rotate180) {
pipi_image_t *src;
pipi_image_t *src, *result;
FETCH_IMG(src);
pipi_image_t *result;
result = pipi_rotate180(src);
ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
}

PHP_FUNCTION(pipi_rotate270) {
pipi_image_t *src;
pipi_image_t *src, *result;
FETCH_IMG(src);
pipi_image_t *result;
result = pipi_rotate270(src);
ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
}
@@ -630,10 +600,9 @@ PHP_FUNCTION(pipi_median) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &_zval, &value) == FAILURE) {
RETURN_FALSE;
}
pipi_image_t *src;
pipi_image_t *src, *result;
ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);

pipi_image_t *result;
result = pipi_median(src, value);
ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
}
@@ -644,34 +613,30 @@ PHP_FUNCTION(pipi_median_ext) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &rx, &ry) == FAILURE) {
RETURN_FALSE;
}
pipi_image_t *src;
pipi_image_t *src, *result;
ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);

pipi_image_t *result;
result = pipi_median_ext(src, rx, ry);
ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
}

PHP_FUNCTION(pipi_dilate) {
pipi_image_t *src;
pipi_image_t *src, *result;
FETCH_IMG(src);
pipi_image_t *result;
result = pipi_dilate(src);
ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
}

PHP_FUNCTION(pipi_erode) {
pipi_image_t *src;
pipi_image_t *src, *result;
FETCH_IMG(src);
pipi_image_t *result;
result = pipi_erode(src);
ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
}

PHP_FUNCTION(pipi_order) {
pipi_image_t *src;
pipi_image_t *src, *result;
FETCH_IMG(src);
pipi_image_t *result;
result = pipi_order(src);
ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
}
@@ -682,10 +647,9 @@ PHP_FUNCTION(pipi_tile) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &width, &height) == FAILURE) {
RETURN_FALSE;
}
pipi_image_t *src;
pipi_image_t *src, *result;
ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);

pipi_image_t *result;
result = pipi_tile(src, width, height);
ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
}
@@ -709,9 +673,8 @@ PHP_FUNCTION(pipi_dither_ediff) {
}

PHP_FUNCTION(pipi_dither_ordered) {
pipi_image_t *img1, *img2;
pipi_image_t *img1, *img2, *result;
FETCH_IMG_IMG(img1, img2);
pipi_image_t *result;
result = pipi_dither_ordered(img1, img2);
ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
}
@@ -723,11 +686,10 @@ PHP_FUNCTION(pipi_dither_ordered_ext) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrdd", &_zval1, &_zval2, &precision, &angle) == FAILURE) {
RETURN_FALSE;
}
pipi_image_t *img1, *img2;
pipi_image_t *img1, *img2, *result;
ZEND_FETCH_RESOURCE(img1, pipi_image_t*, &_zval1, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
ZEND_FETCH_RESOURCE(img2, pipi_image_t*, &_zval2, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);

pipi_image_t *result;
result = pipi_dither_ordered_ext(img1, img2, precision, angle);
ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
}
@@ -738,18 +700,16 @@ PHP_FUNCTION(pipi_dither_halftone) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rdd", &_zval, &r, &angle) == FAILURE) {
RETURN_FALSE;
}
pipi_image_t *src;
pipi_image_t *src, *result;
ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);

pipi_image_t *result;
result = pipi_dither_halftone(src, r, angle);
ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
}

PHP_FUNCTION(pipi_dither_random) {
pipi_image_t *src;
pipi_image_t *src, *result;
FETCH_IMG(src);
pipi_image_t *result;
result = pipi_dither_random(src);
ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
}
@@ -758,9 +718,8 @@ PHP_FUNCTION(pipi_dither_ostromoukhov) {
}

PHP_FUNCTION(pipi_dither_dbs) {
pipi_image_t *src;
pipi_image_t *src, *result;
FETCH_IMG(src);
pipi_image_t *result;
result = pipi_dither_dbs(src);
ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
}
@@ -778,9 +737,31 @@ PHP_FUNCTION(pipi_new_histogram) {
}

PHP_FUNCTION(pipi_get_image_histogram) {
zval *_zval_img, *_zval_hst;
long flags = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrl", &_zval_img, &_zval_hst, &flags) == FAILURE) {
RETURN_FALSE;
}
pipi_image_t *image;
pipi_histogram_t *histogram;
ZEND_FETCH_RESOURCE(image, pipi_image_t*, &_zval_img, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
ZEND_FETCH_RESOURCE(histogram, pipi_histogram_t*, &_zval_hst, -1, PHP_PIPI_HISTOGRAM_RES_NAME, le_pipi_histogram);

RETURN_LONG(pipi_get_image_histogram(image, histogram, flags));
}

PHP_FUNCTION(pipi_render_histogram) {
zval *_zval_img, *_zval_hst;
long flags = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrl", &_zval_img, &_zval_hst, &flags) == FAILURE) {
RETURN_FALSE;
}
pipi_image_t *image;
pipi_histogram_t *histogram;
ZEND_FETCH_RESOURCE(image, pipi_image_t*, &_zval_img, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
ZEND_FETCH_RESOURCE(histogram, pipi_histogram_t*, &_zval_hst, -1, PHP_PIPI_HISTOGRAM_RES_NAME, le_pipi_histogram);

RETURN_LONG(pipi_render_histogram(image, histogram, flags));
}



Loading…
Cancel
Save