Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

782 lignes
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. zval *res;
  179. char *arg1, *arg2 = NULL;
  180. int arg1_len, arg2_len;
  181. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|s", &res, &arg1, &arg1_len, &arg2, &arg2_len) == FAILURE) {
  182. RETURN_FALSE;
  183. }
  184. pipi_context_t *ctxt;
  185. ZEND_FETCH_RESOURCE(ctxt, pipi_context_t*, &res, -1, PHP_PIPI_CONTEXT_RES_NAME, le_pipi_context);
  186. if (arg2_len != 0) {
  187. RETURN_LONG(pipi_command(ctxt, arg1, arg2));
  188. }
  189. RETURN_LONG(pipi_command(ctxt, arg1));
  190. }
  191. PHP_FUNCTION(pipi_load) {
  192. char *str;
  193. FETCH_STR(str);
  194. pipi_image_t *img;
  195. img = pipi_load(str);
  196. ZEND_REGISTER_RESOURCE(return_value, img, le_pipi_image);
  197. }
  198. PHP_FUNCTION(pipi_load_stock) {
  199. char *str;
  200. FETCH_STR(str);
  201. pipi_image_t *img;
  202. img = pipi_load_stock(str);
  203. ZEND_REGISTER_RESOURCE(return_value, img, le_pipi_image);
  204. }
  205. PHP_FUNCTION(pipi_new) {
  206. long width, height = 0;
  207. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &width, &height) == FAILURE) {
  208. RETURN_FALSE;
  209. }
  210. pipi_image_t *img;
  211. img = pipi_new(width, height);
  212. ZEND_REGISTER_RESOURCE(return_value, img, le_pipi_image);
  213. }
  214. PHP_FUNCTION(pipi_copy) {
  215. pipi_image_t *src, *result;
  216. FETCH_IMG(src);
  217. result = pipi_copy(src);
  218. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  219. }
  220. PHP_FUNCTION(pipi_save) {
  221. zval *res;
  222. char *str;
  223. int str_len;
  224. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &res, &str, &str_len) == FAILURE) {
  225. RETURN_FALSE;
  226. }
  227. pipi_image_t *img;
  228. ZEND_FETCH_RESOURCE(img, pipi_image_t*, &res, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
  229. RETURN_LONG(pipi_save(img, str));
  230. }
  231. PHP_FUNCTION(pipi_set_gamma) {
  232. long value;
  233. FETCH_LONG(value);
  234. pipi_set_gamma(value);
  235. }
  236. PHP_FUNCTION(pipi_getpixels) {
  237. }
  238. PHP_FUNCTION(pipi_get_image_width) {
  239. pipi_image_t *img;
  240. FETCH_IMG(img);
  241. RETURN_LONG(pipi_get_image_width(img));
  242. }
  243. PHP_FUNCTION(pipi_get_image_height) {
  244. pipi_image_t *img;
  245. FETCH_IMG(img);
  246. RETURN_LONG(pipi_get_image_height(img));
  247. }
  248. PHP_FUNCTION(pipi_get_image_pitch) {
  249. pipi_image_t *img;
  250. FETCH_IMG(img);
  251. RETURN_LONG(pipi_get_image_pitch(img));
  252. }
  253. PHP_FUNCTION(pipi_get_image_last_modified) {
  254. pipi_image_t *img;
  255. FETCH_IMG(img);
  256. RETURN_LONG(pipi_get_image_last_midified(img));
  257. }
  258. PHP_FUNCTION(pipi_get_format_name) {
  259. long id;
  260. FETCH_LONG(id);
  261. RETURN_STRING(estrdup(pipi_get_format_name(id)), 0);
  262. }
  263. PHP_FUNCTION(pipi_measure_msd) {
  264. pipi_image_t *img1, *img2;
  265. FETCH_IMG_IMG(img1, img2);
  266. RETURN_LONG(pipi_measure_msd(img1, img2));
  267. }
  268. PHP_FUNCTION(pipi_measure_rmsd) {
  269. pipi_image_t *img1, *img2;
  270. FETCH_IMG_IMG(img1, img2);
  271. RETURN_LONG(pipi_measure_rmsd(img1, img2));
  272. }
  273. PHP_FUNCTION(pipi_resize) {
  274. zval *_zval;
  275. long width, height = 0;
  276. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &width, &height) == FAILURE) {
  277. RETURN_FALSE;
  278. }
  279. pipi_image_t *src, *result;
  280. ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
  281. result = pipi_resize(src, width, height);
  282. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  283. }
  284. PHP_FUNCTION(pipi_render_random) {
  285. long width, height = 0;
  286. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &width, &height) == FAILURE) {
  287. RETURN_FALSE;
  288. }
  289. pipi_image_t *img;
  290. img = pipi_render_random(width, height);
  291. ZEND_REGISTER_RESOURCE(return_value, img, le_pipi_image);
  292. }
  293. PHP_FUNCTION(pipi_render_bayer) {
  294. long width, height = 0;
  295. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &width, &height) == FAILURE) {
  296. RETURN_FALSE;
  297. }
  298. pipi_image_t *img;
  299. img = pipi_render_bayer(width, height);
  300. ZEND_REGISTER_RESOURCE(return_value, img, le_pipi_image);
  301. }
  302. PHP_FUNCTION(pipi_render_halftone) {
  303. long width, height = 0;
  304. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &width, &height) == FAILURE) {
  305. RETURN_FALSE;
  306. }
  307. pipi_image_t *img;
  308. img = pipi_render_halftone(width, height);
  309. ZEND_REGISTER_RESOURCE(return_value, img, le_pipi_image);
  310. }
  311. PHP_FUNCTION(pipi_rgb) {
  312. zval *_zval1, *_zval2, *_zval3;
  313. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrr", &_zval1, &_zval2, &_zval3) == FAILURE) {
  314. RETURN_FALSE;
  315. }
  316. pipi_image_t *img_r, *img_g, *img_b, *result;
  317. ZEND_FETCH_RESOURCE(img_r, pipi_image_t*, &_zval1, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
  318. ZEND_FETCH_RESOURCE(img_g, pipi_image_t*, &_zval2, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
  319. ZEND_FETCH_RESOURCE(img_b, pipi_image_t*, &_zval3, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
  320. result = pipi_rgb(img_r, img_g, img_b);
  321. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  322. }
  323. PHP_FUNCTION(pipi_red) {
  324. pipi_image_t *src, *result;
  325. FETCH_IMG(src);
  326. result = pipi_red(src);
  327. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  328. }
  329. PHP_FUNCTION(pipi_green) {
  330. pipi_image_t *src, *result;
  331. FETCH_IMG(src);
  332. result = pipi_green(src);
  333. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  334. }
  335. PHP_FUNCTION(pipi_blue) {
  336. pipi_image_t *src, *result;
  337. FETCH_IMG(src);
  338. result = pipi_blue(src);
  339. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  340. }
  341. PHP_FUNCTION(pipi_mean) {
  342. pipi_image_t *img1, *img2, *result;
  343. FETCH_IMG_IMG(img1, img2);
  344. result = pipi_mean(img1, img2);
  345. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  346. }
  347. PHP_FUNCTION(pipi_min) {
  348. pipi_image_t *img1, *img2, *result;
  349. FETCH_IMG_IMG(img1, img2);
  350. result = pipi_min(img1, img2);
  351. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  352. }
  353. PHP_FUNCTION(pipi_max) {
  354. pipi_image_t *img1, *img2, *result;
  355. FETCH_IMG_IMG(img1, img2);
  356. result = pipi_max(img1, img2);
  357. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  358. }
  359. PHP_FUNCTION(pipi_add) {
  360. pipi_image_t *img1, *img2, *result;
  361. FETCH_IMG_IMG(img1, img2);
  362. result = pipi_add(img1, img2);
  363. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  364. }
  365. PHP_FUNCTION(pipi_sub) {
  366. pipi_image_t *img1, *img2, *result;
  367. FETCH_IMG_IMG(img1, img2);
  368. result = pipi_sub(img1, img2);
  369. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  370. }
  371. PHP_FUNCTION(pipi_difference) {
  372. pipi_image_t *img1, *img2, *result;
  373. FETCH_IMG_IMG(img1, img2);
  374. result = pipi_difference(img1, img2);
  375. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  376. }
  377. PHP_FUNCTION(pipi_multiply) {
  378. pipi_image_t *img1, *img2, *result;
  379. FETCH_IMG_IMG(img1, img2);
  380. result = pipi_multiply(img1, img2);
  381. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  382. }
  383. PHP_FUNCTION(pipi_divide) {
  384. pipi_image_t *img1, *img2, *result;
  385. FETCH_IMG_IMG(img1, img2);
  386. result = pipi_divide(img1, img2);
  387. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  388. }
  389. PHP_FUNCTION(pipi_screen) {
  390. pipi_image_t *img1, *img2, *result;
  391. FETCH_IMG_IMG(img1, img2);
  392. result = pipi_screen(img1, img2);
  393. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  394. }
  395. PHP_FUNCTION(pipi_overlay) {
  396. pipi_image_t *img1, *img2, *result;
  397. FETCH_IMG_IMG(img1, img2);
  398. result = pipi_overlay(img1, img2);
  399. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  400. }
  401. PHP_FUNCTION(pipi_convolution) {
  402. }
  403. PHP_FUNCTION(pipi_gaussian_blur) {
  404. zval *_zval;
  405. double value = 0;
  406. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rd", &_zval, &value) == FAILURE) {
  407. RETURN_FALSE;
  408. }
  409. pipi_image_t *src, *result;
  410. ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
  411. result = pipi_gaussian_blur(src, value);
  412. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  413. }
  414. PHP_FUNCTION(pipi_gaussian_blur_ext) {
  415. zval *_zval;
  416. double v1, v2, v3, v4, v5 = 0;
  417. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rddddd", &_zval, &v1, &v2, &v3, &v4, &v5) == FAILURE) {
  418. RETURN_FALSE;
  419. }
  420. pipi_image_t *src, *result;
  421. ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
  422. result = pipi_gaussian_blur_ext(src, v1, v2, v3, v4, v5);
  423. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  424. }
  425. PHP_FUNCTION(pipi_box_blur) {
  426. zval *_zval;
  427. long value = 0;
  428. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &_zval, &value) == FAILURE) {
  429. RETURN_FALSE;
  430. }
  431. pipi_image_t *src, *result;
  432. ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
  433. result = pipi_box_blur(src, value);
  434. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  435. }
  436. PHP_FUNCTION(pipi_box_blur_ext) {
  437. zval *_zval;
  438. long m, n = 0;
  439. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &m, &n) == FAILURE) {
  440. RETURN_FALSE;
  441. }
  442. pipi_image_t *src, *result;
  443. ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
  444. result = pipi_box_blur_ext(src, m, n);
  445. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  446. }
  447. PHP_FUNCTION(pipi_brightness) {
  448. zval *_zval;
  449. double value = 0;
  450. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rd", &_zval, &value) == FAILURE) {
  451. RETURN_FALSE;
  452. }
  453. pipi_image_t *src, *result;
  454. ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
  455. result = pipi_brightness(src, value);
  456. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  457. }
  458. PHP_FUNCTION(pipi_contrast) {
  459. zval *_zval;
  460. double value = 0;
  461. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rd", &_zval, &value) == FAILURE) {
  462. RETURN_FALSE;
  463. }
  464. pipi_image_t *src, *result;
  465. ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
  466. result = pipi_contrast(src, value);
  467. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  468. }
  469. PHP_FUNCTION(pipi_autocontrast) {
  470. pipi_image_t *src, *result;
  471. FETCH_IMG(src);
  472. result = pipi_autocontrast(src);
  473. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  474. }
  475. PHP_FUNCTION(pipi_invert) {
  476. pipi_image_t *src, *result;
  477. FETCH_IMG(src);
  478. result = pipi_invert(src);
  479. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  480. }
  481. PHP_FUNCTION(pipi_threshold) {
  482. zval *_zval;
  483. double value = 0;
  484. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rd", &_zval, &value) == FAILURE) {
  485. RETURN_FALSE;
  486. }
  487. pipi_image_t *src, *result;
  488. ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
  489. result = pipi_threshold(src, value);
  490. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  491. }
  492. PHP_FUNCTION(pipi_hflip) {
  493. pipi_image_t *src, *result;
  494. FETCH_IMG(src);
  495. result = pipi_hflip(src);
  496. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  497. }
  498. PHP_FUNCTION(pipi_vflip) {
  499. pipi_image_t *src, *result;
  500. FETCH_IMG(src);
  501. result = pipi_vflip(src);
  502. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  503. }
  504. PHP_FUNCTION(pipi_rotate90) {
  505. pipi_image_t *src, *result;
  506. FETCH_IMG(src);
  507. result = pipi_rotate90(src);
  508. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  509. }
  510. PHP_FUNCTION(pipi_rotate180) {
  511. pipi_image_t *src, *result;
  512. FETCH_IMG(src);
  513. result = pipi_rotate180(src);
  514. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  515. }
  516. PHP_FUNCTION(pipi_rotate270) {
  517. pipi_image_t *src, *result;
  518. FETCH_IMG(src);
  519. result = pipi_rotate270(src);
  520. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  521. }
  522. PHP_FUNCTION(pipi_median) {
  523. zval *_zval;
  524. long value = 0;
  525. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &_zval, &value) == FAILURE) {
  526. RETURN_FALSE;
  527. }
  528. pipi_image_t *src, *result;
  529. ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
  530. result = pipi_median(src, value);
  531. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  532. }
  533. PHP_FUNCTION(pipi_median_ext) {
  534. zval *_zval;
  535. long rx, ry = 0;
  536. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &rx, &ry) == FAILURE) {
  537. RETURN_FALSE;
  538. }
  539. pipi_image_t *src, *result;
  540. ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
  541. result = pipi_median_ext(src, rx, ry);
  542. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  543. }
  544. PHP_FUNCTION(pipi_dilate) {
  545. pipi_image_t *src, *result;
  546. FETCH_IMG(src);
  547. result = pipi_dilate(src);
  548. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  549. }
  550. PHP_FUNCTION(pipi_erode) {
  551. pipi_image_t *src, *result;
  552. FETCH_IMG(src);
  553. result = pipi_erode(src);
  554. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  555. }
  556. PHP_FUNCTION(pipi_order) {
  557. pipi_image_t *src, *result;
  558. FETCH_IMG(src);
  559. result = pipi_order(src);
  560. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  561. }
  562. PHP_FUNCTION(pipi_tile) {
  563. zval *_zval;
  564. long width, height = 0;
  565. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &width, &height) == FAILURE) {
  566. RETURN_FALSE;
  567. }
  568. pipi_image_t *src, *result;
  569. ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
  570. result = pipi_tile(src, width, height);
  571. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  572. }
  573. PHP_FUNCTION(pipi_flood_fill) {
  574. }
  575. PHP_FUNCTION(pipi_draw_line) {
  576. }
  577. PHP_FUNCTION(pipi_draw_polyline) {
  578. }
  579. PHP_FUNCTION(pipi_draw_bezier4) {
  580. }
  581. PHP_FUNCTION(pipi_reduce) {
  582. }
  583. PHP_FUNCTION(pipi_dither_ediff) {
  584. }
  585. PHP_FUNCTION(pipi_dither_ordered) {
  586. pipi_image_t *img1, *img2, *result;
  587. FETCH_IMG_IMG(img1, img2);
  588. result = pipi_dither_ordered(img1, img2);
  589. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  590. }
  591. PHP_FUNCTION(pipi_dither_ordered_ext) {
  592. zval *_zval1;
  593. zval *_zval2;
  594. double precision, angle = 0;
  595. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrdd", &_zval1, &_zval2, &precision, &angle) == FAILURE) {
  596. RETURN_FALSE;
  597. }
  598. pipi_image_t *img1, *img2, *result;
  599. ZEND_FETCH_RESOURCE(img1, pipi_image_t*, &_zval1, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
  600. ZEND_FETCH_RESOURCE(img2, pipi_image_t*, &_zval2, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
  601. result = pipi_dither_ordered_ext(img1, img2, precision, angle);
  602. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  603. }
  604. PHP_FUNCTION(pipi_dither_halftone) {
  605. zval *_zval;
  606. double r, angle = 0;
  607. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rdd", &_zval, &r, &angle) == FAILURE) {
  608. RETURN_FALSE;
  609. }
  610. pipi_image_t *src, *result;
  611. ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
  612. result = pipi_dither_halftone(src, r, angle);
  613. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  614. }
  615. PHP_FUNCTION(pipi_dither_random) {
  616. pipi_image_t *src, *result;
  617. FETCH_IMG(src);
  618. result = pipi_dither_random(src);
  619. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  620. }
  621. PHP_FUNCTION(pipi_dither_ostromoukhov) {
  622. }
  623. PHP_FUNCTION(pipi_dither_dbs) {
  624. pipi_image_t *src, *result;
  625. FETCH_IMG(src);
  626. result = pipi_dither_dbs(src);
  627. ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
  628. }
  629. PHP_FUNCTION(pipi_dither_24to16) {
  630. pipi_image_t *img;
  631. FETCH_IMG(img);
  632. pipi_dither_24to16(img);
  633. }
  634. PHP_FUNCTION(pipi_new_histogram) {
  635. pipi_histogram_t *histogram;
  636. histogram = pipi_new_histogram();
  637. ZEND_REGISTER_RESOURCE(return_value, histogram, le_pipi_histogram);
  638. }
  639. PHP_FUNCTION(pipi_get_image_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_get_image_histogram(image, histogram, flags));
  650. }
  651. PHP_FUNCTION(pipi_render_histogram) {
  652. zval *_zval_img, *_zval_hst;
  653. long flags = 0;
  654. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrl", &_zval_img, &_zval_hst, &flags) == FAILURE) {
  655. RETURN_FALSE;
  656. }
  657. pipi_image_t *image;
  658. pipi_histogram_t *histogram;
  659. ZEND_FETCH_RESOURCE(image, pipi_image_t*, &_zval_img, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
  660. ZEND_FETCH_RESOURCE(histogram, pipi_histogram_t*, &_zval_hst, -1, PHP_PIPI_HISTOGRAM_RES_NAME, le_pipi_histogram);
  661. RETURN_LONG(pipi_render_histogram(image, histogram, flags));
  662. }