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

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