Changeset 3148 for libcaca/trunk/caca-php/php_caca.c
- Timestamp:
- Oct 30, 2008, 12:39:24 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/caca-php/php_caca.c
r3143 r3148 86 86 PHP_FE(caca_free_frame, NULL) 87 87 PHP_FE(caca_create_dither, NULL) 88 PHP_FE(caca_create_dither_gd, NULL)89 88 PHP_FE(caca_set_dither_palette, NULL) 90 PHP_FE(caca_set_dither_palette_gd, NULL)91 89 PHP_FE(caca_set_dither_brightness, NULL) 92 90 PHP_FE(caca_get_dither_brightness, NULL) … … 107 105 PHP_FE(caca_get_dither_algorithm_list, NULL) 108 106 PHP_FE(caca_get_dither_algorithm, NULL) 109 PHP_FE(caca_dither_bitmap _gd, NULL)107 PHP_FE(caca_dither_bitmap, NULL) 110 108 PHP_FE(caca_load_font, NULL) 111 109 PHP_FE(caca_get_font_list, NULL) … … 381 379 } 382 380 381 int gd_load_palette(gdImage *img, caca_dither_t *dither) { 382 if (!img || img->trueColor || gdMaxColors != 256) { 383 return -1; 384 } 385 386 uint32_t r[256], g[256], b[256], a[256]; 387 int i; 388 for (i = 0; i < 256; i++) { 389 r[i] = img->red[i] << 4; 390 g[i] = img->green[i] << 4; 391 b[i] = img->blue[i] << 4; 392 a[i] = img->alpha[i] << 4; 393 } 394 395 return caca_set_dither_palette(dither, &r[0], &g[0], &b[0], &a[0]); 396 } 397 383 398 //------- Caca's functions ----------------// 384 399 … … 1007 1022 1008 1023 PHP_FUNCTION(caca_create_dither) { 1009 long bpp, w, h, pitch, rmask, gmask, bmask, amask = 0;1010 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llllllll", &bpp, &w, &h, &pitch, &rmask, &gmask, &bmask, &amask) == FAILURE) {1011 RETURN_FALSE;1012 }1013 caca_dither_t *dither = caca_create_dither(bpp, w, h, pitch, rmask, gmask, bmask, amask);1014 ZEND_REGISTER_RESOURCE(return_value, dither, le_caca_dither);1015 }1016 1017 PHP_FUNCTION(caca_create_dither_gd) {1018 1024 zval *_zval; 1019 1025 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) { … … 1062 1068 } 1063 1069 1064 PHP_FUNCTION(caca_set_dither_palette_gd) {1065 zval *_zval1, *_zval2;1066 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr", &_zval1, &_zval2) == FAILURE) {1067 RETURN_FALSE;1068 }1069 1070 caca_dither_t *dither;1071 ZEND_FETCH_RESOURCE(dither, caca_dither_t*, &_zval1, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_dither);1072 1073 gdImage *img = fetch_external_resource(_zval2, "gd");1074 if (!img || img->trueColor || gdMaxColors != 256) {1075 RETURN_FALSE;1076 }1077 1078 uint32_t r[256], g[256], b[256], a[256];1079 int i;1080 for (i = 0; i < 256; i++) {1081 r[i] = img->red[i] << 4;1082 g[i] = img->green[i] << 4;1083 b[i] = img->blue[i] << 4;1084 a[i] = img->alpha[i] << 4;1085 }1086 1087 RETURN_SUCCESS(caca_set_dither_palette(dither, &r[0], &g[0], &b[0], &a[0]));1088 }1089 1090 1070 PHP_FUNCTION(caca_set_dither_brightness) { 1091 1071 zval *_zval; … … 1288 1268 } 1289 1269 1290 PHP_FUNCTION(caca_dither_bitmap _gd) {1270 PHP_FUNCTION(caca_dither_bitmap) { 1291 1271 zval *_zval1, *_zval2, *_zval3; 1292 1272 long x, y, w, h = 0; 1293 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllllrr", &_zval1, &x, &y, &w, &h, &_zval2, &_zval3) == FAILURE) { 1273 zend_bool load_palette = 1; 1274 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllllrr|b", &_zval1, &x, &y, &w, &h, &_zval2, &_zval3, &load_palette) == FAILURE) { 1294 1275 RETURN_FALSE; 1295 1276 } … … 1307 1288 void *pixels = gd_get_pixels(img); 1308 1289 if (!pixels) { 1290 RETURN_FALSE; 1291 } 1292 1293 //load palette if image is not true color 1294 if (load_palette && !img->trueColor && gd_load_palette(img, dither) != 0) { 1309 1295 RETURN_FALSE; 1310 1296 }
Note: See TracChangeset
for help on using the changeset viewer.