Browse Source

* Add working sample program dithering.php (open logo-caca.png with Gd and

render it with caca caca_dither_bitmap_gd)
* Add a function to fetch a buffer of gd pixels in php_caca.c
tags/v0.99.beta17
Nicolas Vion nico 16 years ago
parent
commit
468304b265
3 changed files with 39 additions and 13 deletions
  1. +11
    -8
      caca-php/examples/dithering.php
  2. BIN
      caca-php/examples/logo-caca.png
  3. +28
    -5
      caca-php/php_caca.c

+ 11
- 8
caca-php/examples/dithering.php View File

@@ -1,15 +1,18 @@
#!/usr/bin/php5
<?
$img = imagecreatefrompng(dirname(__FILE__)."/logo-caca.png");
//$img = imagecreatefromjpeg("/home/nicolas/images/Clown Fish-mini.jpg");
$canvas = caca_create_canvas(0, 0);

$dither = caca_create_dither(16, 128, 128, 3 * 256, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000);
caca_set_dither_gamma($dither, -1.0);
$dither = caca_create_dither(32, 128, 128, 4 * 128, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000);

$display = caca_create_display($canvas);
caca_set_display_time($display, 80000);

caca_dither_bitmap_gd($canvas, 0, 0, caca_get_canvas_width($canvas), caca_get_canvas_height($canvas), $dither, $img);
caca_refresh_display($display);

sleep(5);



if (caca_dither_bitmap_gd($canvas, 0, 0, 30, 30, $dither, $img)) {
$dp = caca_create_display($canvas);
caca_refresh_display($dp);
sleep(5);
}


BIN
caca-php/examples/logo-caca.png View File

Before After
Width: 128  |  Height: 128  |  Size: 7.3 KiB

+ 28
- 5
caca-php/php_caca.c View File

@@ -343,16 +343,36 @@ PHP_MINIT_FUNCTION(caca) {
#define RETURN_SUCCESS(i) \
RETURN_BOOL((i) == 0);

//------- Function that allows to fetch external php resources such as gd resouces
//---------- Some usefull functions --------------------//

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


Loading…
Cancel
Save