您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

768 行
21 KiB

  1. /*
  2. * php-pipi Php binding for Libpipi
  3. * Copyright (c) 2008 Vion Nicolas <nico@picapo.net>
  4. *
  5. *
  6. * This library is free software. It comes without any warranty, to
  7. * the extent permitted by applicable law. You can redistribute it
  8. * and/or modify it under the terms of the Do What The Fuck You Want
  9. * To Public License, Version 2, as published by Sam Hocevar. See
  10. * http://sam.zoy.org/wtfpl/COPYING for more details.
  11. */
  12. #ifdef HAVE_CONFIG_H
  13. #include "config.h"
  14. #endif
  15. #include "php.h"
  16. #include "php_pipi.h"
  17. static function_entry pipi_functions[] = {
  18. PHP_FE(pipi_get_color_from_string, NULL)
  19. PHP_FE(pipi_get_version, NULL)
  20. PHP_FE(pipi_create_context, NULL)
  21. PHP_FE(pipi_get_command_list, NULL)
  22. PHP_FE(pipi_command, NULL)
  23. PHP_FE(pipi_load, NULL)
  24. PHP_FE(pipi_load_stock, NULL)
  25. PHP_FE(pipi_new, NULL)
  26. PHP_FE(pipi_copy, NULL)
  27. PHP_FE(pipi_save, NULL)
  28. PHP_FE(pipi_set_gamma, NULL)
  29. PHP_FE(pipi_getpixels, NULL)
  30. PHP_FE(pipi_get_image_width, NULL)
  31. PHP_FE(pipi_get_image_height, NULL)
  32. PHP_FE(pipi_get_image_pitch, NULL)
  33. PHP_FE(pipi_get_image_last_modified, NULL)
  34. PHP_FE(pipi_get_format_name, NULL)
  35. PHP_FE(pipi_measure_msd, NULL)
  36. PHP_FE(pipi_measure_rmsd, NULL)
  37. PHP_FE(pipi_resize, NULL)
  38. PHP_FE(pipi_render_random, NULL)
  39. PHP_FE(pipi_render_bayer, NULL)
  40. PHP_FE(pipi_render_halftone, NULL)
  41. PHP_FE(pipi_rgb, NULL)
  42. PHP_FE(pipi_red, NULL)
  43. PHP_FE(pipi_green, NULL)
  44. PHP_FE(pipi_blue, NULL)
  45. PHP_FE(pipi_mean, NULL)
  46. PHP_FE(pipi_min, NULL)
  47. PHP_FE(pipi_max, NULL)
  48. PHP_FE(pipi_add, NULL)
  49. PHP_FE(pipi_sub, NULL)
  50. PHP_FE(pipi_difference, NULL)
  51. PHP_FE(pipi_multiply, NULL)
  52. PHP_FE(pipi_divide, NULL)
  53. PHP_FE(pipi_screen, NULL)
  54. PHP_FE(pipi_overlay, NULL)
  55. PHP_FE(pipi_convolution, NULL)
  56. PHP_FE(pipi_gaussian_blur, NULL)
  57. PHP_FE(pipi_gaussian_blur_ext, NULL)
  58. PHP_FE(pipi_box_blur, NULL)
  59. PHP_FE(pipi_box_blur_ext, NULL)
  60. PHP_FE(pipi_brightness, NULL)
  61. PHP_FE(pipi_contrast, NULL)
  62. PHP_FE(pipi_autocontrast, NULL)
  63. PHP_FE(pipi_invert, NULL)
  64. PHP_FE(pipi_threshold, NULL)
  65. PHP_FE(pipi_hflip, NULL)
  66. PHP_FE(pipi_vflip, NULL)
  67. PHP_FE(pipi_rotate90, NULL)
  68. PHP_FE(pipi_rotate180, NULL)
  69. PHP_FE(pipi_rotate270, NULL)
  70. PHP_FE(pipi_median, NULL)
  71. PHP_FE(pipi_median_ext, NULL)
  72. PHP_FE(pipi_dilate, NULL)
  73. PHP_FE(pipi_erode, NULL)
  74. PHP_FE(pipi_order, NULL)
  75. PHP_FE(pipi_tile, NULL)
  76. PHP_FE(pipi_flood_fill, NULL)
  77. PHP_FE(pipi_draw_line, NULL)
  78. PHP_FE(pipi_draw_polyline, NULL)
  79. PHP_FE(pipi_draw_bezier4, NULL)
  80. PHP_FE(pipi_reduce, NULL)
  81. PHP_FE(pipi_dither_ediff, NULL)
  82. PHP_FE(pipi_dither_ordered, NULL)
  83. PHP_FE(pipi_dither_ordered_ext, NULL)
  84. PHP_FE(pipi_dither_halftone, NULL)
  85. PHP_FE(pipi_dither_random, NULL)
  86. PHP_FE(pipi_dither_ostromoukhov, NULL)
  87. PHP_FE(pipi_dither_dbs, NULL)
  88. PHP_FE(pipi_dither_24to16, NULL)
  89. PHP_FE(pipi_new_histogram, NULL)
  90. PHP_FE(pipi_get_image_histogram, NULL)
  91. PHP_FE(pipi_render_histogram, NULL)
  92. {NULL, NULL, NULL}
  93. };
  94. zend_module_entry pipi_module_entry = {
  95. #if ZEND_MODULE_API_NO >= 20010901
  96. STANDARD_MODULE_HEADER,
  97. #endif
  98. PHP_PIPI_EXTNAME,
  99. pipi_functions,
  100. PHP_MINIT(pipi),
  101. NULL,
  102. NULL,
  103. NULL,
  104. PHP_MINFO(pipi),
  105. #if ZEND_MODULE_API_NO >= 20010901
  106. PHP_PIPI_VERSION,
  107. #endif
  108. STANDARD_MODULE_PROPERTIES
  109. };
  110. #ifdef COMPILE_DL_PIPI
  111. ZEND_GET_MODULE(pipi)
  112. #endif
  113. PHP_MINFO_FUNCTION(pipi) {
  114. php_info_print_table_start();
  115. php_info_print_table_row(2, "Pipi library version", pipi_get_version());
  116. php_info_print_table_end();
  117. }
  118. //--------PIPI'S RESSOURCES---------//
  119. static void php_pipi_image_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
  120. pipi_free(rsrc->ptr);
  121. }
  122. static void php_pipi_context_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
  123. pipi_destroy_context(rsrc->ptr);
  124. }
  125. static void php_pipi_histogram_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
  126. pipi_free_histogram(rsrc->ptr);
  127. }
  128. PHP_MINIT_FUNCTION(pipi) {
  129. le_pipi_image = zend_register_list_destructors_ex(php_pipi_image_dtor, NULL, PHP_PIPI_IMAGE_RES_NAME, module_number);
  130. le_pipi_context = zend_register_list_destructors_ex(php_pipi_context_dtor, NULL, PHP_PIPI_CONTEXT_RES_NAME, module_number);
  131. le_pipi_histogram = zend_register_list_destructors_ex(php_pipi_histogram_dtor, NULL, PHP_PIPI_HISTOGRAM_RES_NAME, module_number);
  132. return SUCCESS;
  133. }
  134. //----------SOMEMACROS---------------//
  135. #define FETCH_STR(str) \
  136. int __len; \
  137. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &__len) == FAILURE) { \
  138. RETURN_FALSE; \
  139. }
  140. #define FETCH_LONG(l) \
  141. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &l) == FAILURE) { \
  142. RETURN_FALSE; \
  143. }
  144. #define FETCH_IMG(img) \
  145. zval *_zval; \
  146. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) { \
  147. RETURN_FALSE; \
  148. } \
  149. ZEND_FETCH_RESOURCE(img, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
  150. #define FETCH_IMG_IMG(img1, img2) \
  151. zval *_zval1; \
  152. zval *_zval2; \
  153. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr", &_zval1, &_zval2) == FAILURE) { \
  154. RETURN_FALSE; \
  155. } \
  156. ZEND_FETCH_RESOURCE(img1, pipi_image_t*, &_zval1, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image); \
  157. ZEND_FETCH_RESOURCE(img2, pipi_image_t*, &_zval2, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
  158. //--------PIPI'S FUNCTIONS---------//
  159. PHP_FUNCTION(pipi_get_color_from_string) {
  160. }
  161. PHP_FUNCTION(pipi_get_version) {
  162. RETURN_STRING(estrdup(pipi_get_version()), 0);
  163. }
  164. PHP_FUNCTION(pipi_create_context) {
  165. pipi_context_t *context;
  166. context = pipi_create_context();
  167. ZEND_REGISTER_RESOURCE(return_value, context, le_pipi_context);
  168. }
  169. PHP_FUNCTION(pipi_get_command_list) {
  170. pipi_command_t const *list;
  171. pipi_command_t const *cmd;
  172. list = pipi_get_command_list();
  173. array_init(return_value);
  174. for (cmd = list; cmd->name; cmd++)
  175. add_assoc_long(return_value, (char*) cmd->name, cmd->argc);
  176. }
  177. PHP_FUNCTION(pipi_command) {
  178. }
  179. PHP_FUNCTION(pipi_load) {
  180. char *str;
  181. FETCH_STR(str);
  182. pipi_image_t *img;
  183. img = pipi_load(str);
  184. ZEND_REGISTER_RESOURCE(return_value, img, le_pipi_image);
  185. }
  186. PHP_FUNCTION(pipi_load_stock) {
  187. char *str;
  188. FETCH_STR(str);
  189. pipi_image_t *img;
  190. img = pipi_load_stock(str);
  191. ZEND_REGISTER_RESOURCE(return_value, img, le_pipi_image);
  192. }
  193. PHP_FUNCTION(pipi_new) {
  194. long width, height = 0;
  195. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &width, &height) == FAILURE) {
  196. RETURN_FALSE;
  197. }
  198. pipi_image_t *img;
  199. img = pipi_new(width, height);
  200. ZEND_REGISTER_RESOURCE(return_value, img, le_pipi_image);
  201. }
  202. PHP_FUNCTION(pipi_copy) {
  203. pipi_image_t *src, *result;
  204. FETCH_IMG(src);
  205. result = pipi_copy(src);
  206. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  207. }
  208. PHP_FUNCTION(pipi_save) {
  209. zval *res;
  210. char *str;
  211. int str_len;
  212. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &res, &str, &str_len) == FAILURE) {
  213. RETURN_FALSE;
  214. }
  215. pipi_image_t *img;
  216. ZEND_FETCH_RESOURCE(img, pipi_image_t*, &res, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
  217. RETURN_LONG(pipi_save(img, str));
  218. }
  219. PHP_FUNCTION(pipi_set_gamma) {
  220. long value;
  221. FETCH_LONG(value);
  222. pipi_set_gamma(value);
  223. }
  224. PHP_FUNCTION(pipi_getpixels) {
  225. }
  226. PHP_FUNCTION(pipi_get_image_width) {
  227. pipi_image_t *img;
  228. FETCH_IMG(img);
  229. RETURN_LONG(pipi_get_image_width(img));
  230. }
  231. PHP_FUNCTION(pipi_get_image_height) {
  232. pipi_image_t *img;
  233. FETCH_IMG(img);
  234. RETURN_LONG(pipi_get_image_height(img));
  235. }
  236. PHP_FUNCTION(pipi_get_image_pitch) {
  237. pipi_image_t *img;
  238. FETCH_IMG(img);
  239. RETURN_LONG(pipi_get_image_pitch(img));
  240. }
  241. PHP_FUNCTION(pipi_get_image_last_modified) {
  242. pipi_image_t *img;
  243. FETCH_IMG(img);
  244. RETURN_LONG(pipi_get_image_last_midified(img));
  245. }
  246. PHP_FUNCTION(pipi_get_format_name) {
  247. long id;
  248. FETCH_LONG(id);
  249. RETURN_STRING(estrdup(pipi_get_format_name(id)), 0);
  250. }
  251. PHP_FUNCTION(pipi_measure_msd) {
  252. pipi_image_t *img1, *img2;
  253. FETCH_IMG_IMG(img1, img2);
  254. RETURN_LONG(pipi_measure_msd(img1, img2));
  255. }
  256. PHP_FUNCTION(pipi_measure_rmsd) {
  257. pipi_image_t *img1, *img2;
  258. FETCH_IMG_IMG(img1, img2);
  259. RETURN_LONG(pipi_measure_rmsd(img1, img2));
  260. }
  261. PHP_FUNCTION(pipi_resize) {
  262. zval *_zval;
  263. long width, height = 0;
  264. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &width, &height) == FAILURE) {
  265. RETURN_FALSE;
  266. }
  267. pipi_image_t *src, *result;
  268. ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
  269. result = pipi_resize(src, width, height);
  270. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  271. }
  272. PHP_FUNCTION(pipi_render_random) {
  273. long width, height = 0;
  274. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &width, &height) == FAILURE) {
  275. RETURN_FALSE;
  276. }
  277. pipi_image_t *img;
  278. img = pipi_render_random(width, height);
  279. ZEND_REGISTER_RESOURCE(return_value, img, le_pipi_image);
  280. }
  281. PHP_FUNCTION(pipi_render_bayer) {
  282. long width, height = 0;
  283. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &width, &height) == FAILURE) {
  284. RETURN_FALSE;
  285. }
  286. pipi_image_t *img;
  287. img = pipi_render_bayer(width, height);
  288. ZEND_REGISTER_RESOURCE(return_value, img, le_pipi_image);
  289. }
  290. PHP_FUNCTION(pipi_render_halftone) {
  291. long width, height = 0;
  292. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &width, &height) == FAILURE) {
  293. RETURN_FALSE;
  294. }
  295. pipi_image_t *img;
  296. img = pipi_render_halftone(width, height);
  297. ZEND_REGISTER_RESOURCE(return_value, img, le_pipi_image);
  298. }
  299. PHP_FUNCTION(pipi_rgb) {
  300. zval *_zval1, *_zval2, *_zval3;
  301. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrr", &_zval1, &_zval2, &_zval3) == FAILURE) {
  302. RETURN_FALSE;
  303. }
  304. pipi_image_t *img_r, *img_g, *img_b, *result;
  305. ZEND_FETCH_RESOURCE(img_r, pipi_image_t*, &_zval1, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
  306. ZEND_FETCH_RESOURCE(img_g, pipi_image_t*, &_zval2, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
  307. ZEND_FETCH_RESOURCE(img_b, pipi_image_t*, &_zval3, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
  308. result = pipi_rgb(img_r, img_g, img_b);
  309. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  310. }
  311. PHP_FUNCTION(pipi_red) {
  312. pipi_image_t *src, *result;
  313. FETCH_IMG(src);
  314. result = pipi_red(src);
  315. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  316. }
  317. PHP_FUNCTION(pipi_green) {
  318. pipi_image_t *src, *result;
  319. FETCH_IMG(src);
  320. result = pipi_green(src);
  321. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  322. }
  323. PHP_FUNCTION(pipi_blue) {
  324. pipi_image_t *src, *result;
  325. FETCH_IMG(src);
  326. result = pipi_blue(src);
  327. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  328. }
  329. PHP_FUNCTION(pipi_mean) {
  330. pipi_image_t *img1, *img2, *result;
  331. FETCH_IMG_IMG(img1, img2);
  332. result = pipi_mean(img1, img2);
  333. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  334. }
  335. PHP_FUNCTION(pipi_min) {
  336. pipi_image_t *img1, *img2, *result;
  337. FETCH_IMG_IMG(img1, img2);
  338. result = pipi_min(img1, img2);
  339. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  340. }
  341. PHP_FUNCTION(pipi_max) {
  342. pipi_image_t *img1, *img2, *result;
  343. FETCH_IMG_IMG(img1, img2);
  344. result = pipi_max(img1, img2);
  345. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  346. }
  347. PHP_FUNCTION(pipi_add) {
  348. pipi_image_t *img1, *img2, *result;
  349. FETCH_IMG_IMG(img1, img2);
  350. result = pipi_add(img1, img2);
  351. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  352. }
  353. PHP_FUNCTION(pipi_sub) {
  354. pipi_image_t *img1, *img2, *result;
  355. FETCH_IMG_IMG(img1, img2);
  356. result = pipi_sub(img1, img2);
  357. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  358. }
  359. PHP_FUNCTION(pipi_difference) {
  360. pipi_image_t *img1, *img2, *result;
  361. FETCH_IMG_IMG(img1, img2);
  362. result = pipi_difference(img1, img2);
  363. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  364. }
  365. PHP_FUNCTION(pipi_multiply) {
  366. pipi_image_t *img1, *img2, *result;
  367. FETCH_IMG_IMG(img1, img2);
  368. result = pipi_multiply(img1, img2);
  369. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  370. }
  371. PHP_FUNCTION(pipi_divide) {
  372. pipi_image_t *img1, *img2, *result;
  373. FETCH_IMG_IMG(img1, img2);
  374. result = pipi_divide(img1, img2);
  375. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  376. }
  377. PHP_FUNCTION(pipi_screen) {
  378. pipi_image_t *img1, *img2, *result;
  379. FETCH_IMG_IMG(img1, img2);
  380. result = pipi_screen(img1, img2);
  381. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  382. }
  383. PHP_FUNCTION(pipi_overlay) {
  384. pipi_image_t *img1, *img2, *result;
  385. FETCH_IMG_IMG(img1, img2);
  386. result = pipi_overlay(img1, img2);
  387. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  388. }
  389. PHP_FUNCTION(pipi_convolution) {
  390. }
  391. PHP_FUNCTION(pipi_gaussian_blur) {
  392. zval *_zval;
  393. double value = 0;
  394. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rd", &_zval, &value) == FAILURE) {
  395. RETURN_FALSE;
  396. }
  397. pipi_image_t *src, *result;
  398. ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
  399. result = pipi_gaussian_blur(src, value);
  400. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  401. }
  402. PHP_FUNCTION(pipi_gaussian_blur_ext) {
  403. zval *_zval;
  404. double v1, v2, v3, v4, v5 = 0;
  405. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rddddd", &_zval, &v1, &v2, &v3, &v4, &v5) == FAILURE) {
  406. RETURN_FALSE;
  407. }
  408. pipi_image_t *src, *result;
  409. ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
  410. result = pipi_gaussian_blur_ext(src, v1, v2, v3, v4, v5);
  411. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  412. }
  413. PHP_FUNCTION(pipi_box_blur) {
  414. zval *_zval;
  415. long value = 0;
  416. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &_zval, &value) == FAILURE) {
  417. RETURN_FALSE;
  418. }
  419. pipi_image_t *src, *result;
  420. ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
  421. result = pipi_box_blur(src, value);
  422. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  423. }
  424. PHP_FUNCTION(pipi_box_blur_ext) {
  425. zval *_zval;
  426. long m, n = 0;
  427. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &m, &n) == FAILURE) {
  428. RETURN_FALSE;
  429. }
  430. pipi_image_t *src, *result;
  431. ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
  432. result = pipi_box_blur_ext(src, m, n);
  433. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  434. }
  435. PHP_FUNCTION(pipi_brightness) {
  436. zval *_zval;
  437. double value = 0;
  438. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rd", &_zval, &value) == FAILURE) {
  439. RETURN_FALSE;
  440. }
  441. pipi_image_t *src, *result;
  442. ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
  443. result = pipi_brightness(src, value);
  444. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  445. }
  446. PHP_FUNCTION(pipi_contrast) {
  447. zval *_zval;
  448. double value = 0;
  449. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rd", &_zval, &value) == FAILURE) {
  450. RETURN_FALSE;
  451. }
  452. pipi_image_t *src, *result;
  453. ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
  454. result = pipi_contrast(src, value);
  455. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  456. }
  457. PHP_FUNCTION(pipi_autocontrast) {
  458. pipi_image_t *src, *result;
  459. FETCH_IMG(src);
  460. result = pipi_autocontrast(src);
  461. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  462. }
  463. PHP_FUNCTION(pipi_invert) {
  464. pipi_image_t *src, *result;
  465. FETCH_IMG(src);
  466. result = pipi_invert(src);
  467. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  468. }
  469. PHP_FUNCTION(pipi_threshold) {
  470. zval *_zval;
  471. double value = 0;
  472. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rd", &_zval, &value) == FAILURE) {
  473. RETURN_FALSE;
  474. }
  475. pipi_image_t *src, *result;
  476. ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
  477. result = pipi_threshold(src, value);
  478. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  479. }
  480. PHP_FUNCTION(pipi_hflip) {
  481. pipi_image_t *src, *result;
  482. FETCH_IMG(src);
  483. result = pipi_hflip(src);
  484. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  485. }
  486. PHP_FUNCTION(pipi_vflip) {
  487. pipi_image_t *src, *result;
  488. FETCH_IMG(src);
  489. result = pipi_vflip(src);
  490. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  491. }
  492. PHP_FUNCTION(pipi_rotate90) {
  493. pipi_image_t *src, *result;
  494. FETCH_IMG(src);
  495. result = pipi_rotate90(src);
  496. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  497. }
  498. PHP_FUNCTION(pipi_rotate180) {
  499. pipi_image_t *src, *result;
  500. FETCH_IMG(src);
  501. result = pipi_rotate180(src);
  502. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  503. }
  504. PHP_FUNCTION(pipi_rotate270) {
  505. pipi_image_t *src, *result;
  506. FETCH_IMG(src);
  507. result = pipi_rotate270(src);
  508. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  509. }
  510. PHP_FUNCTION(pipi_median) {
  511. zval *_zval;
  512. long value = 0;
  513. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &_zval, &value) == FAILURE) {
  514. RETURN_FALSE;
  515. }
  516. pipi_image_t *src, *result;
  517. ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
  518. result = pipi_median(src, value);
  519. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  520. }
  521. PHP_FUNCTION(pipi_median_ext) {
  522. zval *_zval;
  523. long rx, ry = 0;
  524. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &rx, &ry) == FAILURE) {
  525. RETURN_FALSE;
  526. }
  527. pipi_image_t *src, *result;
  528. ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
  529. result = pipi_median_ext(src, rx, ry);
  530. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  531. }
  532. PHP_FUNCTION(pipi_dilate) {
  533. pipi_image_t *src, *result;
  534. FETCH_IMG(src);
  535. result = pipi_dilate(src);
  536. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  537. }
  538. PHP_FUNCTION(pipi_erode) {
  539. pipi_image_t *src, *result;
  540. FETCH_IMG(src);
  541. result = pipi_erode(src);
  542. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  543. }
  544. PHP_FUNCTION(pipi_order) {
  545. pipi_image_t *src, *result;
  546. FETCH_IMG(src);
  547. result = pipi_order(src);
  548. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  549. }
  550. PHP_FUNCTION(pipi_tile) {
  551. zval *_zval;
  552. long width, height = 0;
  553. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &width, &height) == FAILURE) {
  554. RETURN_FALSE;
  555. }
  556. pipi_image_t *src, *result;
  557. ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
  558. result = pipi_tile(src, width, height);
  559. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  560. }
  561. PHP_FUNCTION(pipi_flood_fill) {
  562. }
  563. PHP_FUNCTION(pipi_draw_line) {
  564. }
  565. PHP_FUNCTION(pipi_draw_polyline) {
  566. }
  567. PHP_FUNCTION(pipi_draw_bezier4) {
  568. }
  569. PHP_FUNCTION(pipi_reduce) {
  570. }
  571. PHP_FUNCTION(pipi_dither_ediff) {
  572. }
  573. PHP_FUNCTION(pipi_dither_ordered) {
  574. pipi_image_t *img1, *img2, *result;
  575. FETCH_IMG_IMG(img1, img2);
  576. result = pipi_dither_ordered(img1, img2);
  577. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  578. }
  579. PHP_FUNCTION(pipi_dither_ordered_ext) {
  580. zval *_zval1;
  581. zval *_zval2;
  582. double precision, angle = 0;
  583. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrdd", &_zval1, &_zval2, &precision, &angle) == FAILURE) {
  584. RETURN_FALSE;
  585. }
  586. pipi_image_t *img1, *img2, *result;
  587. ZEND_FETCH_RESOURCE(img1, pipi_image_t*, &_zval1, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
  588. ZEND_FETCH_RESOURCE(img2, pipi_image_t*, &_zval2, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
  589. result = pipi_dither_ordered_ext(img1, img2, precision, angle);
  590. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  591. }
  592. PHP_FUNCTION(pipi_dither_halftone) {
  593. zval *_zval;
  594. double r, angle = 0;
  595. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rdd", &_zval, &r, &angle) == FAILURE) {
  596. RETURN_FALSE;
  597. }
  598. pipi_image_t *src, *result;
  599. ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
  600. result = pipi_dither_halftone(src, r, angle);
  601. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  602. }
  603. PHP_FUNCTION(pipi_dither_random) {
  604. pipi_image_t *src, *result;
  605. FETCH_IMG(src);
  606. result = pipi_dither_random(src);
  607. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  608. }
  609. PHP_FUNCTION(pipi_dither_ostromoukhov) {
  610. }
  611. PHP_FUNCTION(pipi_dither_dbs) {
  612. pipi_image_t *src, *result;
  613. FETCH_IMG(src);
  614. result = pipi_dither_dbs(src);
  615. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  616. }
  617. PHP_FUNCTION(pipi_dither_24to16) {
  618. pipi_image_t *img;
  619. FETCH_IMG(img);
  620. pipi_dither_24to16(img);
  621. }
  622. PHP_FUNCTION(pipi_new_histogram) {
  623. pipi_histogram_t *histogram;
  624. histogram = pipi_new_histogram();
  625. ZEND_REGISTER_RESOURCE(return_value, histogram, le_pipi_histogram);
  626. }
  627. PHP_FUNCTION(pipi_get_image_histogram) {
  628. zval *_zval_img, *_zval_hst;
  629. long flags = 0;
  630. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrl", &_zval_img, &_zval_hst, &flags) == FAILURE) {
  631. RETURN_FALSE;
  632. }
  633. pipi_image_t *image;
  634. pipi_histogram_t *histogram;
  635. ZEND_FETCH_RESOURCE(image, pipi_image_t*, &_zval_img, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
  636. ZEND_FETCH_RESOURCE(histogram, pipi_histogram_t*, &_zval_hst, -1, PHP_PIPI_HISTOGRAM_RES_NAME, le_pipi_histogram);
  637. RETURN_LONG(pipi_get_image_histogram(image, histogram, flags));
  638. }
  639. PHP_FUNCTION(pipi_render_histogram) {
  640. zval *_zval_img, *_zval_hst;
  641. long flags = 0;
  642. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrl", &_zval_img, &_zval_hst, &flags) == FAILURE) {
  643. RETURN_FALSE;
  644. }
  645. pipi_image_t *image;
  646. pipi_histogram_t *histogram;
  647. ZEND_FETCH_RESOURCE(image, pipi_image_t*, &_zval_img, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
  648. ZEND_FETCH_RESOURCE(histogram, pipi_histogram_t*, &_zval_hst, -1, PHP_PIPI_HISTOGRAM_RES_NAME, le_pipi_histogram);
  649. RETURN_LONG(pipi_render_histogram(image, histogram, flags));
  650. }