Changeset 3122 for libcaca


Ignore:
Timestamp:
Oct 27, 2008, 8:14:32 PM (11 years ago)
Author:
nico
Message:
  • 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
Location:
libcaca/trunk/caca-php
Files:
1 added
2 edited

Legend:

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

    r3120 r3122  
    22<?
    33$img = imagecreatefrompng(dirname(__FILE__)."/logo-caca.png");
    4 //$img = imagecreatefromjpeg("/home/nicolas/images/Clown Fish-mini.jpg");
    54$canvas = caca_create_canvas(0, 0);
    65
    7 $dither = caca_create_dither(16, 128, 128, 3 * 256, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000);
    8 caca_set_dither_gamma($dither, -1.0);
     6$dither = caca_create_dither(32, 128, 128, 4 * 128, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000);
    97
    10 if (caca_dither_bitmap_gd($canvas, 0, 0, 30, 30, $dither, $img)) {
    11         $dp = caca_create_display($canvas);
    12         caca_refresh_display($dp);
    13         sleep(5);
    14 }
     8$display = caca_create_display($canvas);
     9caca_set_display_time($display, 80000);
    1510
     11caca_dither_bitmap_gd($canvas, 0, 0, caca_get_canvas_width($canvas), caca_get_canvas_height($canvas), $dither, $img);
     12caca_refresh_display($display);
     13
     14sleep(5);
     15
     16
     17
     18
  • libcaca/trunk/caca-php/php_caca.c

    r3121 r3122  
    344344        RETURN_BOOL((i) == 0);
    345345
    346 //------- Function that allows to fetch external php resources such as gd resouces
     346//---------- Some usefull functions --------------------//
     347
     348//Fetch external php resources such as gd resouces
    347349
    348350void *fetch_external_resource(zval *_zval, char const *type_name) {
     
    350352        int resource_type;
    351353        void *result = zend_list_find(resource_id, &resource_type);
     354        if (!result)
     355                return NULL;
    352356        char *resource_type_name = zend_rsrc_list_get_rsrc_type(resource_id);
    353357        return (strcmp(resource_type_name, type_name) == 0) ? result : NULL;
    354358}
     359
     360//Fetch buffer of pixels from gdImage
     361
     362void *gd_get_pixels(gdImage *img) {
     363        if (img->trueColor) {
     364                int line_size = img->sx * sizeof(int);
     365                void *result = malloc(img->sy * line_size);
     366                int j;         
     367                for (j = 0; j < img->sy; j++)
     368                        memcpy(result + (j * line_size), (const void *) img->tpixels[j], line_size);
     369                return result;
     370        }
     371        return NULL;
     372}
     373
     374
    355375
    356376//------- PHP Binding's specific functions ----------//
     
    11631183        }
    11641184
    1165         printf("image size: %i x %i\n", img->sx, img->sy);
    1166         if (img->trueColor) {
    1167                 printf("image is true color\n");
    1168                 RETURN_SUCCESS(caca_dither_bitmap(canvas, x, y, w, h, dither, (void *) *(img->tpixels)));
    1169         }
     1185        void *pixels = gd_get_pixels(img);
     1186        if (!pixels) {
     1187                RETURN_FALSE;
     1188        }
     1189
     1190        caca_dither_bitmap(canvas, x, y, w, h, dither, pixels);
     1191        free(pixels);
     1192        RETURN_TRUE;
    11701193}
    11711194
Note: See TracChangeset for help on using the changeset viewer.