Ignore:
Timestamp:
Oct 27, 2008, 5:23:05 PM (11 years ago)
Author:
nico
Message:
  • 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
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/caca-php/php_caca.c

    r3117 r3119  
    1717#include "php.h"
    1818#include "php_caca.h"
     19#include <gd.h>
    1920
    2021static function_entry caca_functions[] = {
     
    106107        PHP_FE(caca_get_dither_algorithm_list, NULL)
    107108        PHP_FE(caca_get_dither_algorithm, NULL)
    108         PHP_FE(caca_dither_bitmap, NULL)
     109        PHP_FE(caca_dither_bitmap_gd, NULL)
    109110        PHP_FE(caca_get_font_list, NULL)
    110111        PHP_FE(caca_get_font_width, NULL)
     
    342343        RETURN_BOOL((i) == 0);
    343344
     345//------- Function that allows to fetch external php resources such as gd resouces
     346
     347void *fetch_external_resource(zval *_zval, char const *type_name) {
     348        int resource_id = _zval->value.lval;
     349        int resource_type;
     350        void *result = zend_list_find(resource_id, &resource_type);
     351        char *resource_type_name = zend_rsrc_list_get_rsrc_type(resource_id);
     352        return (strcmp(resource_type_name, type_name) == 0) ? result : NULL;
     353}
     354
    344355//------- PHP Binding's specific functions ----------//
    345356
     
    11251136}
    11261137
    1127 PHP_FUNCTION(caca_dither_bitmap) {
    1128         zval *_zval1, *_zval2;
    1129         int x, y, w, h = 0;
    1130         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllllr", &_zval1, &x, &y, &w, &h, &_zval2) == FAILURE) {
    1131                 RETURN_FALSE;
    1132         }
    1133         caca_canvas_t *canvas;
    1134         ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval1, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
    1135         caca_dither_t *dither;
    1136         ZEND_FETCH_RESOURCE(dither, caca_dither_t*, &_zval2, -1, PHP_CACA_DITHER_RES_NAME, le_caca_dither);
    1137 /*      RETURN_SUCCESS(caca_dither_bitmap(canvas, x, y, x, h, dither, pixels); //TODO: Use gd ressouces for pixels?
    1138 */
     1138PHP_FUNCTION(caca_dither_bitmap_gd) {
     1139        zval *_zval;
     1140        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) {
     1141                RETURN_FALSE;
     1142        }
     1143        gdImage *img = fetch_external_resource(_zval, "gd");
     1144        if (img) {
     1145                printf("image size: %i x %i\n", img->sx, img->sy);
     1146        }
    11391147}
    11401148
Note: See TracChangeset for help on using the changeset viewer.