Changeset 3149
- Timestamp:
- Oct 30, 2008, 2:21:26 PM (15 years ago)
- Location:
- libcaca/trunk/caca-php
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/caca-php/php_caca.c
r3148 r3149 107 107 PHP_FE(caca_dither_bitmap, NULL) 108 108 PHP_FE(caca_load_font, NULL) 109 PHP_FE(caca_load_builtin_font, NULL) 109 110 PHP_FE(caca_get_font_list, NULL) 110 111 PHP_FE(caca_get_font_width, NULL) … … 361 362 362 363 void *gd_get_pixels(gdImage *img) { 364 void *result; 365 int j, pitch; 363 366 if (img->trueColor) { 364 int line_size = img->sx * sizeof(int); 365 void *result = malloc(img->sy * line_size); 366 int j; 367 pitch = img->sx * sizeof(int); 368 result = malloc(img->sy * pitch); 367 369 for (j = 0; j < img->sy; j++) 368 memcpy(result + (j * line_size), (const void *) img->tpixels[j], line_size); 369 return result; 370 memcpy(result + (j * pitch), (const void *) img->tpixels[j], pitch); 370 371 } 371 372 else { 372 int line_size = img->sx * sizeof(char); 373 void *result = malloc(img->sy * line_size); 374 int j; 373 pitch = img->sx * sizeof(char); 374 result = malloc(img->sy * pitch); 375 375 for (j = 0; j < img->sy; j++) 376 memcpy(result + (j * line_size), (const void *) img->pixels[j], line_size);377 return result;378 }376 memcpy(result + (j * pitch), (const void *) img->pixels[j], pitch); 377 } 378 return result; 379 379 } 380 380 … … 1038 1038 dither = caca_create_dither(sizeof(char) * 8, img->sx, img->sy, img->sx * sizeof(char), 0, 0, 0, 0); 1039 1039 1040 if (!dither) { 1041 RETURN_FALSE; 1042 } 1043 1040 1044 ZEND_REGISTER_RESOURCE(return_value, dither, le_caca_dither); 1041 1045 } … … 1144 1148 1145 1149 PHP_FUNCTION(caca_get_dither_antialias_list) { 1146 //TODO: write 1150 zval *_zval; 1151 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) { 1152 RETURN_FALSE; 1153 } 1154 caca_dither_t *dither; 1155 ZEND_FETCH_RESOURCE(dither, caca_dither_t*, &_zval, -1, PHP_CACA_DITHER_RES_NAME, le_caca_dither); 1156 1157 char const * const *list = caca_get_dither_antialias_list(dither); 1158 int i; 1159 array_init(return_value); 1160 for(i = 0; list[i]; i += 1) 1161 add_next_index_string(return_value, (char*) list[i], 1); 1147 1162 } 1148 1163 … … 1308 1323 } 1309 1324 caca_font_t *font = caca_load_font(str, str_len); 1325 if (!font) { 1326 RETURN_FALSE; 1327 } 1328 ZEND_REGISTER_RESOURCE(return_value, font, le_caca_font); 1329 } 1330 1331 PHP_FUNCTION(caca_load_builtin_font) { 1332 char *str; 1333 long str_len; 1334 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) { 1335 RETURN_FALSE; 1336 } 1337 caca_font_t *font = caca_load_font(str, 0); 1338 if (!font) { 1339 RETURN_FALSE; 1340 } 1310 1341 ZEND_REGISTER_RESOURCE(return_value, font, le_caca_font); 1311 1342 } … … 1356 1387 1357 1388 PHP_FUNCTION(caca_render_canvas) { 1358 //TODO: write 1389 zval *_zval1, *_zval2, *_zval3; 1390 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrr", &_zval1, &_zval2, &_zval3) == FAILURE) { 1391 RETURN_FALSE; 1392 } 1393 caca_canvas_t *canvas; 1394 ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval1, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas); 1395 caca_font_t *font; 1396 ZEND_FETCH_RESOURCE(font, caca_font_t*, &_zval2, -1, PHP_CACA_FONT_RES_NAME, le_caca_font); 1397 1398 gdImage *img = fetch_external_resource(_zval3, "gd"); 1399 if (!img || !img->trueColor) { 1400 RETURN_FALSE; 1401 } 1402 1403 int pitch = img->sx * sizeof(int); 1404 void *buffer = malloc(pitch * img->sy); 1405 if (!buffer) { 1406 RETURN_FALSE; 1407 } 1408 1409 caca_render_canvas(canvas, font, buffer, img->sx, img->sy, pitch); 1410 int i; 1411 for (i = 0; i < img->sy; i++) 1412 memcpy(img->tpixels[i], buffer + (i * pitch), pitch); 1413 1414 //TODO: fix colors order 1415 free(buffer); 1416 RETURN_TRUE; 1359 1417 } 1360 1418 … … 1400 1458 } 1401 1459 caca_file_t *file = caca_file_open(path, mode); 1460 if (!file) { 1461 RETURN_FALSE; 1462 } 1402 1463 ZEND_REGISTER_RESOURCE(return_value, file, le_caca_file); 1403 1464 } … … 1566 1627 1567 1628 caca_display_t *display = caca_create_display(canvas); 1629 if (!display) { 1630 RETURN_FALSE; 1631 } 1568 1632 ZEND_REGISTER_RESOURCE(return_value, display, le_caca_display); 1569 1633 } … … 1624 1688 ZEND_FETCH_RESOURCE(display, caca_display_t*, &_zval, -1, PHP_CACA_DISPLAY_RES_NAME, le_caca_display); 1625 1689 caca_canvas_t *canvas = caca_get_canvas(display); 1690 if (!canvas) { 1691 RETURN_FALSE; 1692 } 1626 1693 ZEND_REGISTER_RESOURCE(return_value, canvas, le_caca_canvas); 1627 1694 } -
libcaca/trunk/caca-php/php_caca.h
r3148 r3149 123 123 PHP_FUNCTION(caca_dither_bitmap); 124 124 PHP_FUNCTION(caca_load_font); 125 PHP_FUNCTION(caca_load_builtin_font); 125 126 PHP_FUNCTION(caca_get_font_list); 126 127 PHP_FUNCTION(caca_get_font_width);
Note: See TracChangeset
for help on using the changeset viewer.