Browse Source

* Add a function "fetch_external_resource" that allows to fetch external php

resources such as gd resouces
* Add test for presence of gd development files in config.m4
* Rename php function caca_dither_bitmap in caca_dither_bitmap_gd
tags/v0.99.beta17
Nicolas Vion nico 16 years ago
parent
commit
a8e0322720
3 changed files with 28 additions and 13 deletions
  1. +8
    -1
      caca-php/config.m4
  2. +19
    -11
      caca-php/php_caca.c
  3. +1
    -1
      caca-php/php_caca.h

+ 8
- 1
caca-php/config.m4 View File

@@ -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

+ 19
- 11
caca-php/php_caca.c View File

@@ -16,6 +16,7 @@

#include "php.h"
#include "php_caca.h"
#include <gd.h>

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) {


+ 1
- 1
caca-php/php_caca.h View File

@@ -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);


Loading…
Cancel
Save