Bladeren bron

* Centralize pipi's errors managment in macro RETURN_SUCCESS

* Change php headers in samples programs
* Add binding for pipi_draw_line
* Check args in pipi_new_histogram and pipi_get_version


git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@3170 92316355-f0b4-4df1-b90c-862c8a59935f
master
nico 16 jaren geleden
bovenliggende
commit
f857890dda
4 gewijzigde bestanden met toevoegingen van 34 en 8 verwijderingen
  1. +5
    -1
      pipi-php/examples/example1.php
  2. +5
    -1
      pipi-php/examples/histogram.php
  3. +3
    -1
      pipi-php/examples/pipi.php
  4. +21
    -5
      pipi-php/php_pipi.c

+ 5
- 1
pipi-php/examples/example1.php Bestand weergeven

@@ -1,7 +1,11 @@
<?
#!/usr/bin/php5
<?php

$img = pipi_load_stock("random:128x128");
$img = pipi_gaussian_blur($img, 10);
//$img = pipi_box_blur($img, 30);
$img = pipi_contrast($img, 0.98);
$img = pipi_tile($img, 256, 256);
pipi_save($img, "out.png");

?>

+ 5
- 1
pipi-php/examples/histogram.php Bestand weergeven

@@ -1,4 +1,6 @@
<?
#!/usr/bin/php5
<?php

$img = pipi_load_stock("random:128x128");
$img = pipi_gaussian_blur($img, 10);
$img = pipi_contrast($img, 0.98);
@@ -9,3 +11,5 @@ pipi_get_image_histogram($img, $histogram, 1);
pipi_render_histogram($img_histogram, $histogram, 1);

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

?>

+ 3
- 1
pipi-php/examples/pipi.php Bestand weergeven

@@ -1,5 +1,5 @@
#!/usr/bin/php5
<?
<?php
$aliases = array(
"-o" => "--save",
"--output" => "--save"
@@ -46,3 +46,5 @@ for ($argi = 1; $argi < $argc; $argi++) {
die("could not load $arg\n");
}
}

?>

+ 21
- 5
pipi-php/php_pipi.c Bestand weergeven

@@ -193,6 +193,8 @@ PHP_MINIT_FUNCTION(pipi) {
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);

#define RETURN_SUCCESS(i) \
RETURN_BOOL((i) == 0);


//--------PIPI'S FUNCTIONS---------//
@@ -201,6 +203,9 @@ PHP_FUNCTION(pipi_get_color_from_string) {
}

PHP_FUNCTION(pipi_get_version) {
if (ZEND_NUM_ARGS() != 0) {
WRONG_PARAM_COUNT;
}
RETURN_STRING(estrdup(pipi_get_version()), 0);
}

@@ -231,9 +236,9 @@ PHP_FUNCTION(pipi_command) {
ZEND_FETCH_RESOURCE(ctxt, pipi_context_t*, &res, -1, PHP_PIPI_CONTEXT_RES_NAME, le_pipi_context);

if (arg2_len != 0) {
RETURN_BOOL(pipi_command(ctxt, arg1, arg2) == 0);
RETURN_SUCCESS(pipi_command(ctxt, arg1, arg2));
}
RETURN_BOOL(pipi_command(ctxt, arg1) == 0);
RETURN_SUCCESS(pipi_command(ctxt, arg1));
}

PHP_FUNCTION(pipi_load) {
@@ -280,7 +285,7 @@ PHP_FUNCTION(pipi_save) {
pipi_image_t *img;
ZEND_FETCH_RESOURCE(img, pipi_image_t*, &res, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);

RETURN_BOOL(pipi_save(img, str) == 0);
RETURN_SUCCESS(pipi_save(img, str));
}

PHP_FUNCTION(pipi_set_gamma) {
@@ -690,6 +695,14 @@ PHP_FUNCTION(pipi_flood_fill) {
}

PHP_FUNCTION(pipi_draw_line) {
zval *_zval;
long x1, y1, x2, y2, color, style = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllll|l", &_zval, &x1, &y1, &x2, &y2, &color, &style) == FAILURE) {
RETURN_FALSE;
}
pipi_image_t *img;
ZEND_FETCH_RESOURCE(img, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
RETURN_SUCCESS(pipi_draw_line(img, x1, y1, x2, y2, color, style));
}

PHP_FUNCTION(pipi_draw_rectangle) {
@@ -766,6 +779,9 @@ PHP_FUNCTION(pipi_dither_24to16) {
}

PHP_FUNCTION(pipi_new_histogram) {
if (ZEND_NUM_ARGS() != 0) {
WRONG_PARAM_COUNT;
}
pipi_histogram_t *histogram;
histogram = pipi_new_histogram();
ZEND_REGISTER_RESOURCE(return_value, histogram, le_pipi_histogram);
@@ -782,7 +798,7 @@ PHP_FUNCTION(pipi_get_image_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_BOOL(pipi_get_image_histogram(image, histogram, flags) == 0);
RETURN_SUCCESS(pipi_get_image_histogram(image, histogram, flags));
}

PHP_FUNCTION(pipi_render_histogram) {
@@ -796,7 +812,7 @@ PHP_FUNCTION(pipi_render_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_BOOL(pipi_render_histogram(image, histogram, flags) == 0);
RETURN_SUCCESS(pipi_render_histogram(image, histogram, flags));
}



Laden…
Annuleren
Opslaan