You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

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