source: libpipi/trunk/pipi-php/php_pipi.c @ 3080

Last change on this file since 3080 was 3080, checked in by nico, 12 years ago

Add php binding for functions: pipi_render_histogram, pipi_get_image_histogram
Add a sample program: examples/histogram.php

File size: 20.7 KB
Line 
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
13#ifdef HAVE_CONFIG_H
14#include "config.h"
15#endif
16
17#include "php.h"
18#include "php_pipi.h"
19
20static function_entry pipi_functions[] = {
21        PHP_FE(pipi_get_color_from_string, NULL)   
22        PHP_FE(pipi_get_version, NULL)
23        PHP_FE(pipi_create_context, NULL)
24        PHP_FE(pipi_get_command_list, NULL)
25        PHP_FE(pipi_command, NULL)
26        PHP_FE(pipi_load, NULL)
27        PHP_FE(pipi_load_stock, NULL)
28        PHP_FE(pipi_new, NULL)
29        PHP_FE(pipi_copy, NULL)
30        PHP_FE(pipi_save, NULL)
31        PHP_FE(pipi_set_gamma, NULL)
32        PHP_FE(pipi_getpixels, NULL)
33        PHP_FE(pipi_get_image_width, NULL)
34        PHP_FE(pipi_get_image_height, NULL)
35        PHP_FE(pipi_get_image_pitch, NULL)
36        PHP_FE(pipi_get_image_last_modified, NULL)
37        PHP_FE(pipi_get_format_name, NULL)
38        PHP_FE(pipi_measure_msd, NULL)
39        PHP_FE(pipi_measure_rmsd, NULL)
40        PHP_FE(pipi_resize, NULL)
41        PHP_FE(pipi_render_random, NULL)
42        PHP_FE(pipi_render_bayer, NULL)
43        PHP_FE(pipi_render_halftone, NULL)
44        PHP_FE(pipi_rgb, NULL)
45        PHP_FE(pipi_red, NULL)
46        PHP_FE(pipi_green, NULL)
47        PHP_FE(pipi_blue, NULL)
48        PHP_FE(pipi_mean, NULL)
49        PHP_FE(pipi_min, NULL)
50        PHP_FE(pipi_max, NULL)
51        PHP_FE(pipi_add, NULL)
52        PHP_FE(pipi_sub, NULL)
53        PHP_FE(pipi_difference, NULL)
54        PHP_FE(pipi_multiply, NULL)
55        PHP_FE(pipi_divide, NULL)
56        PHP_FE(pipi_screen, NULL)
57        PHP_FE(pipi_overlay, NULL)
58        PHP_FE(pipi_convolution, NULL)
59        PHP_FE(pipi_gaussian_blur, NULL)
60        PHP_FE(pipi_gaussian_blur_ext, NULL)
61        PHP_FE(pipi_box_blur, NULL)
62        PHP_FE(pipi_box_blur_ext, NULL)
63        PHP_FE(pipi_brightness, NULL)
64        PHP_FE(pipi_contrast, NULL)
65        PHP_FE(pipi_autocontrast, NULL)
66        PHP_FE(pipi_invert, NULL)
67        PHP_FE(pipi_threshold, NULL)
68        PHP_FE(pipi_hflip, NULL)
69        PHP_FE(pipi_vflip, NULL)
70        PHP_FE(pipi_rotate90, NULL)
71        PHP_FE(pipi_rotate180, NULL)
72        PHP_FE(pipi_rotate270, NULL)
73        PHP_FE(pipi_median, NULL)
74        PHP_FE(pipi_median_ext, NULL)
75        PHP_FE(pipi_dilate, NULL)
76        PHP_FE(pipi_erode, NULL)
77        PHP_FE(pipi_order, NULL)
78        PHP_FE(pipi_tile, NULL)
79        PHP_FE(pipi_flood_fill, NULL)
80        PHP_FE(pipi_draw_line, NULL)
81        PHP_FE(pipi_draw_polyline, NULL)
82        PHP_FE(pipi_draw_bezier4, NULL)
83        PHP_FE(pipi_reduce, NULL)
84        PHP_FE(pipi_dither_ediff, NULL)
85        PHP_FE(pipi_dither_ordered, NULL)
86        PHP_FE(pipi_dither_ordered_ext, NULL)
87        PHP_FE(pipi_dither_halftone, NULL)
88        PHP_FE(pipi_dither_random, NULL)
89        PHP_FE(pipi_dither_ostromoukhov, NULL)
90        PHP_FE(pipi_dither_dbs, NULL)
91        PHP_FE(pipi_dither_24to16, NULL)
92        PHP_FE(pipi_new_histogram, NULL)
93        PHP_FE(pipi_get_image_histogram, NULL)
94        PHP_FE(pipi_render_histogram, NULL)
95
96        {NULL, NULL, NULL}
97};
98
99zend_module_entry pipi_module_entry = {
100#if ZEND_MODULE_API_NO >= 20010901
101        STANDARD_MODULE_HEADER,
102#endif
103        PHP_PIPI_EXTNAME,
104        pipi_functions,
105        PHP_MINIT(pipi),
106        NULL,
107        NULL,
108        NULL,
109        PHP_MINFO(pipi),
110#if ZEND_MODULE_API_NO >= 20010901
111        PHP_PIPI_VERSION,
112#endif
113        STANDARD_MODULE_PROPERTIES
114};
115
116#ifdef COMPILE_DL_PIPI
117ZEND_GET_MODULE(pipi)
118#endif
119
120PHP_MINFO_FUNCTION(pipi) {
121        php_info_print_table_start();
122        php_info_print_table_row(2, "Pipi library version", pipi_get_version());
123        php_info_print_table_end();
124}
125
126
127//--------PIPI'S RESSOURCES---------//
128
129static void php_pipi_image_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
130        pipi_free(rsrc->ptr);
131}
132
133static void php_pipi_context_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
134        pipi_destroy_context(rsrc->ptr);
135}
136
137static void php_pipi_histogram_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
138        pipi_free_histogram(rsrc->ptr);
139}
140
141PHP_MINIT_FUNCTION(pipi) {
142        le_pipi_image = zend_register_list_destructors_ex(php_pipi_image_dtor, NULL, PHP_PIPI_IMAGE_RES_NAME, module_number);
143        le_pipi_context = zend_register_list_destructors_ex(php_pipi_context_dtor, NULL, PHP_PIPI_CONTEXT_RES_NAME, module_number);
144        le_pipi_histogram = zend_register_list_destructors_ex(php_pipi_histogram_dtor, NULL, PHP_PIPI_HISTOGRAM_RES_NAME, module_number);
145        return SUCCESS;
146}
147
148//----------SOMEMACROS---------------//
149
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
156#define FETCH_LONG(l) \
157        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &l) == FAILURE) { \
158                RETURN_FALSE; \
159        }
160
161#define FETCH_IMG(img) \
162        zval *_zval; \
163        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) { \
164                RETURN_FALSE; \
165        } \
166        ZEND_FETCH_RESOURCE(img, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
167
168#define FETCH_IMG_IMG(img1, img2) \
169        zval *_zval1; \
170        zval *_zval2; \
171        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr", &_zval1, &_zval2) == FAILURE) { \
172                RETURN_FALSE; \
173        } \
174        ZEND_FETCH_RESOURCE(img1, pipi_image_t*, &_zval1, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image); \
175        ZEND_FETCH_RESOURCE(img2, pipi_image_t*, &_zval2, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
176
177
178
179//--------PIPI'S FUNCTIONS---------//
180
181PHP_FUNCTION(pipi_get_color_from_string) {
182}
183
184PHP_FUNCTION(pipi_get_version) {
185        RETURN_STRING(estrdup(pipi_get_version()), 0);
186}
187
188PHP_FUNCTION(pipi_create_context) {
189        pipi_context_t *context;
190        context = pipi_create_context();
191        ZEND_REGISTER_RESOURCE(return_value, context, le_pipi_context);
192}
193
194PHP_FUNCTION(pipi_get_command_list) {
195        pipi_command_t const *list;
196        pipi_command_t const *cmd;
197        list = pipi_get_command_list();
198
199        array_init(return_value);
200        for (cmd = list; cmd->name; cmd++)
201                add_assoc_long(return_value, (char*) cmd->name, cmd->argc);
202}
203
204PHP_FUNCTION(pipi_command) {
205}
206
207PHP_FUNCTION(pipi_load) {
208        char *str;
209        FETCH_STR(str);
210        pipi_image_t *img;
211        img = pipi_load(str);
212        ZEND_REGISTER_RESOURCE(return_value, img, le_pipi_image);
213}
214
215PHP_FUNCTION(pipi_load_stock) {
216        char *str;
217        FETCH_STR(str);
218        pipi_image_t *img;
219        img = pipi_load_stock(str);
220        ZEND_REGISTER_RESOURCE(return_value, img, le_pipi_image);
221}
222
223PHP_FUNCTION(pipi_new) {
224        long width, height = 0;
225        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &width, &height) == FAILURE) {
226                RETURN_FALSE;
227        }
228        pipi_image_t *img;
229        img = pipi_new(width, height);
230        ZEND_REGISTER_RESOURCE(return_value, img, le_pipi_image);
231}
232
233PHP_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
240PHP_FUNCTION(pipi_save) {
241        zval *res;
242        char *str;
243        int str_len;
244        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &res, &str, &str_len) == FAILURE) {
245                RETURN_FALSE;
246        }
247
248        pipi_image_t *img;
249        ZEND_FETCH_RESOURCE(img, pipi_image_t*, &res, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
250
251        RETURN_LONG(pipi_save(img, str));       
252}
253
254PHP_FUNCTION(pipi_set_gamma) {
255        long value;
256        FETCH_LONG(value);
257        pipi_set_gamma(value);
258}
259
260PHP_FUNCTION(pipi_getpixels) {
261}
262
263PHP_FUNCTION(pipi_get_image_width) {
264        pipi_image_t *img;
265        FETCH_IMG(img);
266        RETURN_LONG(pipi_get_image_width(img));
267}
268
269PHP_FUNCTION(pipi_get_image_height) {
270        pipi_image_t *img;
271        FETCH_IMG(img);
272        RETURN_LONG(pipi_get_image_height(img));
273}
274
275PHP_FUNCTION(pipi_get_image_pitch) {
276        pipi_image_t *img;
277        FETCH_IMG(img);
278        RETURN_LONG(pipi_get_image_pitch(img));
279}
280
281PHP_FUNCTION(pipi_get_image_last_modified) {
282        pipi_image_t *img;
283        FETCH_IMG(img);
284        RETURN_LONG(pipi_get_image_last_midified(img));
285}
286
287PHP_FUNCTION(pipi_get_format_name) {
288        long id;
289        FETCH_LONG(id);
290        RETURN_STRING(estrdup(pipi_get_format_name(id)), 0);
291}
292
293PHP_FUNCTION(pipi_measure_msd) {
294        pipi_image_t *img1, *img2;
295        FETCH_IMG_IMG(img1, img2);
296        RETURN_LONG(pipi_measure_msd(img1, img2));
297}
298
299PHP_FUNCTION(pipi_measure_rmsd) {
300        pipi_image_t *img1, *img2;
301        FETCH_IMG_IMG(img1, img2);
302        RETURN_LONG(pipi_measure_rmsd(img1, img2));
303}
304
305PHP_FUNCTION(pipi_resize) {
306        zval *_zval;
307        long width, height = 0;
308        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &width, &height) == FAILURE) {
309                RETURN_FALSE;
310        }
311        pipi_image_t *src, *result;
312        ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
313
314        result = pipi_resize(src, width, height);
315        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
316}
317
318PHP_FUNCTION(pipi_render_random) {
319        long width, height = 0;
320        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &width, &height) == FAILURE) {
321                RETURN_FALSE;
322        }
323        pipi_image_t *img;
324        img = pipi_render_random(width, height);
325        ZEND_REGISTER_RESOURCE(return_value, img, le_pipi_image);
326}
327
328PHP_FUNCTION(pipi_render_bayer) {
329        long width, height = 0;
330        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &width, &height) == FAILURE) {
331                RETURN_FALSE;
332        }
333        pipi_image_t *img;
334        img = pipi_render_bayer(width, height);
335        ZEND_REGISTER_RESOURCE(return_value, img, le_pipi_image);
336}
337
338PHP_FUNCTION(pipi_render_halftone) {
339        long width, height = 0;
340        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &width, &height) == FAILURE) {
341                RETURN_FALSE;
342        }
343        pipi_image_t *img;
344        img = pipi_render_halftone(width, height);
345        ZEND_REGISTER_RESOURCE(return_value, img, le_pipi_image);
346}
347
348PHP_FUNCTION(pipi_rgb) {
349        zval *_zval1, *_zval2, *_zval3;
350        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrr", &_zval1, &_zval2, &_zval3) == FAILURE) {
351                RETURN_FALSE;
352        }
353
354        pipi_image_t *img_r, *img_g, *img_b, *result;
355        ZEND_FETCH_RESOURCE(img_r, pipi_image_t*, &_zval1, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
356        ZEND_FETCH_RESOURCE(img_g, pipi_image_t*, &_zval2, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
357        ZEND_FETCH_RESOURCE(img_b, pipi_image_t*, &_zval3, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
358
359        result = pipi_rgb(img_r, img_g, img_b);
360        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
361}
362
363PHP_FUNCTION(pipi_red) {
364        pipi_image_t *src, *result;
365        FETCH_IMG(src);
366        result = pipi_red(src);
367        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
368}
369
370PHP_FUNCTION(pipi_green) {
371        pipi_image_t *src, *result;
372        FETCH_IMG(src);
373        result = pipi_green(src);
374        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
375}
376
377PHP_FUNCTION(pipi_blue) {
378        pipi_image_t *src, *result;
379        FETCH_IMG(src);
380        result = pipi_blue(src);
381        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
382}
383
384PHP_FUNCTION(pipi_mean) {
385        pipi_image_t *img1, *img2, *result;
386        FETCH_IMG_IMG(img1, img2);
387        result = pipi_mean(img1, img2);
388        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
389}
390
391PHP_FUNCTION(pipi_min) {
392        pipi_image_t *img1, *img2, *result;
393        FETCH_IMG_IMG(img1, img2);
394        result = pipi_min(img1, img2);
395        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
396}
397
398PHP_FUNCTION(pipi_max) {
399        pipi_image_t *img1, *img2, *result;
400        FETCH_IMG_IMG(img1, img2);
401        result = pipi_max(img1, img2);
402        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
403}
404
405PHP_FUNCTION(pipi_add) {
406        pipi_image_t *img1, *img2, *result;
407        FETCH_IMG_IMG(img1, img2);
408        result = pipi_add(img1, img2);
409        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
410}
411
412PHP_FUNCTION(pipi_sub) {
413        pipi_image_t *img1, *img2, *result;
414        FETCH_IMG_IMG(img1, img2);
415        result = pipi_sub(img1, img2);
416        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
417}
418
419PHP_FUNCTION(pipi_difference) {
420        pipi_image_t *img1, *img2, *result;
421        FETCH_IMG_IMG(img1, img2);
422        result = pipi_difference(img1, img2);
423        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
424}
425
426PHP_FUNCTION(pipi_multiply) {
427        pipi_image_t *img1, *img2, *result;
428        FETCH_IMG_IMG(img1, img2);
429        result = pipi_multiply(img1, img2);
430        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
431}
432
433PHP_FUNCTION(pipi_divide) {
434        pipi_image_t *img1, *img2, *result;
435        FETCH_IMG_IMG(img1, img2);
436        result = pipi_divide(img1, img2);
437        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
438}
439
440PHP_FUNCTION(pipi_screen) {
441        pipi_image_t *img1, *img2, *result;
442        FETCH_IMG_IMG(img1, img2);
443        result = pipi_screen(img1, img2);
444        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
445}
446
447PHP_FUNCTION(pipi_overlay) {
448        pipi_image_t *img1, *img2, *result;
449        FETCH_IMG_IMG(img1, img2);
450        result = pipi_overlay(img1, img2);
451        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
452}
453
454PHP_FUNCTION(pipi_convolution) {
455}
456
457PHP_FUNCTION(pipi_gaussian_blur) {
458        zval *_zval;
459        double value = 0;
460        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rd", &_zval, &value) == FAILURE) {
461                RETURN_FALSE;
462        }
463        pipi_image_t *src, *result;
464        ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
465
466        result = pipi_gaussian_blur(src, value);
467        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
468}
469
470PHP_FUNCTION(pipi_gaussian_blur_ext) {
471        zval *_zval;
472        double v1, v2, v3, v4, v5 = 0;
473        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rddddd", &_zval, &v1, &v2, &v3, &v4, &v5) == 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
479        result = pipi_gaussian_blur_ext(src, v1, v2, v3, v4, v5);
480        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
481}
482
483PHP_FUNCTION(pipi_box_blur) {
484        zval *_zval;
485        long value = 0;
486        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &_zval, &value) == FAILURE) {
487                RETURN_FALSE;
488        }
489        pipi_image_t *src, *result;
490        ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
491
492        result = pipi_box_blur(src, value);
493        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
494}
495
496PHP_FUNCTION(pipi_box_blur_ext) {
497        zval *_zval;
498        long m, n = 0;
499        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &m, &n) == FAILURE) {
500                RETURN_FALSE;
501        }
502        pipi_image_t *src, *result;
503        ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
504
505        result = pipi_box_blur_ext(src, m, n);
506        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
507}
508
509PHP_FUNCTION(pipi_brightness) {
510        zval *_zval;
511        double value = 0;
512        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rd", &_zval, &value) == FAILURE) {
513                RETURN_FALSE;
514        }
515        pipi_image_t *src, *result;
516        ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
517
518        result = pipi_brightness(src, value);
519        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
520}
521
522PHP_FUNCTION(pipi_contrast) {
523        zval *_zval;
524        double value = 0;
525        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rd", &_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
531        result = pipi_contrast(src, value);
532        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
533}
534
535PHP_FUNCTION(pipi_autocontrast) {
536        pipi_image_t *src, *result;
537        FETCH_IMG(src);
538        result = pipi_autocontrast(src);
539        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
540}
541
542PHP_FUNCTION(pipi_invert) {
543        pipi_image_t *src, *result;
544        FETCH_IMG(src);
545        result = pipi_invert(src);
546        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
547}
548
549PHP_FUNCTION(pipi_threshold) {
550        zval *_zval;
551        double value = 0;
552        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rd", &_zval, &value) == FAILURE) {
553                RETURN_FALSE;
554        }
555        pipi_image_t *src, *result;
556        ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
557
558        result = pipi_threshold(src, value);
559        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
560}
561
562PHP_FUNCTION(pipi_hflip) {
563        pipi_image_t *src, *result;
564        FETCH_IMG(src);
565        result = pipi_hflip(src);
566        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
567}
568
569PHP_FUNCTION(pipi_vflip) {
570        pipi_image_t *src, *result;
571        FETCH_IMG(src);
572        result = pipi_vflip(src);
573        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
574}
575
576PHP_FUNCTION(pipi_rotate90) {
577        pipi_image_t *src, *result;
578        FETCH_IMG(src);
579        result = pipi_rotate90(src);
580        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
581}
582
583PHP_FUNCTION(pipi_rotate180) {
584        pipi_image_t *src, *result;
585        FETCH_IMG(src);
586        result = pipi_rotate180(src);
587        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
588}
589
590PHP_FUNCTION(pipi_rotate270) {
591        pipi_image_t *src, *result;
592        FETCH_IMG(src);
593        result = pipi_rotate270(src);
594        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
595}
596
597PHP_FUNCTION(pipi_median) {
598        zval *_zval;
599        long value = 0;
600        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &_zval, &value) == FAILURE) {
601                RETURN_FALSE;
602        }
603        pipi_image_t *src, *result;
604        ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
605
606        result = pipi_median(src, value);
607        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
608}
609
610PHP_FUNCTION(pipi_median_ext) {
611        zval *_zval;
612        long rx, ry = 0;
613        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &rx, &ry) == FAILURE) {
614                RETURN_FALSE;
615        }
616        pipi_image_t *src, *result;
617        ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
618
619        result = pipi_median_ext(src, rx, ry);
620        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
621}
622
623PHP_FUNCTION(pipi_dilate) {
624        pipi_image_t *src, *result;
625        FETCH_IMG(src);
626        result = pipi_dilate(src);
627        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
628}
629
630PHP_FUNCTION(pipi_erode) {
631        pipi_image_t *src, *result;
632        FETCH_IMG(src);
633        result = pipi_erode(src);
634        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
635}
636
637PHP_FUNCTION(pipi_order) {
638        pipi_image_t *src, *result;
639        FETCH_IMG(src);
640        result = pipi_order(src);
641        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
642}
643
644PHP_FUNCTION(pipi_tile) {
645        zval *_zval;
646        long width, height = 0;
647        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &width, &height) == FAILURE) {
648                RETURN_FALSE;
649        }
650        pipi_image_t *src, *result;
651        ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
652
653        result = pipi_tile(src, width, height);
654        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
655}
656
657PHP_FUNCTION(pipi_flood_fill) {
658}
659
660PHP_FUNCTION(pipi_draw_line) {
661}
662
663PHP_FUNCTION(pipi_draw_polyline) {
664}
665
666PHP_FUNCTION(pipi_draw_bezier4) {
667}
668
669PHP_FUNCTION(pipi_reduce) {
670}
671
672PHP_FUNCTION(pipi_dither_ediff) {
673}
674
675PHP_FUNCTION(pipi_dither_ordered) {
676        pipi_image_t *img1, *img2, *result;
677        FETCH_IMG_IMG(img1, img2);
678        result = pipi_dither_ordered(img1, img2);
679        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
680}
681
682PHP_FUNCTION(pipi_dither_ordered_ext) {
683        zval *_zval1;
684        zval *_zval2;
685        double precision, angle = 0;
686        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrdd", &_zval1, &_zval2, &precision, &angle) == FAILURE) {
687                RETURN_FALSE;
688        }
689        pipi_image_t *img1, *img2, *result;
690        ZEND_FETCH_RESOURCE(img1, pipi_image_t*, &_zval1, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
691        ZEND_FETCH_RESOURCE(img2, pipi_image_t*, &_zval2, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
692
693        result = pipi_dither_ordered_ext(img1, img2, precision, angle);
694        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
695}
696
697PHP_FUNCTION(pipi_dither_halftone) {
698        zval *_zval;
699        double r, angle = 0;
700        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rdd", &_zval, &r, &angle) == FAILURE) {
701                RETURN_FALSE;
702        }
703        pipi_image_t *src, *result;
704        ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
705
706        result = pipi_dither_halftone(src, r, angle);
707        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
708}
709
710PHP_FUNCTION(pipi_dither_random) {
711        pipi_image_t *src, *result;
712        FETCH_IMG(src);
713        result = pipi_dither_random(src);
714        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
715}
716
717PHP_FUNCTION(pipi_dither_ostromoukhov) {
718}
719
720PHP_FUNCTION(pipi_dither_dbs) {
721        pipi_image_t *src, *result;
722        FETCH_IMG(src);
723        result = pipi_dither_dbs(src);
724        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
725}
726
727PHP_FUNCTION(pipi_dither_24to16) {
728        pipi_image_t *img;
729        FETCH_IMG(img);
730        pipi_dither_24to16(img);
731}
732
733PHP_FUNCTION(pipi_new_histogram) {
734        pipi_histogram_t *histogram;
735        histogram = pipi_new_histogram();
736        ZEND_REGISTER_RESOURCE(return_value, histogram, le_pipi_histogram);
737}
738
739PHP_FUNCTION(pipi_get_image_histogram) {
740        zval *_zval_img, *_zval_hst;
741        long flags = 0;
742        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrl", &_zval_img, &_zval_hst, &flags) == FAILURE) {
743                RETURN_FALSE;
744        }
745        pipi_image_t *image;
746        pipi_histogram_t *histogram;
747        ZEND_FETCH_RESOURCE(image, pipi_image_t*, &_zval_img, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
748        ZEND_FETCH_RESOURCE(histogram, pipi_histogram_t*, &_zval_hst, -1, PHP_PIPI_HISTOGRAM_RES_NAME, le_pipi_histogram);
749
750        RETURN_LONG(pipi_get_image_histogram(image, histogram, flags));
751}
752
753PHP_FUNCTION(pipi_render_histogram) {
754        zval *_zval_img, *_zval_hst;
755        long flags = 0;
756        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrl", &_zval_img, &_zval_hst, &flags) == FAILURE) {
757                RETURN_FALSE;
758        }
759        pipi_image_t *image;
760        pipi_histogram_t *histogram;
761        ZEND_FETCH_RESOURCE(image, pipi_image_t*, &_zval_img, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
762        ZEND_FETCH_RESOURCE(histogram, pipi_histogram_t*, &_zval_hst, -1, PHP_PIPI_HISTOGRAM_RES_NAME, le_pipi_histogram);
763
764        RETURN_LONG(pipi_render_histogram(image, histogram, flags));
765}
766
767
Note: See TracBrowser for help on using the repository browser.