Ignore:
Timestamp:
Oct 27, 2008, 8:35:48 PM (11 years ago)
Author:
nico
Message:
  • Add a "caca_create_dither_gd" function that create the proper dither for a given gd resource.
Location:
libcaca/trunk/caca-php
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/caca-php/examples/dithering.php

    r3122 r3123  
    22<?
    33$img = imagecreatefrompng(dirname(__FILE__)."/logo-caca.png");
     4$dither = caca_create_dither_gd($img);
     5if (!$dither)
     6        die("Can not create dither. Maybe this image is not truecolor.\n");
     7
    48$canvas = caca_create_canvas(0, 0);
    5 
    6 $dither = caca_create_dither(32, 128, 128, 4 * 128, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000);
    7 
    89$display = caca_create_display($canvas);
    9 caca_set_display_time($display, 80000);
     10if (!$dither)
     11        die("Can not create display.\n");
    1012
    1113caca_dither_bitmap_gd($canvas, 0, 0, caca_get_canvas_width($canvas), caca_get_canvas_height($canvas), $dither, $img);
  • libcaca/trunk/caca-php/php_caca.c

    r3122 r3123  
    8989        PHP_FE(caca_free_frame, NULL)
    9090        PHP_FE(caca_create_dither, NULL)
     91        PHP_FE(caca_create_dither_gd, NULL)
    9192        PHP_FE(caca_set_dither_palette, NULL)
    9293        PHP_FE(caca_set_dither_brightness, NULL)
     
    964965}
    965966
     967PHP_FUNCTION(caca_create_dither_gd) {
     968        zval *_zval;
     969        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) {
     970                RETURN_FALSE;
     971        }
     972
     973        gdImage *img = fetch_external_resource(_zval, "gd");
     974        if (!img | !img->trueColor) {
     975                RETURN_FALSE;
     976        }
     977        caca_dither_t *dither = caca_create_dither(sizeof(int) * 8, img->sx, img->sy, img->sx * sizeof(int), 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000);
     978        ZEND_REGISTER_RESOURCE(return_value, dither, le_caca_dither);
     979}
     980
    966981PHP_FUNCTION(caca_set_dither_palette) {
    967982}
  • libcaca/trunk/caca-php/php_caca.h

    r3120 r3123  
    106106PHP_FUNCTION(caca_free_frame);
    107107PHP_FUNCTION(caca_create_dither);
     108PHP_FUNCTION(caca_create_dither_gd);
    108109PHP_FUNCTION(caca_set_dither_palette);
    109110PHP_FUNCTION(caca_set_dither_brightness);
Note: See TracChangeset for help on using the changeset viewer.