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

Last change on this file since 4696 was 4696, checked in by Sam Hocevar, 9 years ago

Implement bicubic resampling. Lacks some blurring in the pre-pass, maybe.

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