Changeset 3122 for libcaca/trunk/caca-php
- Timestamp:
- Oct 27, 2008, 8:14:32 PM (14 years ago)
- Location:
- libcaca/trunk/caca-php
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/caca-php/examples/dithering.php
r3120 r3122 2 2 <? 3 3 $img = imagecreatefrompng(dirname(__FILE__)."/logo-caca.png"); 4 //$img = imagecreatefromjpeg("/home/nicolas/images/Clown Fish-mini.jpg");5 4 $canvas = caca_create_canvas(0, 0); 6 5 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); 9 7 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); 9 caca_set_display_time($display, 80000); 15 10 11 caca_dither_bitmap_gd($canvas, 0, 0, caca_get_canvas_width($canvas), caca_get_canvas_height($canvas), $dither, $img); 12 caca_refresh_display($display); 13 14 sleep(5); 15 16 17 18 -
libcaca/trunk/caca-php/php_caca.c
r3121 r3122 344 344 RETURN_BOOL((i) == 0); 345 345 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 347 349 348 350 void *fetch_external_resource(zval *_zval, char const *type_name) { … … 350 352 int resource_type; 351 353 void *result = zend_list_find(resource_id, &resource_type); 354 if (!result) 355 return NULL; 352 356 char *resource_type_name = zend_rsrc_list_get_rsrc_type(resource_id); 353 357 return (strcmp(resource_type_name, type_name) == 0) ? result : NULL; 354 358 } 359 360 //Fetch buffer of pixels from gdImage 361 362 void *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 355 375 356 376 //------- PHP Binding's specific functions ----------// … … 1163 1183 } 1164 1184 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; 1170 1193 } 1171 1194
Note: See TracChangeset
for help on using the changeset viewer.