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

Last change on this file since 3164 was 3164, checked in by Sam Hocevar, 12 years ago

Quick and dirty implementation of pipi_draw_rectangle() to save zMoo.

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