Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 
 

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