Add a php rewrite of pipi.c in examples/ git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@3086 92316355-f0b4-4df1-b90c-862c8a59935fremotes/tiles
| @@ -5,7 +5,7 @@ $img = pipi_contrast($img, 0.98); | |||||
| $histogram = pipi_new_histogram(); | $histogram = pipi_new_histogram(); | ||||
| $histogram_img = pipi_new(320, 200); | $histogram_img = pipi_new(320, 200); | ||||
| echo pipi_get_image_histogram($img, $histogram, 1); | |||||
| echo pipi_render_histogram($img_histogram, $histogram, 1); | |||||
| pipi_get_image_histogram($img, $histogram, 1); | |||||
| pipi_render_histogram($img_histogram, $histogram, 1); | |||||
| pipi_save($histogram_img, "out.png"); | pipi_save($histogram_img, "out.png"); | ||||
| @@ -0,0 +1,48 @@ | |||||
| #!/usr/bin/php5 | |||||
| <? | |||||
| $aliases = array( | |||||
| "-o" => "--save", | |||||
| "--output" => "--save" | |||||
| ); | |||||
| $ctx = pipi_create_context(); | |||||
| $list = pipi_get_command_list(); | |||||
| for ($argi = 1; $argi < $argc; $argi++) { | |||||
| $arg = $argv[$argi]; | |||||
| if (isset($aliases[$arg])) | |||||
| $arg = $aliases[$arg]; | |||||
| if (substr($arg, 0, 2) == "--") { | |||||
| $cmd_name = substr($arg, 2); | |||||
| if (!isset($list[$cmd_name])) { | |||||
| die("unknown command $cmd_name\n"); | |||||
| } | |||||
| $cmd_argc = $list[$cmd_name]; | |||||
| if ($argi + $cmd_argc > $argc) { | |||||
| die("too few arguments for $arg_name\n"); | |||||
| } | |||||
| switch ($cmd_argc) { | |||||
| case 0: | |||||
| $res = pipi_command($ctx, $cmd_name); | |||||
| break; | |||||
| case 1: | |||||
| $res = pipi_command($ctx, $cmd_name, $argv[$argi + 1]); | |||||
| break; | |||||
| default: | |||||
| die(); | |||||
| } | |||||
| if ($res != 0) { | |||||
| die("command $cmd_name failed\n"); | |||||
| } | |||||
| $argi += $cmd_argc; | |||||
| } | |||||
| else { | |||||
| if (pipi_command($ctx, "load", $arg) != 0) | |||||
| die("could not load $arg\n"); | |||||
| } | |||||
| } | |||||
| @@ -202,6 +202,20 @@ PHP_FUNCTION(pipi_get_command_list) { | |||||
| } | } | ||||
| PHP_FUNCTION(pipi_command) { | PHP_FUNCTION(pipi_command) { | ||||
| zval *res; | |||||
| char *arg1, *arg2 = NULL; | |||||
| int arg1_len, arg2_len; | |||||
| if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|s", &res, &arg1, &arg1_len, &arg2, &arg2_len) == FAILURE) { | |||||
| RETURN_FALSE; | |||||
| } | |||||
| pipi_context_t *ctxt; | |||||
| ZEND_FETCH_RESOURCE(ctxt, pipi_context_t*, &res, -1, PHP_PIPI_CONTEXT_RES_NAME, le_pipi_context); | |||||
| if (arg2_len != 0) { | |||||
| RETURN_LONG(pipi_command(ctxt, arg1, arg2)); | |||||
| } | |||||
| RETURN_LONG(pipi_command(ctxt, arg1)); | |||||
| } | } | ||||
| PHP_FUNCTION(pipi_load) { | PHP_FUNCTION(pipi_load) { | ||||