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

Last change on this file since 3087 was 3087, checked in by nico, 12 years ago
  • Change return value for function (success return (bool) true):

pipi_load, pipi_save, pipi_command, pipi_render_histogram,
pipi_get_image_histogram

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