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
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.