Browse Source

* Improve function "caca_dither_bitmap_gd"

* Add php binding for "caca_create_dither"
* Add new sample program "dithering.php"
tags/v0.99.beta17
Nicolas Vion nico 16 years ago
parent
commit
ff2c8fddc9
3 changed files with 44 additions and 5 deletions
  1. +15
    -0
      caca-php/examples/dithering.php
  2. +28
    -5
      caca-php/php_caca.c
  3. +1
    -0
      caca-php/php_caca.h

+ 15
- 0
caca-php/examples/dithering.php View File

@@ -0,0 +1,15 @@
#!/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);

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


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

@@ -87,6 +87,7 @@ static function_entry caca_functions[] = {
PHP_FE(caca_set_frame_name, NULL)
PHP_FE(caca_create_frame, NULL)
PHP_FE(caca_free_frame, NULL)
PHP_FE(caca_create_dither, NULL)
PHP_FE(caca_set_dither_palette, NULL)
PHP_FE(caca_set_dither_brightness, NULL)
PHP_FE(caca_get_dither_brightness, NULL)
@@ -933,6 +934,15 @@ PHP_FUNCTION(caca_free_frame) {
RETURN_SUCCESS(caca_free_frame(canvas, id));
}

PHP_FUNCTION(caca_create_dither) {
long bpp, w, h, pitch, rmask, gmask, bmask, amask = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llllllll", &bpp, &w, &h, &pitch, &rmask, &gmask, &bmask, &amask) == FAILURE) {
RETURN_FALSE;
}
caca_dither_t *dither = caca_create_dither(bpp, w, h, pitch, rmask, gmask, bmask, amask);
ZEND_REGISTER_RESOURCE(return_value, dither, le_caca_dither);
}

PHP_FUNCTION(caca_set_dither_palette) {
}

@@ -1136,13 +1146,26 @@ PHP_FUNCTION(caca_get_dither_algorithm) {
}

PHP_FUNCTION(caca_dither_bitmap_gd) {
zval *_zval;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) {
zval *_zval1, *_zval2, *_zval3;
long x, y, w, h = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllllrr", &_zval1, &x, &y, &w, &h, &_zval2, &_zval3) == FAILURE) {
RETURN_FALSE;
}
gdImage *img = fetch_external_resource(_zval, "gd");
if (img) {
printf("image size: %i x %i\n", img->sx, img->sy);

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

gdImage *img = fetch_external_resource(_zval3, "gd");
if (!img) {
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)));
}
}



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

@@ -104,6 +104,7 @@ PHP_FUNCTION(caca_set_frame);
PHP_FUNCTION(caca_set_frame_name);
PHP_FUNCTION(caca_create_frame);
PHP_FUNCTION(caca_free_frame);
PHP_FUNCTION(caca_create_dither);
PHP_FUNCTION(caca_set_dither_palette);
PHP_FUNCTION(caca_set_dither_brightness);
PHP_FUNCTION(caca_get_dither_brightness);


Loading…
Cancel
Save