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

Last change on this file since 3086 was 3086, checked in by nico, 13 years ago

Add php binding for pipi_command
Add a php rewrite of pipi.c in examples/

File size: 21.1 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        zval *res;
206        char *arg1, *arg2 = NULL;
207        int arg1_len, arg2_len;
208        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|s", &res, &arg1, &arg1_len, &arg2, &arg2_len) == FAILURE) {
209                RETURN_FALSE;
210        }
211
212        pipi_context_t *ctxt;
213        ZEND_FETCH_RESOURCE(ctxt, pipi_context_t*, &res, -1, PHP_PIPI_CONTEXT_RES_NAME, le_pipi_context);
214
215        if (arg2_len != 0) {
216                RETURN_LONG(pipi_command(ctxt, arg1, arg2));
217        }
218        RETURN_LONG(pipi_command(ctxt, arg1)); 
219}
220
221PHP_FUNCTION(pipi_load) {
222        char *str;
223        FETCH_STR(str);
224        pipi_image_t *img;
225        img = pipi_load(str);
226        ZEND_REGISTER_RESOURCE(return_value, img, le_pipi_image);
227}
228
229PHP_FUNCTION(pipi_load_stock) {
230        char *str;
231        FETCH_STR(str);
232        pipi_image_t *img;
233        img = pipi_load_stock(str);
234        ZEND_REGISTER_RESOURCE(return_value, img, le_pipi_image);
235}
236
237PHP_FUNCTION(pipi_new) {
238        long width, height = 0;
239        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &width, &height) == FAILURE) {
240                RETURN_FALSE;
241        }
242        pipi_image_t *img;
243        img = pipi_new(width, height);
244        ZEND_REGISTER_RESOURCE(return_value, img, le_pipi_image);
245}
246
247PHP_FUNCTION(pipi_copy) {
248        pipi_image_t *src, *result;
249        FETCH_IMG(src);
250        result = pipi_copy(src);
251        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
252}
253
254PHP_FUNCTION(pipi_save) {
255        zval *res;
256        char *str;
257        int str_len;
258        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &res, &str, &str_len) == FAILURE) {
259                RETURN_FALSE;
260        }
261
262        pipi_image_t *img;
263        ZEND_FETCH_RESOURCE(img, pipi_image_t*, &res, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
264
265        RETURN_LONG(pipi_save(img, str));       
266}
267
268PHP_FUNCTION(pipi_set_gamma) {
269        long value;
270        FETCH_LONG(value);
271        pipi_set_gamma(value);
272}
273
274PHP_FUNCTION(pipi_getpixels) {
275}
276
277PHP_FUNCTION(pipi_get_image_width) {
278        pipi_image_t *img;
279        FETCH_IMG(img);
280        RETURN_LONG(pipi_get_image_width(img));
281}
282
283PHP_FUNCTION(pipi_get_image_height) {
284        pipi_image_t *img;
285        FETCH_IMG(img);
286        RETURN_LONG(pipi_get_image_height(img));
287}
288
289PHP_FUNCTION(pipi_get_image_pitch) {
290        pipi_image_t *img;
291        FETCH_IMG(img);
292        RETURN_LONG(pipi_get_image_pitch(img));
293}
294
295PHP_FUNCTION(pipi_get_image_last_modified) {
296        pipi_image_t *img;
297        FETCH_IMG(img);
298        RETURN_LONG(pipi_get_image_last_midified(img));
299}
300
301PHP_FUNCTION(pipi_get_format_name) {
302        long id;
303        FETCH_LONG(id);
304        RETURN_STRING(estrdup(pipi_get_format_name(id)), 0);
305}
306
307PHP_FUNCTION(pipi_measure_msd) {
308        pipi_image_t *img1, *img2;
309        FETCH_IMG_IMG(img1, img2);
310        RETURN_LONG(pipi_measure_msd(img1, img2));
311}
312
313PHP_FUNCTION(pipi_measure_rmsd) {
314        pipi_image_t *img1, *img2;
315        FETCH_IMG_IMG(img1, img2);
316        RETURN_LONG(pipi_measure_rmsd(img1, img2));
317}
318
319PHP_FUNCTION(pipi_resize) {
320        zval *_zval;
321        long width, height = 0;
322        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &width, &height) == FAILURE) {
323                RETURN_FALSE;
324        }
325        pipi_image_t *src, *result;
326        ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
327
328        result = pipi_resize(src, width, height);
329        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
330}
331
332PHP_FUNCTION(pipi_render_random) {
333        long width, height = 0;
334        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &width, &height) == FAILURE) {
335                RETURN_FALSE;
336        }
337        pipi_image_t *img;
338        img = pipi_render_random(width, height);
339        ZEND_REGISTER_RESOURCE(return_value, img, le_pipi_image);
340}
341
342PHP_FUNCTION(pipi_render_bayer) {
343        long width, height = 0;
344        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &width, &height) == FAILURE) {
345                RETURN_FALSE;
346        }
347        pipi_image_t *img;
348        img = pipi_render_bayer(width, height);
349        ZEND_REGISTER_RESOURCE(return_value, img, le_pipi_image);
350}
351
352PHP_FUNCTION(pipi_render_halftone) {
353        long width, height = 0;
354        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &width, &height) == FAILURE) {
355                RETURN_FALSE;
356        }
357        pipi_image_t *img;
358        img = pipi_render_halftone(width, height);
359        ZEND_REGISTER_RESOURCE(return_value, img, le_pipi_image);
360}
361
362PHP_FUNCTION(pipi_rgb) {
363        zval *_zval1, *_zval2, *_zval3;
364        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrr", &_zval1, &_zval2, &_zval3) == FAILURE) {
365                RETURN_FALSE;
366        }
367
368        pipi_image_t *img_r, *img_g, *img_b, *result;
369        ZEND_FETCH_RESOURCE(img_r, pipi_image_t*, &_zval1, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
370        ZEND_FETCH_RESOURCE(img_g, pipi_image_t*, &_zval2, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
371        ZEND_FETCH_RESOURCE(img_b, pipi_image_t*, &_zval3, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
372
373        result = pipi_rgb(img_r, img_g, img_b);
374        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
375}
376
377PHP_FUNCTION(pipi_red) {
378        pipi_image_t *src, *result;
379        FETCH_IMG(src);
380        result = pipi_red(src);
381        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
382}
383
384PHP_FUNCTION(pipi_green) {
385        pipi_image_t *src, *result;
386        FETCH_IMG(src);
387        result = pipi_green(src);
388        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
389}
390
391PHP_FUNCTION(pipi_blue) {
392        pipi_image_t *src, *result;
393        FETCH_IMG(src);
394        result = pipi_blue(src);
395        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
396}
397
398PHP_FUNCTION(pipi_mean) {
399        pipi_image_t *img1, *img2, *result;
400        FETCH_IMG_IMG(img1, img2);
401        result = pipi_mean(img1, img2);
402        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
403}
404
405PHP_FUNCTION(pipi_min) {
406        pipi_image_t *img1, *img2, *result;
407        FETCH_IMG_IMG(img1, img2);
408        result = pipi_min(img1, img2);
409        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
410}
411
412PHP_FUNCTION(pipi_max) {
413        pipi_image_t *img1, *img2, *result;
414        FETCH_IMG_IMG(img1, img2);
415        result = pipi_max(img1, img2);
416        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
417}
418
419PHP_FUNCTION(pipi_add) {
420        pipi_image_t *img1, *img2, *result;
421        FETCH_IMG_IMG(img1, img2);
422        result = pipi_add(img1, img2);
423        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
424}
425
426PHP_FUNCTION(pipi_sub) {
427        pipi_image_t *img1, *img2, *result;
428        FETCH_IMG_IMG(img1, img2);
429        result = pipi_sub(img1, img2);
430        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
431}
432
433PHP_FUNCTION(pipi_difference) {
434        pipi_image_t *img1, *img2, *result;
435        FETCH_IMG_IMG(img1, img2);
436        result = pipi_difference(img1, img2);
437        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
438}
439
440PHP_FUNCTION(pipi_multiply) {
441        pipi_image_t *img1, *img2, *result;
442        FETCH_IMG_IMG(img1, img2);
443        result = pipi_multiply(img1, img2);
444        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
445}
446
447PHP_FUNCTION(pipi_divide) {
448        pipi_image_t *img1, *img2, *result;
449        FETCH_IMG_IMG(img1, img2);
450        result = pipi_divide(img1, img2);
451        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
452}
453
454PHP_FUNCTION(pipi_screen) {
455        pipi_image_t *img1, *img2, *result;
456        FETCH_IMG_IMG(img1, img2);
457        result = pipi_screen(img1, img2);
458        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
459}
460
461PHP_FUNCTION(pipi_overlay) {
462        pipi_image_t *img1, *img2, *result;
463        FETCH_IMG_IMG(img1, img2);
464        result = pipi_overlay(img1, img2);
465        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
466}
467
468PHP_FUNCTION(pipi_convolution) {
469}
470
471PHP_FUNCTION(pipi_gaussian_blur) {
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
480        result = pipi_gaussian_blur(src, value);
481        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
482}
483
484PHP_FUNCTION(pipi_gaussian_blur_ext) {
485        zval *_zval;
486        double v1, v2, v3, v4, v5 = 0;
487        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rddddd", &_zval, &v1, &v2, &v3, &v4, &v5) == FAILURE) {
488                RETURN_FALSE;
489        }
490        pipi_image_t *src, *result;
491        ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
492
493        result = pipi_gaussian_blur_ext(src, v1, v2, v3, v4, v5);
494        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
495}
496
497PHP_FUNCTION(pipi_box_blur) {
498        zval *_zval;
499        long value = 0;
500        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &_zval, &value) == FAILURE) {
501                RETURN_FALSE;
502        }
503        pipi_image_t *src, *result;
504        ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
505
506        result = pipi_box_blur(src, value);
507        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
508}
509
510PHP_FUNCTION(pipi_box_blur_ext) {
511        zval *_zval;
512        long m, n = 0;
513        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &m, &n) == FAILURE) {
514                RETURN_FALSE;
515        }
516        pipi_image_t *src, *result;
517        ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
518
519        result = pipi_box_blur_ext(src, m, n);
520        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
521}
522
523PHP_FUNCTION(pipi_brightness) {
524        zval *_zval;
525        double value = 0;
526        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rd", &_zval, &value) == FAILURE) {
527                RETURN_FALSE;
528        }
529        pipi_image_t *src, *result;
530        ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
531
532        result = pipi_brightness(src, value);
533        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
534}
535
536PHP_FUNCTION(pipi_contrast) {
537        zval *_zval;
538        double value = 0;
539        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rd", &_zval, &value) == FAILURE) {
540                RETURN_FALSE;
541        }
542        pipi_image_t *src, *result;
543        ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
544
545        result = pipi_contrast(src, value);
546        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
547}
548
549PHP_FUNCTION(pipi_autocontrast) {
550        pipi_image_t *src, *result;
551        FETCH_IMG(src);
552        result = pipi_autocontrast(src);
553        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
554}
555
556PHP_FUNCTION(pipi_invert) {
557        pipi_image_t *src, *result;
558        FETCH_IMG(src);
559        result = pipi_invert(src);
560        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
561}
562
563PHP_FUNCTION(pipi_threshold) {
564        zval *_zval;
565        double value = 0;
566        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rd", &_zval, &value) == FAILURE) {
567                RETURN_FALSE;
568        }
569        pipi_image_t *src, *result;
570        ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
571
572        result = pipi_threshold(src, value);
573        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
574}
575
576PHP_FUNCTION(pipi_hflip) {
577        pipi_image_t *src, *result;
578        FETCH_IMG(src);
579        result = pipi_hflip(src);
580        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
581}
582
583PHP_FUNCTION(pipi_vflip) {
584        pipi_image_t *src, *result;
585        FETCH_IMG(src);
586        result = pipi_vflip(src);
587        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
588}
589
590PHP_FUNCTION(pipi_rotate90) {
591        pipi_image_t *src, *result;
592        FETCH_IMG(src);
593        result = pipi_rotate90(src);
594        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
595}
596
597PHP_FUNCTION(pipi_rotate180) {
598        pipi_image_t *src, *result;
599        FETCH_IMG(src);
600        result = pipi_rotate180(src);
601        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
602}
603
604PHP_FUNCTION(pipi_rotate270) {
605        pipi_image_t *src, *result;
606        FETCH_IMG(src);
607        result = pipi_rotate270(src);
608        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
609}
610
611PHP_FUNCTION(pipi_median) {
612        zval *_zval;
613        long value = 0;
614        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &_zval, &value) == FAILURE) {
615                RETURN_FALSE;
616        }
617        pipi_image_t *src, *result;
618        ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
619
620        result = pipi_median(src, value);
621        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
622}
623
624PHP_FUNCTION(pipi_median_ext) {
625        zval *_zval;
626        long rx, ry = 0;
627        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &rx, &ry) == FAILURE) {
628                RETURN_FALSE;
629        }
630        pipi_image_t *src, *result;
631        ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
632
633        result = pipi_median_ext(src, rx, ry);
634        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
635}
636
637PHP_FUNCTION(pipi_dilate) {
638        pipi_image_t *src, *result;
639        FETCH_IMG(src);
640        result = pipi_dilate(src);
641        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
642}
643
644PHP_FUNCTION(pipi_erode) {
645        pipi_image_t *src, *result;
646        FETCH_IMG(src);
647        result = pipi_erode(src);
648        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
649}
650
651PHP_FUNCTION(pipi_order) {
652        pipi_image_t *src, *result;
653        FETCH_IMG(src);
654        result = pipi_order(src);
655        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
656}
657
658PHP_FUNCTION(pipi_tile) {
659        zval *_zval;
660        long width, height = 0;
661        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &width, &height) == FAILURE) {
662                RETURN_FALSE;
663        }
664        pipi_image_t *src, *result;
665        ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
666
667        result = pipi_tile(src, width, height);
668        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
669}
670
671PHP_FUNCTION(pipi_flood_fill) {
672}
673
674PHP_FUNCTION(pipi_draw_line) {
675}
676
677PHP_FUNCTION(pipi_draw_polyline) {
678}
679
680PHP_FUNCTION(pipi_draw_bezier4) {
681}
682
683PHP_FUNCTION(pipi_reduce) {
684}
685
686PHP_FUNCTION(pipi_dither_ediff) {
687}
688
689PHP_FUNCTION(pipi_dither_ordered) {
690        pipi_image_t *img1, *img2, *result;
691        FETCH_IMG_IMG(img1, img2);
692        result = pipi_dither_ordered(img1, img2);
693        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
694}
695
696PHP_FUNCTION(pipi_dither_ordered_ext) {
697        zval *_zval1;
698        zval *_zval2;
699        double precision, angle = 0;
700        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrdd", &_zval1, &_zval2, &precision, &angle) == FAILURE) {
701                RETURN_FALSE;
702        }
703        pipi_image_t *img1, *img2, *result;
704        ZEND_FETCH_RESOURCE(img1, pipi_image_t*, &_zval1, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
705        ZEND_FETCH_RESOURCE(img2, pipi_image_t*, &_zval2, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
706
707        result = pipi_dither_ordered_ext(img1, img2, precision, angle);
708        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
709}
710
711PHP_FUNCTION(pipi_dither_halftone) {
712        zval *_zval;
713        double r, angle = 0;
714        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rdd", &_zval, &r, &angle) == FAILURE) {
715                RETURN_FALSE;
716        }
717        pipi_image_t *src, *result;
718        ZEND_FETCH_RESOURCE(src, pipi_image_t*, &_zval, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
719
720        result = pipi_dither_halftone(src, r, angle);
721        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
722}
723
724PHP_FUNCTION(pipi_dither_random) {
725        pipi_image_t *src, *result;
726        FETCH_IMG(src);
727        result = pipi_dither_random(src);
728        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
729}
730
731PHP_FUNCTION(pipi_dither_ostromoukhov) {
732}
733
734PHP_FUNCTION(pipi_dither_dbs) {
735        pipi_image_t *src, *result;
736        FETCH_IMG(src);
737        result = pipi_dither_dbs(src);
738        ZEND_REGISTER_RESOURCE(return_value, result, le_pipi_image);
739}
740
741PHP_FUNCTION(pipi_dither_24to16) {
742        pipi_image_t *img;
743        FETCH_IMG(img);
744        pipi_dither_24to16(img);
745}
746
747PHP_FUNCTION(pipi_new_histogram) {
748        pipi_histogram_t *histogram;
749        histogram = pipi_new_histogram();
750        ZEND_REGISTER_RESOURCE(return_value, histogram, le_pipi_histogram);
751}
752
753PHP_FUNCTION(pipi_get_image_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_get_image_histogram(image, histogram, flags));
765}
766
767PHP_FUNCTION(pipi_render_histogram) {
768        zval *_zval_img, *_zval_hst;
769        long flags = 0;
770        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrl", &_zval_img, &_zval_hst, &flags) == FAILURE) {
771                RETURN_FALSE;
772        }
773        pipi_image_t *image;
774        pipi_histogram_t *histogram;
775        ZEND_FETCH_RESOURCE(image, pipi_image_t*, &_zval_img, -1, PHP_PIPI_IMAGE_RES_NAME, le_pipi_image);
776        ZEND_FETCH_RESOURCE(histogram, pipi_histogram_t*, &_zval_hst, -1, PHP_PIPI_HISTOGRAM_RES_NAME, le_pipi_histogram);
777
778        RETURN_LONG(pipi_render_histogram(image, histogram, flags));
779}
780
781
Note: See TracBrowser for help on using the repository browser.