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

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

Add php binding for functions:

pipi_dither_ordered_ext, pipi_dither_halftone, pipi_median_ext, pipi_median,
pipi_threshold, pipi_box_blur_ext, pipi_box_blur, pipi_get_command_list

Add sample program "examples/example1.php"

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