diff --git a/caca-php/examples/dithering.php b/caca-php/examples/dithering.php index 646655a..bb67827 100755 --- a/caca-php/examples/dithering.php +++ b/caca-php/examples/dithering.php @@ -1,15 +1,18 @@ #!/usr/bin/php5 value.lval; int resource_type; void *result = zend_list_find(resource_id, &resource_type); + if (!result) + return NULL; char *resource_type_name = zend_rsrc_list_get_rsrc_type(resource_id); return (strcmp(resource_type_name, type_name) == 0) ? result : NULL; } +//Fetch buffer of pixels from gdImage + +void *gd_get_pixels(gdImage *img) { + if (img->trueColor) { + int line_size = img->sx * sizeof(int); + void *result = malloc(img->sy * line_size); + int j; + for (j = 0; j < img->sy; j++) + memcpy(result + (j * line_size), (const void *) img->tpixels[j], line_size); + return result; + } + return NULL; +} + + + //------- PHP Binding's specific functions ----------// PHP_FUNCTION(caca_create_event) { @@ -1162,11 +1182,14 @@ PHP_FUNCTION(caca_dither_bitmap_gd) { RETURN_FALSE; } - printf("image size: %i x %i\n", img->sx, img->sy); - if (img->trueColor) { - printf("image is true color\n"); - RETURN_SUCCESS(caca_dither_bitmap(canvas, x, y, w, h, dither, (void *) *(img->tpixels))); + void *pixels = gd_get_pixels(img); + if (!pixels) { + RETURN_FALSE; } + + caca_dither_bitmap(canvas, x, y, w, h, dither, pixels); + free(pixels); + RETURN_TRUE; } PHP_FUNCTION(caca_get_font_list) {