diff --git a/caca-php/config.m4 b/caca-php/config.m4 index a6ed2a6..ceec4cd 100644 --- a/caca-php/config.m4 +++ b/caca-php/config.m4 @@ -5,8 +5,15 @@ if test "$PHP_CACA" = "yes"; then AC_CHECK_LIB(caca, caca_get_version, [ PHP_ADD_LIBRARY(caca,, CACA_SHARED_LIBADD) ], [ - AC_MSG_ERROR(libcaca required !) + AC_MSG_ERROR(libcaca development files required !) ]) + + AC_CHECK_LIB(gd, gdImageSetPixel, [ + PHP_ADD_LIBRARY(gd,, CACA_SHARED_LIBADD) + ], [ + AC_MSG_ERROR(gd development files required !) + ]) + PHP_NEW_EXTENSION(caca, php_caca.c, $ext_shared,,) PHP_SUBST(CACA_SHARED_LIBADD) fi diff --git a/caca-php/php_caca.c b/caca-php/php_caca.c index ed6a172..4dedf24 100644 --- a/caca-php/php_caca.c +++ b/caca-php/php_caca.c @@ -16,6 +16,7 @@ #include "php.h" #include "php_caca.h" +#include static function_entry caca_functions[] = { PHP_FE(caca_create_event, NULL) @@ -105,7 +106,7 @@ static function_entry caca_functions[] = { PHP_FE(caca_set_dither_algorithm, NULL) PHP_FE(caca_get_dither_algorithm_list, NULL) PHP_FE(caca_get_dither_algorithm, NULL) - PHP_FE(caca_dither_bitmap, NULL) + PHP_FE(caca_dither_bitmap_gd, NULL) PHP_FE(caca_get_font_list, NULL) PHP_FE(caca_get_font_width, NULL) PHP_FE(caca_get_font_height, NULL) @@ -341,6 +342,16 @@ PHP_MINIT_FUNCTION(caca) { #define RETURN_SUCCESS(i) \ RETURN_BOOL((i) == 0); +//------- Function that allows to fetch external php resources such as gd resouces + +void *fetch_external_resource(zval *_zval, char const *type_name) { + int resource_id = _zval->value.lval; + int resource_type; + void *result = zend_list_find(resource_id, &resource_type); + char *resource_type_name = zend_rsrc_list_get_rsrc_type(resource_id); + return (strcmp(resource_type_name, type_name) == 0) ? result : NULL; +} + //------- PHP Binding's specific functions ----------// PHP_FUNCTION(caca_create_event) { @@ -1124,18 +1135,15 @@ PHP_FUNCTION(caca_get_dither_algorithm) { RETURN_STRING((char *) caca_get_dither_algorithm(dither), 1); } -PHP_FUNCTION(caca_dither_bitmap) { - zval *_zval1, *_zval2; - int x, y, w, h = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllllr", &_zval1, &x, &y, &w, &h, &_zval2) == FAILURE) { +PHP_FUNCTION(caca_dither_bitmap_gd) { + zval *_zval; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) { RETURN_FALSE; } - caca_canvas_t *canvas; - ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval1, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas); - caca_dither_t *dither; - ZEND_FETCH_RESOURCE(dither, caca_dither_t*, &_zval2, -1, PHP_CACA_DITHER_RES_NAME, le_caca_dither); -/* RETURN_SUCCESS(caca_dither_bitmap(canvas, x, y, x, h, dither, pixels); //TODO: Use gd ressouces for pixels? -*/ + gdImage *img = fetch_external_resource(_zval, "gd"); + if (img) { + printf("image size: %i x %i\n", img->sx, img->sy); + } } PHP_FUNCTION(caca_get_font_list) { diff --git a/caca-php/php_caca.h b/caca-php/php_caca.h index fae5e11..c65f120 100644 --- a/caca-php/php_caca.h +++ b/caca-php/php_caca.h @@ -123,7 +123,7 @@ PHP_FUNCTION(caca_get_dither_charset); PHP_FUNCTION(caca_set_dither_algorithm); PHP_FUNCTION(caca_get_dither_algorithm_list); PHP_FUNCTION(caca_get_dither_algorithm); -PHP_FUNCTION(caca_dither_bitmap); +PHP_FUNCTION(caca_dither_bitmap_gd); PHP_FUNCTION(caca_get_font_list); PHP_FUNCTION(caca_get_font_width); PHP_FUNCTION(caca_get_font_height);