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

Last change on this file since 3342 was 3342, checked in by Sam Hocevar, 10 years ago

Change _C pixel format suffixes into _U8 for more clarity.

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