Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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