source: libcaca/trunk/caca-php/php_caca.c @ 4304

Last change on this file since 4304 was 3587, checked in by Sam Hocevar, 11 years ago

Rename caca_get_cursor_x() and caca_get_cursor_y() to caca_wherex() and
caca_wherey(), in order to match the old <conio.h> naming scheme.

File size: 63.2 KB
Line 
1/*
2 *  php-caca      Php binding for Libcaca
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_caca.h"
19
20#ifdef HAVE_GD
21#include <gd.h>
22#endif
23
24static function_entry caca_functions[] = {
25    PHP_FE(caca_create_canvas, NULL)
26    PHP_FE(caca_set_canvas_size, NULL)
27    PHP_FE(caca_get_canvas_width, NULL)
28    PHP_FE(caca_get_canvas_height, NULL)
29    PHP_FE(caca_get_canvas_chars, NULL)
30    PHP_FE(caca_get_canvas_attrs, NULL)
31    PHP_FE(caca_rand, NULL)
32    PHP_FE(caca_get_version, NULL)
33    PHP_FE(caca_gotoxy, NULL)
34    PHP_FE(caca_wherex, NULL)
35    PHP_FE(caca_wherey, NULL)
36    PHP_FE(caca_put_char, NULL)
37    PHP_FE(caca_get_char, NULL)
38    PHP_FE(caca_put_str, NULL)
39    PHP_FE(caca_clear_canvas, NULL)
40    PHP_FE(caca_set_canvas_handle, NULL)
41    PHP_FE(caca_get_canvas_handle_x, NULL)
42    PHP_FE(caca_get_canvas_handle_y, NULL)
43    PHP_FE(caca_blit, NULL)
44    PHP_FE(caca_set_canvas_boundaries, NULL)
45    PHP_FE(caca_invert, NULL)
46    PHP_FE(caca_flip, NULL)
47    PHP_FE(caca_flop, NULL)
48    PHP_FE(caca_rotate_180, NULL)
49    PHP_FE(caca_rotate_left, NULL)
50    PHP_FE(caca_rotate_right, NULL)
51    PHP_FE(caca_stretch_left, NULL)
52    PHP_FE(caca_stretch_right, NULL)
53    PHP_FE(caca_get_attr, NULL)
54    PHP_FE(caca_set_attr, NULL)
55    PHP_FE(caca_put_attr, NULL)
56    PHP_FE(caca_set_color_ansi, NULL)
57    PHP_FE(caca_set_color_argb, NULL)
58    PHP_FE(caca_attr_to_ansi, NULL)
59    PHP_FE(caca_attr_to_ansi_fg, NULL)
60    PHP_FE(caca_attr_to_ansi_bg, NULL)
61    PHP_FE(caca_attr_to_rgb12_fg, NULL)
62    PHP_FE(caca_attr_to_rgb12_bg, NULL)
63    PHP_FE(caca_attr_to_argb64, NULL)
64    PHP_FE(caca_utf8_to_utf32, NULL)
65    PHP_FE(caca_utf32_to_utf8, NULL)
66    PHP_FE(caca_utf32_to_cp437, NULL)
67    PHP_FE(caca_cp437_to_utf32, NULL)
68    PHP_FE(caca_utf32_to_ascii, NULL)
69    PHP_FE(caca_utf32_is_fullwidth, NULL)
70    PHP_FE(caca_draw_line, NULL)
71    PHP_FE(caca_draw_polyline, NULL)
72    PHP_FE(caca_draw_thin_line, NULL)
73    PHP_FE(caca_draw_thin_polyline, NULL)
74    PHP_FE(caca_draw_circle, NULL)
75    PHP_FE(caca_draw_ellipse, NULL)
76    PHP_FE(caca_draw_thin_ellipse, NULL)
77    PHP_FE(caca_fill_ellipse, NULL)
78    PHP_FE(caca_draw_box, NULL)
79    PHP_FE(caca_draw_thin_box, NULL)
80    PHP_FE(caca_draw_cp437_box, NULL)
81    PHP_FE(caca_fill_box, NULL)
82    PHP_FE(caca_draw_triangle, NULL)
83    PHP_FE(caca_draw_thin_triangle, NULL)
84    PHP_FE(caca_fill_triangle, NULL)
85    PHP_FE(caca_get_frame_count, NULL)
86    PHP_FE(caca_set_frame, NULL)
87    PHP_FE(caca_set_frame_name, NULL)
88    PHP_FE(caca_create_frame, NULL)
89    PHP_FE(caca_free_frame, NULL)
90    PHP_FE(caca_create_dither, NULL)
91    PHP_FE(caca_set_dither_palette, NULL)
92    PHP_FE(caca_set_dither_brightness, NULL)
93    PHP_FE(caca_get_dither_brightness, NULL)
94    PHP_FE(caca_set_dither_gamma, NULL)
95    PHP_FE(caca_get_dither_gamma, NULL)
96    PHP_FE(caca_set_dither_contrast, NULL)
97    PHP_FE(caca_get_dither_contrast, NULL)
98    PHP_FE(caca_set_dither_antialias, NULL)
99    PHP_FE(caca_get_dither_antialias_list, NULL)
100    PHP_FE(caca_get_dither_antialias, NULL)
101    PHP_FE(caca_set_dither_color, NULL)
102    PHP_FE(caca_get_dither_color_list, NULL)
103    PHP_FE(caca_get_dither_color, NULL)
104    PHP_FE(caca_set_dither_charset, NULL)
105    PHP_FE(caca_get_dither_charset_list, NULL)
106    PHP_FE(caca_get_dither_charset, NULL)
107    PHP_FE(caca_set_dither_algorithm, NULL)
108    PHP_FE(caca_get_dither_algorithm_list, NULL)
109    PHP_FE(caca_get_dither_algorithm, NULL)
110    PHP_FE(caca_dither_bitmap, NULL)
111    PHP_FE(caca_load_font, NULL)
112    PHP_FE(caca_load_builtin_font, NULL)
113    PHP_FE(caca_get_font_list, NULL)
114    PHP_FE(caca_get_font_width, NULL)
115    PHP_FE(caca_get_font_height, NULL)
116    PHP_FE(caca_get_font_blocks, NULL)
117    PHP_FE(caca_render_canvas, NULL)
118    PHP_FE(caca_canvas_set_figfont, NULL)
119    PHP_FE(caca_put_figchar, NULL)
120    PHP_FE(caca_flush_figlet, NULL)
121    PHP_FE(caca_file_open, NULL)
122    PHP_FE(caca_file_close, NULL)
123    PHP_FE(caca_file_tell, NULL)
124    PHP_FE(caca_file_read, NULL)
125    PHP_FE(caca_file_write, NULL)
126    PHP_FE(caca_file_gets, NULL)
127    PHP_FE(caca_file_eof, NULL)
128    PHP_FE(caca_import_string, NULL)
129    PHP_FE(caca_import_file, NULL)
130    PHP_FE(caca_get_import_list, NULL)
131    PHP_FE(caca_export_string, NULL)
132    PHP_FE(caca_get_export_list, NULL)
133    PHP_FE(caca_create_display, NULL)
134    PHP_FE(caca_create_display_with_driver, NULL)
135    PHP_FE(caca_get_display_driver_list, NULL)
136    PHP_FE(caca_get_display_driver, NULL)
137    PHP_FE(caca_set_display_driver, NULL)
138    PHP_FE(caca_get_canvas, NULL)
139    PHP_FE(caca_refresh_display, NULL)
140    PHP_FE(caca_set_display_time, NULL)
141    PHP_FE(caca_get_display_time, NULL)
142    PHP_FE(caca_get_display_width, NULL)
143    PHP_FE(caca_get_display_height, NULL)
144    PHP_FE(caca_set_display_title, NULL)
145    PHP_FE(caca_set_mouse, NULL)
146    PHP_FE(caca_set_cursor, NULL)
147    PHP_FE(caca_get_event, NULL)
148    PHP_FE(caca_get_mouse_x, NULL)
149    PHP_FE(caca_get_mouse_y, NULL)
150    PHP_FE(caca_get_event_type, NULL)
151    PHP_FE(caca_get_event_key_ch, NULL)
152    PHP_FE(caca_get_event_mouse_button, NULL)
153    PHP_FE(caca_get_event_mouse_x, NULL)
154    PHP_FE(caca_get_event_mouse_y, NULL)
155    PHP_FE(caca_get_event_resize_width, NULL)
156    PHP_FE(caca_get_event_resize_height, NULL)
157
158    {NULL, NULL, NULL}
159};
160
161zend_module_entry caca_module_entry = {
162#if ZEND_MODULE_API_NO >= 20010901
163    STANDARD_MODULE_HEADER,
164#endif
165    PHP_CACA_EXTNAME,
166    caca_functions,
167    PHP_MINIT(caca),
168    NULL,
169    NULL,
170    NULL,
171    PHP_MINFO(caca),
172#if ZEND_MODULE_API_NO >= 20010901
173    PHP_CACA_VERSION,
174#endif
175    STANDARD_MODULE_PROPERTIES
176};
177
178#ifdef COMPILE_DL_CACA
179ZEND_GET_MODULE(caca)
180#endif
181
182PHP_MINFO_FUNCTION(caca) {
183    php_info_print_table_start();
184    php_info_print_table_row(2, "Caca library version", caca_get_version());
185#ifdef HAVE_GD
186    php_info_print_table_row(2, "Gd support", "enabled");
187    php_info_print_table_row(2, "Gd API version", GD_VERSION_STRING);
188#else
189    php_info_print_table_row(2, "Compiled with gd support", "disabled");
190#endif
191    php_info_print_table_end();
192}
193
194//-------- Caca's ressources destructors -----------//
195
196static void php_caca_canvas_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
197    caca_free_canvas(rsrc->ptr);
198}
199
200static void php_caca_dither_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
201    caca_free_dither(rsrc->ptr);
202}
203
204static void php_caca_font_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
205    caca_free_font(rsrc->ptr);
206}
207
208static void php_caca_file_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
209    caca_file_close(rsrc->ptr);
210}
211
212static void php_caca_display_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
213    caca_free_display(rsrc->ptr);
214}
215
216static void php_caca_event_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
217    efree((caca_event_t *) rsrc->ptr);
218}
219
220//-------- Initialization ---------//
221
222PHP_MINIT_FUNCTION(caca) {
223
224    le_caca_canvas = zend_register_list_destructors_ex(php_caca_canvas_dtor, NULL, PHP_CACA_CANVAS_RES_NAME, module_number);
225    le_caca_dither = zend_register_list_destructors_ex(php_caca_dither_dtor, NULL, PHP_CACA_DITHER_RES_NAME, module_number);
226    le_caca_font = zend_register_list_destructors_ex(php_caca_font_dtor, NULL, PHP_CACA_FONT_RES_NAME, module_number);
227    le_caca_file = zend_register_list_destructors_ex(php_caca_file_dtor, NULL, PHP_CACA_FILE_RES_NAME, module_number);
228    le_caca_display = zend_register_list_destructors_ex(php_caca_display_dtor, NULL, PHP_CACA_DISPLAY_RES_NAME, module_number);
229    le_caca_event = zend_register_list_destructors_ex(php_caca_event_dtor, NULL, PHP_CACA_EVENT_RES_NAME, module_number);
230
231    REGISTER_LONG_CONSTANT("CACA_BLACK", CACA_BLACK, CONST_CS | CONST_PERSISTENT);
232    REGISTER_LONG_CONSTANT("CACA_BLUE", CACA_BLUE, CONST_CS | CONST_PERSISTENT);
233    REGISTER_LONG_CONSTANT("CACA_GREEN", CACA_GREEN, CONST_CS | CONST_PERSISTENT);
234    REGISTER_LONG_CONSTANT("CACA_CYAN", CACA_CYAN, CONST_CS | CONST_PERSISTENT);
235    REGISTER_LONG_CONSTANT("CACA_RED", CACA_RED, CONST_CS | CONST_PERSISTENT);
236    REGISTER_LONG_CONSTANT("CACA_MAGENTA", CACA_MAGENTA, CONST_CS | CONST_PERSISTENT);
237    REGISTER_LONG_CONSTANT("CACA_BROWN", CACA_BROWN, CONST_CS | CONST_PERSISTENT);
238    REGISTER_LONG_CONSTANT("CACA_LIGHTGRAY", CACA_LIGHTGRAY, CONST_CS | CONST_PERSISTENT);
239    REGISTER_LONG_CONSTANT("CACA_DARKGRAY", CACA_DARKGRAY, CONST_CS | CONST_PERSISTENT);
240    REGISTER_LONG_CONSTANT("CACA_LIGHTBLUE", CACA_LIGHTBLUE, CONST_CS | CONST_PERSISTENT);
241    REGISTER_LONG_CONSTANT("CACA_LIGHTGREEN", CACA_LIGHTGREEN, CONST_CS | CONST_PERSISTENT);
242    REGISTER_LONG_CONSTANT("CACA_LIGHTCYAN", CACA_LIGHTCYAN, CONST_CS | CONST_PERSISTENT);
243    REGISTER_LONG_CONSTANT("CACA_LIGHTRED", CACA_LIGHTRED, CONST_CS | CONST_PERSISTENT);
244    REGISTER_LONG_CONSTANT("CACA_LIGHTMAGENTA", CACA_LIGHTMAGENTA, CONST_CS | CONST_PERSISTENT);
245    REGISTER_LONG_CONSTANT("CACA_YELLOW", CACA_YELLOW, CONST_CS | CONST_PERSISTENT);
246    REGISTER_LONG_CONSTANT("CACA_WHITE", CACA_WHITE, CONST_CS | CONST_PERSISTENT);
247    REGISTER_LONG_CONSTANT("CACA_DEFAULT", CACA_DEFAULT, CONST_CS | CONST_PERSISTENT);
248    REGISTER_LONG_CONSTANT("CACA_TRANSPARENT", CACA_TRANSPARENT, CONST_CS | CONST_PERSISTENT);
249    REGISTER_LONG_CONSTANT("CACA_BOLD", CACA_BOLD, CONST_CS | CONST_PERSISTENT);
250    REGISTER_LONG_CONSTANT("CACA_ITALICS", CACA_ITALICS, CONST_CS | CONST_PERSISTENT);
251    REGISTER_LONG_CONSTANT("CACA_UNDERLINE", CACA_UNDERLINE, CONST_CS | CONST_PERSISTENT);
252    REGISTER_LONG_CONSTANT("CACA_BLINK", CACA_BLINK, CONST_CS | CONST_PERSISTENT);
253
254    REGISTER_LONG_CONSTANT("CACA_EVENT_NONE", CACA_EVENT_NONE, CONST_CS | CONST_PERSISTENT);
255    REGISTER_LONG_CONSTANT("CACA_EVENT_KEY_PRESS", CACA_EVENT_KEY_PRESS, CONST_CS | CONST_PERSISTENT);
256    REGISTER_LONG_CONSTANT("CACA_EVENT_KEY_RELEASE", CACA_EVENT_KEY_RELEASE, CONST_CS | CONST_PERSISTENT);
257    REGISTER_LONG_CONSTANT("CACA_EVENT_MOUSE_PRESS", CACA_EVENT_MOUSE_PRESS, CONST_CS | CONST_PERSISTENT);
258    REGISTER_LONG_CONSTANT("CACA_EVENT_MOUSE_RELEASE", CACA_EVENT_MOUSE_RELEASE, CONST_CS | CONST_PERSISTENT);
259    REGISTER_LONG_CONSTANT("CACA_EVENT_MOUSE_MOTION", CACA_EVENT_MOUSE_MOTION, CONST_CS | CONST_PERSISTENT);
260    REGISTER_LONG_CONSTANT("CACA_EVENT_RESIZE", CACA_EVENT_RESIZE, CONST_CS | CONST_PERSISTENT);
261    REGISTER_LONG_CONSTANT("CACA_EVENT_QUIT", CACA_EVENT_QUIT, CONST_CS | CONST_PERSISTENT);
262    REGISTER_LONG_CONSTANT("CACA_EVENT_ANY", CACA_EVENT_ANY, CONST_CS | CONST_PERSISTENT);
263
264    REGISTER_LONG_CONSTANT("CACA_KEY_UNKNOWN", CACA_KEY_UNKNOWN, CONST_CS | CONST_PERSISTENT);
265    REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_A", CACA_KEY_CTRL_A, CONST_CS | CONST_PERSISTENT);
266    REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_B", CACA_KEY_CTRL_B, CONST_CS | CONST_PERSISTENT);
267    REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_C", CACA_KEY_CTRL_C, CONST_CS | CONST_PERSISTENT);
268    REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_D", CACA_KEY_CTRL_D, CONST_CS | CONST_PERSISTENT);
269    REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_E", CACA_KEY_CTRL_E, CONST_CS | CONST_PERSISTENT);
270    REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_F", CACA_KEY_CTRL_F, CONST_CS | CONST_PERSISTENT);
271    REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_G", CACA_KEY_CTRL_G, CONST_CS | CONST_PERSISTENT);
272    REGISTER_LONG_CONSTANT("CACA_KEY_BACKSPACE", CACA_KEY_BACKSPACE, CONST_CS | CONST_PERSISTENT);
273    REGISTER_LONG_CONSTANT("CACA_KEY_TAB", CACA_KEY_TAB, CONST_CS | CONST_PERSISTENT);
274    REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_J", CACA_KEY_CTRL_J, CONST_CS | CONST_PERSISTENT);
275    REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_K", CACA_KEY_CTRL_K, CONST_CS | CONST_PERSISTENT);
276    REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_L", CACA_KEY_CTRL_L, CONST_CS | CONST_PERSISTENT);
277    REGISTER_LONG_CONSTANT("CACA_KEY_RETURN", CACA_KEY_RETURN, CONST_CS | CONST_PERSISTENT);
278    REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_N", CACA_KEY_CTRL_N, CONST_CS | CONST_PERSISTENT);
279    REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_O", CACA_KEY_CTRL_O, CONST_CS | CONST_PERSISTENT);
280    REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_P", CACA_KEY_CTRL_P, CONST_CS | CONST_PERSISTENT);
281    REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_Q", CACA_KEY_CTRL_Q, CONST_CS | CONST_PERSISTENT);
282    REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_R", CACA_KEY_CTRL_R, CONST_CS | CONST_PERSISTENT);
283    REGISTER_LONG_CONSTANT("CACA_KEY_PAUSE", CACA_KEY_PAUSE, CONST_CS | CONST_PERSISTENT);
284    REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_T", CACA_KEY_CTRL_T, CONST_CS | CONST_PERSISTENT);
285    REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_U", CACA_KEY_CTRL_U, CONST_CS | CONST_PERSISTENT);
286    REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_V", CACA_KEY_CTRL_V, CONST_CS | CONST_PERSISTENT);
287    REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_W", CACA_KEY_CTRL_W, CONST_CS | CONST_PERSISTENT);
288    REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_X", CACA_KEY_CTRL_X, CONST_CS | CONST_PERSISTENT);
289    REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_Y", CACA_KEY_CTRL_Y, CONST_CS | CONST_PERSISTENT);
290    REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_Z", CACA_KEY_CTRL_Z, CONST_CS | CONST_PERSISTENT);
291    REGISTER_LONG_CONSTANT("CACA_KEY_ESCAPE", CACA_KEY_ESCAPE, CONST_CS | CONST_PERSISTENT);
292    REGISTER_LONG_CONSTANT("CACA_KEY_DELETE", CACA_KEY_DELETE, CONST_CS | CONST_PERSISTENT);
293    REGISTER_LONG_CONSTANT("CACA_KEY_UP", CACA_KEY_UP, CONST_CS | CONST_PERSISTENT);
294    REGISTER_LONG_CONSTANT("CACA_KEY_DOWN", CACA_KEY_DOWN, CONST_CS | CONST_PERSISTENT);
295    REGISTER_LONG_CONSTANT("CACA_KEY_LEFT", CACA_KEY_LEFT, CONST_CS | CONST_PERSISTENT);
296    REGISTER_LONG_CONSTANT("CACA_KEY_RIGHT", CACA_KEY_RIGHT, CONST_CS | CONST_PERSISTENT);
297    REGISTER_LONG_CONSTANT("CACA_KEY_INSERT", CACA_KEY_INSERT, CONST_CS | CONST_PERSISTENT);
298    REGISTER_LONG_CONSTANT("CACA_KEY_HOME", CACA_KEY_HOME, CONST_CS | CONST_PERSISTENT);
299    REGISTER_LONG_CONSTANT("CACA_KEY_END", CACA_KEY_END, CONST_CS | CONST_PERSISTENT);
300    REGISTER_LONG_CONSTANT("CACA_KEY_PAGEUP", CACA_KEY_PAGEUP, CONST_CS | CONST_PERSISTENT);
301    REGISTER_LONG_CONSTANT("CACA_KEY_PAGEDOWN", CACA_KEY_PAGEDOWN, CONST_CS | CONST_PERSISTENT);
302    REGISTER_LONG_CONSTANT("CACA_KEY_F1", CACA_KEY_F1, CONST_CS | CONST_PERSISTENT);
303    REGISTER_LONG_CONSTANT("CACA_KEY_F2", CACA_KEY_F2, CONST_CS | CONST_PERSISTENT);
304    REGISTER_LONG_CONSTANT("CACA_KEY_F3", CACA_KEY_F3, CONST_CS | CONST_PERSISTENT);
305    REGISTER_LONG_CONSTANT("CACA_KEY_F4", CACA_KEY_F4, CONST_CS | CONST_PERSISTENT);
306    REGISTER_LONG_CONSTANT("CACA_KEY_F5", CACA_KEY_F5, CONST_CS | CONST_PERSISTENT);
307    REGISTER_LONG_CONSTANT("CACA_KEY_F6", CACA_KEY_F6, CONST_CS | CONST_PERSISTENT);
308    REGISTER_LONG_CONSTANT("CACA_KEY_F7", CACA_KEY_F7, CONST_CS | CONST_PERSISTENT);
309    REGISTER_LONG_CONSTANT("CACA_KEY_F8", CACA_KEY_F8, CONST_CS | CONST_PERSISTENT);
310    REGISTER_LONG_CONSTANT("CACA_KEY_F9", CACA_KEY_F9, CONST_CS | CONST_PERSISTENT);
311    REGISTER_LONG_CONSTANT("CACA_KEY_F10", CACA_KEY_F10, CONST_CS | CONST_PERSISTENT);
312    REGISTER_LONG_CONSTANT("CACA_KEY_F11", CACA_KEY_F11, CONST_CS | CONST_PERSISTENT);
313    REGISTER_LONG_CONSTANT("CACA_KEY_F12", CACA_KEY_F12, CONST_CS | CONST_PERSISTENT);
314    REGISTER_LONG_CONSTANT("CACA_KEY_F13", CACA_KEY_F13, CONST_CS | CONST_PERSISTENT);
315    REGISTER_LONG_CONSTANT("CACA_KEY_F14", CACA_KEY_F14, CONST_CS | CONST_PERSISTENT);
316    REGISTER_LONG_CONSTANT("CACA_KEY_F15", CACA_KEY_F15, CONST_CS | CONST_PERSISTENT);
317
318    return SUCCESS;
319}
320
321//---------- Some usefull macros ---------------//
322
323#define FETCH_CANVAS(canvas) \
324    zval *_zval; \
325    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) { \
326        RETURN_FALSE; \
327    } \
328    ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
329
330#define FETCH_DISPLAY(display) \
331    zval *_zval; \
332    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) { \
333        RETURN_FALSE; \
334    } \
335    ZEND_FETCH_RESOURCE(display, caca_display_t*, &_zval, -1, PHP_CACA_DISPLAY_RES_NAME, le_caca_display);
336
337#define FETCH_EVENT(event) \
338    zval *_zval; \
339    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) { \
340        RETURN_FALSE; \
341    } \
342    ZEND_FETCH_RESOURCE(event, caca_event_t*, &_zval, -1, PHP_CACA_EVENT_RES_NAME, le_caca_event);
343
344#define FETCH_LONG(l) \
345    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &l) == FAILURE) { \
346        RETURN_FALSE; \
347    }
348
349#define RETURN_CHAR(c) \
350    char *str = emalloc(2); \
351    str[0] = c; \
352    str[1] = '\0'; \
353    RETURN_STRING(str, 0);
354
355#define RETURN_SUCCESS(i) \
356    RETURN_BOOL((i) == 0);
357
358//---------- Some usefull functions --------------------//
359
360//Fetch external php resources such as gd resouces
361
362void *fetch_external_resource(zval *_zval, char const *type_name) {
363    int resource_id = _zval->value.lval;
364    int resource_type;
365    void *result = zend_list_find(resource_id, &resource_type);
366    if (!result)
367        return NULL;
368    char *resource_type_name = zend_rsrc_list_get_rsrc_type(resource_id);
369    return (strcmp(resource_type_name, type_name) == 0) ? result : NULL;
370}
371
372//Fetch buffer of pixels from gdImage
373
374#ifdef HAVE_GD
375void *gd_get_pixels(gdImage *img) {
376    void *result;
377    int i, j, pitch;
378    if (img->trueColor)  {
379        pitch = img->sx * sizeof(int);
380        result = malloc(img->sy * pitch);
381        if (result)
382        {
383            for (i = 0; i < img->sy; i++) {
384                for (j = 0; j < img->sx; j++) {
385                    int *dst = (int *) (((char *) result) + i * pitch + j * sizeof(int));
386
387                    *dst = (((255 - (uint8_t) ((((uint32_t) img->tpixels[i][j]) & 0x7f000000) >> 23)) << 24)
388                        |
389                        (img->tpixels[i][j] & 0x00ffffff));
390                }
391            }
392        }
393    }
394    else {
395        pitch = img->sx * sizeof(char);
396        result = malloc(img->sy * pitch);
397        for (j = 0; j < img->sy; j++)
398            memcpy(result + (j * pitch), (const void *) img->pixels[j], pitch);
399    }
400    return result;
401}
402
403int gd_load_palette(gdImage *img, caca_dither_t *dither) {
404    if (!img || img->trueColor || gdMaxColors != 256) {
405        return -1;
406    }
407
408    uint32_t r[256], g[256], b[256], a[256];
409    int i;
410    for (i = 0; i < 256; i++) {
411        r[i] = img->red[i] << 4;
412        g[i] = img->green[i] << 4;
413        b[i] = img->blue[i] << 4;
414        a[i] = img->alpha[i] << 4;
415    }
416
417    return caca_set_dither_palette(dither, &r[0], &g[0], &b[0], &a[0]);
418}
419#endif
420//------- Caca's functions ----------------//
421
422PHP_FUNCTION(caca_create_canvas) {
423    long width, height = 0;
424    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &width, &height) == FAILURE) {
425        RETURN_FALSE;
426    }
427    caca_canvas_t *canvas = caca_create_canvas(width, height);
428    if (!canvas) {
429        RETURN_FALSE;
430    }
431    ZEND_REGISTER_RESOURCE(return_value, canvas, le_caca_canvas);
432}
433
434PHP_FUNCTION(caca_set_canvas_size) {
435    zval *_zval;
436    long width, height = 0;
437    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &width, &height) == FAILURE) {
438        RETURN_FALSE;
439    }
440    caca_canvas_t *canvas;
441    ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
442    RETURN_SUCCESS(caca_set_canvas_size(canvas, width, height));
443}
444
445PHP_FUNCTION(caca_get_canvas_width) {
446    caca_canvas_t *canvas;
447    FETCH_CANVAS(canvas);
448    RETURN_LONG(caca_get_canvas_width(canvas));
449}
450
451PHP_FUNCTION(caca_get_canvas_height) {
452    caca_canvas_t *canvas;
453    FETCH_CANVAS(canvas);
454    RETURN_LONG(caca_get_canvas_height(canvas));
455}
456
457PHP_FUNCTION(caca_get_canvas_chars) {
458    caca_canvas_t *canvas;
459    FETCH_CANVAS(canvas);
460    RETURN_STRING((char *) caca_get_canvas_chars(canvas), 1);
461}
462
463PHP_FUNCTION(caca_get_canvas_attrs) {
464    caca_canvas_t *canvas;
465    FETCH_CANVAS(canvas);
466    RETURN_STRING((char *) caca_get_canvas_attrs(canvas), 1);
467}
468
469PHP_FUNCTION(caca_rand) {
470    long min, max = 0;
471    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &min, &max) == FAILURE) {
472        RETURN_FALSE;
473    }
474    RETURN_LONG(caca_rand(min, max));
475}
476
477PHP_FUNCTION(caca_get_version) {
478    if (ZEND_NUM_ARGS() != 0) {
479        WRONG_PARAM_COUNT;
480    }
481    RETURN_STRING((char *) caca_get_version(), 1);
482}
483
484PHP_FUNCTION(caca_gotoxy) {
485    zval *_zval;
486    long x, y = 0;
487    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &x, &y) == FAILURE) {
488        RETURN_FALSE;
489    }
490    caca_canvas_t *canvas;
491    ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
492    RETURN_SUCCESS(caca_gotoxy(canvas, x, y));
493}
494
495PHP_FUNCTION(caca_wherex) {
496    caca_canvas_t *canvas;
497    FETCH_CANVAS(canvas);
498    RETURN_LONG(caca_wherex(canvas));
499}
500
501PHP_FUNCTION(caca_wherey) {
502    caca_canvas_t *canvas;
503    FETCH_CANVAS(canvas);
504    RETURN_LONG(caca_wherey(canvas));
505}
506
507PHP_FUNCTION(caca_put_char) {
508    zval *_zval;
509    long x, y, c;
510    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlll", &_zval, &x, &y, &c) == FAILURE) {
511        RETURN_FALSE;
512    }
513    caca_canvas_t *canvas;
514    ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
515    RETURN_SUCCESS(caca_put_char(canvas, x, y, c));
516}
517
518PHP_FUNCTION(caca_get_char) {
519    zval *_zval;
520    long x, y = 0;
521    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &x, &y) == FAILURE) {
522        RETURN_FALSE;
523    }
524    caca_canvas_t *canvas;
525    ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
526    RETURN_CHAR(caca_get_char(canvas, x, y));
527}
528
529PHP_FUNCTION(caca_put_str) {
530    zval *_zval;
531    char *str;
532    long x, y, str_len = 0;
533    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlls", &_zval, &x, &y, &str, &str_len) == FAILURE) {
534        RETURN_FALSE;
535    }
536    caca_canvas_t *canvas;
537    ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
538    RETURN_SUCCESS(caca_put_str(canvas, x, y, str));
539}
540
541PHP_FUNCTION(caca_clear_canvas) {
542    caca_canvas_t *canvas;
543    FETCH_CANVAS(canvas);
544    RETURN_LONG(caca_clear_canvas(canvas));
545}
546
547PHP_FUNCTION(caca_set_canvas_handle) {
548    zval *_zval;
549    long x, y = 0;
550    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &x, &y) == FAILURE) {
551        RETURN_FALSE;
552    }
553    caca_canvas_t *canvas;
554    ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
555    RETURN_SUCCESS(caca_set_canvas_handle(canvas, x, y));
556}
557
558PHP_FUNCTION(caca_get_canvas_handle_x) {
559    caca_canvas_t *canvas;
560    FETCH_CANVAS(canvas);
561    RETURN_LONG(caca_get_canvas_handle_x(canvas));
562}
563
564PHP_FUNCTION(caca_get_canvas_handle_y) {
565    caca_canvas_t *canvas;
566    FETCH_CANVAS(canvas);
567    RETURN_LONG(caca_get_canvas_handle_y(canvas));
568}
569
570PHP_FUNCTION(caca_blit) {
571    zval *_zval1, *_zval2, *_zval3 = NULL;
572    long x, y = 0;
573    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllr|r", &_zval1, &x, &y, &_zval2, &_zval3) == FAILURE) {
574        RETURN_FALSE;
575    }
576    caca_canvas_t *dst, *src, *mask = NULL;
577    ZEND_FETCH_RESOURCE(dst, caca_canvas_t*, &_zval1, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
578    ZEND_FETCH_RESOURCE(src, caca_canvas_t*, &_zval2, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
579    if (_zval3) {
580        ZEND_FETCH_RESOURCE(mask, caca_canvas_t*, &_zval3, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
581    }
582    RETURN_SUCCESS(caca_blit(dst, x, y, src, NULL));
583}
584
585PHP_FUNCTION(caca_set_canvas_boundaries) {
586    zval *_zval;
587    long x, y, width, height = 0;
588    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll", &_zval, &x, &y, &width, &height) == FAILURE) {
589        RETURN_FALSE;
590    }
591    caca_canvas_t *canvas;
592    ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
593    RETURN_SUCCESS(caca_set_canvas_boundaries(canvas, x, y, width, height));
594}
595
596PHP_FUNCTION(caca_invert) {
597    caca_canvas_t *canvas;
598    FETCH_CANVAS(canvas);
599    RETURN_SUCCESS(caca_invert(canvas));
600}
601
602PHP_FUNCTION(caca_flip) {
603    caca_canvas_t *canvas;
604    FETCH_CANVAS(canvas);
605    RETURN_SUCCESS(caca_flip(canvas));
606}
607
608PHP_FUNCTION(caca_flop) {
609    caca_canvas_t *canvas;
610    FETCH_CANVAS(canvas);
611    RETURN_SUCCESS(caca_flop(canvas));
612}
613
614PHP_FUNCTION(caca_rotate_180) {
615    caca_canvas_t *canvas;
616    FETCH_CANVAS(canvas);
617    RETURN_SUCCESS(caca_rotate_180(canvas));
618}
619
620PHP_FUNCTION(caca_rotate_left) {
621    caca_canvas_t *canvas;
622    FETCH_CANVAS(canvas);
623    RETURN_SUCCESS(caca_rotate_left(canvas));
624}
625
626PHP_FUNCTION(caca_rotate_right) {
627    caca_canvas_t *canvas;
628    FETCH_CANVAS(canvas);
629    RETURN_SUCCESS(caca_rotate_right(canvas));
630}
631
632PHP_FUNCTION(caca_stretch_left) {
633    caca_canvas_t *canvas;
634    FETCH_CANVAS(canvas);
635    RETURN_SUCCESS(caca_stretch_left(canvas));
636}
637
638PHP_FUNCTION(caca_stretch_right) {
639    caca_canvas_t *canvas;
640    FETCH_CANVAS(canvas);
641    RETURN_SUCCESS(caca_stretch_right(canvas));
642}
643
644PHP_FUNCTION(caca_get_attr) {
645    zval *_zval;
646    long x, y = 0;
647    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &x, &y) == FAILURE) {
648        RETURN_FALSE;
649    }
650    caca_canvas_t *canvas;
651    ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
652    RETURN_LONG(caca_get_attr(canvas, x, y));
653}
654
655PHP_FUNCTION(caca_set_attr) {
656    zval *_zval;
657    long attr = 0;
658    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &_zval, &attr) == FAILURE) {
659        RETURN_FALSE;
660    }
661    caca_canvas_t *canvas;
662    ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
663    RETURN_SUCCESS(caca_set_attr(canvas, attr));
664}
665
666PHP_FUNCTION(caca_put_attr) {
667    zval *_zval;
668    long x, y, attr = 0;
669    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlll", &_zval, &x, &y, &attr) == FAILURE) {
670        RETURN_FALSE;
671    }
672    caca_canvas_t *canvas;
673    ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
674    RETURN_SUCCESS(caca_put_attr(canvas, x, y, attr));
675}
676
677PHP_FUNCTION(caca_set_color_ansi) {
678    zval *_zval;
679    long foreground, background = 0;
680    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &foreground, &background) == FAILURE) {
681        RETURN_FALSE;
682    }
683    caca_canvas_t *canvas;
684    ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
685    RETURN_SUCCESS(caca_set_color_ansi(canvas, foreground, background));
686}
687
688PHP_FUNCTION(caca_set_color_argb) {
689    zval *_zval;
690    long foreground, background = 0;
691    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &foreground, &background) == FAILURE) {
692        RETURN_FALSE;
693    }
694    caca_canvas_t *canvas;
695    ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
696    RETURN_SUCCESS(caca_set_color_argb(canvas, foreground, background));
697}
698
699PHP_FUNCTION(caca_attr_to_ansi) {
700    long l;
701    FETCH_LONG(l);
702    RETURN_LONG(caca_attr_to_ansi(l));
703}
704
705PHP_FUNCTION(caca_attr_to_ansi_fg) {
706    long l;
707    FETCH_LONG(l);
708    RETURN_LONG(caca_attr_to_ansi_fg(l));
709}
710
711PHP_FUNCTION(caca_attr_to_ansi_bg) {
712    long l;
713    FETCH_LONG(l);
714    RETURN_LONG(caca_attr_to_ansi_bg(l));
715}
716
717PHP_FUNCTION(caca_attr_to_rgb12_fg) {
718    long l;
719    FETCH_LONG(l);
720    RETURN_LONG(caca_attr_to_rgb12_fg(l));
721}
722
723PHP_FUNCTION(caca_attr_to_rgb12_bg) {
724    long l;
725    FETCH_LONG(l);
726    RETURN_LONG(caca_attr_to_rgb12_bg(l));
727}
728
729PHP_FUNCTION(caca_attr_to_argb64) {
730    //TODO: write or delete
731}
732
733PHP_FUNCTION(caca_utf8_to_utf32) {
734    //TODO: write or delete
735}
736
737PHP_FUNCTION(caca_utf32_to_utf8) {
738    //TODO: write or delete
739}
740
741PHP_FUNCTION(caca_utf32_to_cp437) {
742    long l;
743    FETCH_LONG(l);
744    RETURN_LONG(caca_utf32_to_cp437(l));
745}
746
747PHP_FUNCTION(caca_cp437_to_utf32) {
748    long l;
749    FETCH_LONG(l);
750    RETURN_LONG(caca_cp437_to_utf32(l));
751}
752
753PHP_FUNCTION(caca_utf32_to_ascii) {
754    long l;
755    FETCH_LONG(l);
756    RETURN_CHAR(caca_utf32_to_ascii(l));
757}
758
759PHP_FUNCTION(caca_utf32_is_fullwidth) {
760    //TODO: write or delete
761}
762
763PHP_FUNCTION(caca_draw_line) {
764    zval *_zval;
765    long xa, ya, xb, yb, c;
766    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllll", &_zval, &xa, &ya, &xb, &yb, &c) == FAILURE) {
767        RETURN_FALSE;
768    }
769    caca_canvas_t *canvas;
770    ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
771    RETURN_SUCCESS(caca_draw_line(canvas, xa, ya, xb, yb, c));
772}
773
774PHP_FUNCTION(caca_draw_polyline) {
775    zval *zval_res, *zval_arr;
776    long c;
777
778    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ral", &zval_res, &zval_arr, &c) == FAILURE) {
779        RETURN_FALSE;
780    }
781
782    caca_canvas_t *canvas;
783    ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &zval_res, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
784
785    HashTable *arr_hash = Z_ARRVAL_P(zval_arr);
786    int lenmax = zend_hash_num_elements(arr_hash);
787    int *tbl_x, *tbl_y;
788    int tbl_count = 0;
789    tbl_x = malloc(sizeof(int) * lenmax);
790    tbl_y = malloc(sizeof(int) * lenmax);
791
792    HashPosition pos;
793    zval **pt, **x, **y;
794    for (
795        zend_hash_internal_pointer_reset_ex(arr_hash, &pos);
796        zend_hash_get_current_data_ex(arr_hash, (void**) &pt, &pos) == SUCCESS;
797        zend_hash_move_forward_ex(arr_hash, &pos)
798    ) {
799        if (
800            Z_TYPE_P(*pt) == IS_ARRAY
801            && (zend_hash_index_find(Z_ARRVAL_P(*pt), 0, (void**) &x) != FAILURE)
802            && (zend_hash_index_find(Z_ARRVAL_P(*pt), 1, (void**) &y) != FAILURE)
803        ) {
804            convert_to_long_ex(x);
805            convert_to_long_ex(y);
806            tbl_x[tbl_count] = Z_LVAL_PP(x);
807            tbl_y[tbl_count] = Z_LVAL_PP(y);
808            tbl_count++;
809        }
810    }
811    int res = caca_draw_polyline(canvas, tbl_x, tbl_y, tbl_count - 1, c);
812    free(tbl_x);
813    free(tbl_y);
814    RETURN_SUCCESS(res);
815}
816
817PHP_FUNCTION(caca_draw_thin_line) {
818    zval *_zval;
819    long xa, ya, xb, yb = 0;
820    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll", &_zval, &xa, &ya, &xb, &yb) == FAILURE) {
821        RETURN_FALSE;
822    }
823    caca_canvas_t *canvas;
824    ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
825    RETURN_SUCCESS(caca_draw_thin_line(canvas, xa, ya, xb, yb));
826}
827
828PHP_FUNCTION(caca_draw_thin_polyline) {
829    zval *zval_res, *zval_arr;
830    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ra", &zval_res, &zval_arr) == FAILURE) {
831        RETURN_FALSE;
832    }
833
834    caca_canvas_t *canvas;
835    ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &zval_res, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
836
837    HashTable *arr_hash = Z_ARRVAL_P(zval_arr);
838    int lenmax = zend_hash_num_elements(arr_hash);
839    int *tbl_x, *tbl_y;
840    int tbl_count = 0;
841    tbl_x = malloc(sizeof(int) * lenmax);
842    tbl_y = malloc(sizeof(int) * lenmax);
843
844    if (!tbl_x || !tbl_y) {
845        RETURN_FALSE;
846    }
847
848    HashPosition pos;
849    zval **pt, **x, **y;
850    for (
851        zend_hash_internal_pointer_reset_ex(arr_hash, &pos);
852        zend_hash_get_current_data_ex(arr_hash, (void**) &pt, &pos) == SUCCESS;
853        zend_hash_move_forward_ex(arr_hash, &pos)
854    ) {
855        if (
856            Z_TYPE_P(*pt) == IS_ARRAY
857            && (zend_hash_index_find(Z_ARRVAL_P(*pt), 0, (void**) &x) != FAILURE)
858            && (zend_hash_index_find(Z_ARRVAL_P(*pt), 1, (void**) &y) != FAILURE)
859        ) {
860            convert_to_long_ex(x);
861            convert_to_long_ex(y);
862            tbl_x[tbl_count] = Z_LVAL_PP(x);
863            tbl_y[tbl_count] = Z_LVAL_PP(y);
864            tbl_count++;
865        }
866    }
867    int res = caca_draw_thin_polyline(canvas, tbl_x, tbl_y, tbl_count - 1);
868    free(tbl_x);
869    free(tbl_y);
870    RETURN_SUCCESS(res);
871}
872
873PHP_FUNCTION(caca_draw_circle) {
874    zval *_zval;
875    long x, y, r, c;
876    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll", &_zval, &x, &y, &r, &c) == FAILURE) {
877        RETURN_FALSE;
878    }
879    caca_canvas_t *canvas;
880    ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
881    RETURN_SUCCESS(caca_draw_circle(canvas, x, y, r, c));
882}
883
884PHP_FUNCTION(caca_draw_ellipse) {
885    zval *_zval;
886    long xa, ya, xb, yb, c = 0;
887    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllll", &_zval, &xa, &ya, &xb, &yb, &c) == FAILURE) {
888        RETURN_FALSE;
889    }
890    caca_canvas_t *canvas;
891    ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
892    RETURN_SUCCESS(caca_draw_ellipse(canvas, xa, ya, xb, yb, c));
893}
894
895PHP_FUNCTION(caca_draw_thin_ellipse) {
896    zval *_zval;
897    long xa, ya, xb, yb = 0;
898    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll", &_zval, &xa, &ya, &xb, &yb) == FAILURE) {
899        RETURN_FALSE;
900    }
901    caca_canvas_t *canvas;
902    ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
903    RETURN_SUCCESS(caca_draw_thin_ellipse(canvas, xa, ya, xb, yb));
904}
905
906PHP_FUNCTION(caca_fill_ellipse) {
907    zval *_zval;
908    long xa, ya, xb, yb, c;
909    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllll", &_zval, &xa, &ya, &xb, &yb, &c) == FAILURE) {
910        RETURN_FALSE;
911    }
912    caca_canvas_t *canvas;
913    ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
914    RETURN_SUCCESS(caca_fill_ellipse(canvas, xa, ya, xb, yb, c));
915}
916
917PHP_FUNCTION(caca_draw_box) {
918    zval *_zval;
919    long xa, ya, xb, yb, c;
920    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllll", &_zval, &xa, &ya, &xb, &yb, &c) == FAILURE) {
921        RETURN_FALSE;
922    }
923    caca_canvas_t *canvas;
924    ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
925    RETURN_SUCCESS(caca_draw_box(canvas, xa, ya, xb, yb, c));
926}
927
928PHP_FUNCTION(caca_draw_thin_box) {
929    zval *_zval;
930    long xa, ya, xb, yb = 0;
931    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll", &_zval, &xa, &ya, &xb, &yb) == FAILURE) {
932        RETURN_FALSE;
933    }
934    caca_canvas_t *canvas;
935    ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
936    RETURN_SUCCESS(caca_draw_thin_box(canvas, xa, ya, xb, yb));
937}
938
939PHP_FUNCTION(caca_draw_cp437_box) {
940    zval *_zval;
941    long xa, ya, xb, yb;
942    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll", &_zval, &xa, &ya, &xb, &yb) == FAILURE) {
943        RETURN_FALSE;
944    }
945    caca_canvas_t *canvas;
946    ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
947    RETURN_SUCCESS(caca_draw_cp437_box(canvas, xa, ya, xb, yb));
948}
949
950PHP_FUNCTION(caca_fill_box) {
951    zval *_zval;
952    long xa, ya, xb, yb, c;
953    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllll", &_zval, &xa, &ya, &xb, &yb, &c) == FAILURE) {
954        RETURN_FALSE;
955    }
956    caca_canvas_t *canvas;
957    ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
958    RETURN_SUCCESS(caca_fill_box(canvas, xa, ya, xb, yb, c));
959}
960
961PHP_FUNCTION(caca_draw_triangle) {
962    zval *_zval;
963    long xa, ya, xb, yb, xc, yc, c;
964    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllllll", &_zval, &xa, &ya, &xb, &yb, &xc, &yc, &c) == FAILURE) {
965        RETURN_FALSE;
966    }
967    caca_canvas_t *canvas;
968    ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
969    RETURN_SUCCESS(caca_draw_triangle(canvas, xa, ya, xb, yb, xc, yc, c));
970}
971
972PHP_FUNCTION(caca_draw_thin_triangle) {
973    zval *_zval;
974    long xa, ya, xb, yb, xc, yc = 0;
975    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllllll", &_zval, &xa, &ya, &xb, &yb, &xc, &yc) == FAILURE) {
976        RETURN_FALSE;
977    }
978    caca_canvas_t *canvas;
979    ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
980    RETURN_SUCCESS(caca_draw_thin_triangle(canvas, xa, ya, xb, yb, xc, yc));
981}
982
983PHP_FUNCTION(caca_fill_triangle) {
984    zval *_zval;
985    long xa, ya, xb, yb, xc, yc, c = 0;
986    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllllll", &_zval, &xa, &ya, &xb, &yb, &xc, &yc, &c) == FAILURE) {
987        RETURN_FALSE;
988    }
989    caca_canvas_t *canvas;
990    ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
991    RETURN_SUCCESS(caca_fill_triangle(canvas, xa, ya, xb, yb, xc, yc, c));
992}
993
994PHP_FUNCTION(caca_get_frame_count) {
995    zval *_zval;
996    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) {
997        RETURN_FALSE;
998    }
999    caca_canvas_t *canvas;
1000    ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
1001    RETURN_LONG(caca_get_canvas_count(canvas));
1002}
1003
1004PHP_FUNCTION(caca_set_frame) {
1005    zval *_zval;
1006    long id;
1007    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &_zval, &id) == FAILURE) {
1008        RETURN_FALSE;
1009    }
1010    caca_canvas_t *canvas;
1011    ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
1012    RETURN_SUCCESS(caca_set_frame(canvas, id));
1013}
1014
1015PHP_FUNCTION(caca_set_frame_name) {
1016    zval *_zval;
1017    char *str;
1018    long str_len;
1019    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &_zval, &str, &str_len) == FAILURE) {
1020        RETURN_FALSE;
1021    }
1022    caca_canvas_t *canvas;
1023    ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
1024    RETURN_SUCCESS(caca_set_frame_name(canvas, str));
1025}
1026
1027PHP_FUNCTION(caca_create_frame) {
1028    zval *_zval;
1029    long id;
1030    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &_zval, &id) == FAILURE) {
1031        RETURN_FALSE;
1032    }
1033    caca_canvas_t *canvas;
1034    ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
1035    RETURN_SUCCESS(caca_create_frame(canvas, id));
1036}
1037
1038PHP_FUNCTION(caca_free_frame) {
1039    zval *_zval;
1040    long id;
1041    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &_zval, &id) == FAILURE) {
1042        RETURN_FALSE;
1043    }
1044    caca_canvas_t *canvas;
1045    ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
1046    RETURN_SUCCESS(caca_free_frame(canvas, id));
1047}
1048
1049PHP_FUNCTION(caca_create_dither) {
1050    zval *_zval;
1051    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) {
1052        RETURN_FALSE;
1053    }
1054#ifdef HAVE_GD
1055    gdImage *img = fetch_external_resource(_zval, "gd");
1056    if (!img) {
1057        RETURN_FALSE;
1058    }
1059
1060    caca_dither_t *dither;
1061    if (img->trueColor)
1062        dither = caca_create_dither(sizeof(int) * 8, img->sx, img->sy, img->sx * sizeof(int), 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
1063    else
1064        dither = caca_create_dither(sizeof(char) * 8, img->sx, img->sy, img->sx * sizeof(char), 0, 0, 0, 0);
1065
1066    if (!dither) {
1067        RETURN_FALSE;
1068    }
1069
1070    ZEND_REGISTER_RESOURCE(return_value, dither, le_caca_dither);
1071#else
1072    RETURN_FALSE
1073#endif
1074}
1075
1076PHP_FUNCTION(caca_set_dither_palette) {
1077    zval *zval_res, *arr;
1078    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ra", &zval_res, &arr) == FAILURE) {
1079        RETURN_FALSE;
1080    }
1081
1082    caca_dither_t *dither;
1083    ZEND_FETCH_RESOURCE(dither, caca_dither_t*, &zval_res, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_dither);
1084
1085    uint32_t tbl[4][256];
1086    zval **color, **value;
1087    int i, j;
1088    for (i = 0; i < 256; i++) {
1089        if (zend_hash_index_find(Z_ARRVAL_P(arr), i, (void**) &color) == FAILURE || Z_TYPE_P(*color) != IS_ARRAY) {
1090            RETURN_FALSE;
1091        }
1092        for (j = 0; j < 4; j++) {
1093            if (zend_hash_index_find(Z_ARRVAL_P(*color), j, (void**) &value) == FAILURE) {
1094                RETURN_FALSE;
1095            }
1096            convert_to_long_ex(value);
1097            tbl[j][i] = Z_LVAL_PP(value);
1098        }
1099    }
1100    RETURN_SUCCESS(caca_set_dither_palette(dither, tbl[0], tbl[1], tbl[2], tbl[3]));
1101}
1102
1103PHP_FUNCTION(caca_set_dither_brightness) {
1104    zval *_zval;
1105    double value;
1106    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rd", &_zval, &value) == FAILURE) {
1107        RETURN_FALSE;
1108    }
1109    caca_dither_t *dither;
1110    ZEND_FETCH_RESOURCE(dither, caca_dither_t*, &_zval, -1, PHP_CACA_DITHER_RES_NAME, le_caca_dither);
1111    RETURN_SUCCESS(caca_set_dither_brightness(dither, value));
1112}
1113
1114PHP_FUNCTION(caca_get_dither_brightness) {
1115    zval *_zval;
1116    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) {
1117        RETURN_FALSE;
1118    }
1119    caca_dither_t *dither;
1120    ZEND_FETCH_RESOURCE(dither, caca_dither_t*, &_zval, -1, PHP_CACA_DITHER_RES_NAME, le_caca_dither);
1121    RETURN_DOUBLE(caca_get_dither_brightness(dither));
1122}
1123
1124PHP_FUNCTION(caca_set_dither_gamma) {
1125    zval *_zval;
1126    double value;
1127    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rd", &_zval, &value) == FAILURE) {
1128        RETURN_FALSE;
1129    }
1130    caca_dither_t *dither;
1131    ZEND_FETCH_RESOURCE(dither, caca_dither_t*, &_zval, -1, PHP_CACA_DITHER_RES_NAME, le_caca_dither);
1132    RETURN_SUCCESS(caca_set_dither_gamma(dither, value));
1133}
1134
1135PHP_FUNCTION(caca_get_dither_gamma) {
1136    zval *_zval;
1137    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) {
1138        RETURN_FALSE;
1139    }
1140    caca_dither_t *dither;
1141    ZEND_FETCH_RESOURCE(dither, caca_dither_t*, &_zval, -1, PHP_CACA_DITHER_RES_NAME, le_caca_dither);
1142    RETURN_DOUBLE(caca_get_dither_gamma(dither));
1143}
1144
1145PHP_FUNCTION(caca_set_dither_contrast) {
1146    zval *_zval;
1147    double value;
1148    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rd", &_zval, &value) == FAILURE) {
1149        RETURN_FALSE;
1150    }
1151    caca_dither_t *dither;
1152    ZEND_FETCH_RESOURCE(dither, caca_dither_t*, &_zval, -1, PHP_CACA_DITHER_RES_NAME, le_caca_dither);
1153    RETURN_SUCCESS(caca_set_dither_contrast(dither, value));
1154}
1155
1156PHP_FUNCTION(caca_get_dither_contrast) {
1157    zval *_zval;
1158    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) {
1159        RETURN_FALSE;
1160    }
1161    caca_dither_t *dither;
1162    ZEND_FETCH_RESOURCE(dither, caca_dither_t*, &_zval, -1, PHP_CACA_DITHER_RES_NAME, le_caca_dither);
1163    RETURN_DOUBLE(caca_get_dither_contrast(dither));
1164}
1165
1166PHP_FUNCTION(caca_set_dither_antialias) {
1167    zval *_zval;
1168    int str_len;
1169    char *str;
1170    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &_zval, &str, &str_len) == FAILURE) {
1171        RETURN_FALSE;
1172    }
1173    caca_dither_t *dither;
1174    ZEND_FETCH_RESOURCE(dither, caca_dither_t*, &_zval, -1, PHP_CACA_DITHER_RES_NAME, le_caca_dither);
1175    RETURN_SUCCESS(caca_set_dither_antialias(dither, str));
1176}
1177
1178PHP_FUNCTION(caca_get_dither_antialias_list) {
1179    zval *_zval;
1180    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) {
1181        RETURN_FALSE;
1182    }
1183    caca_dither_t *dither;
1184    ZEND_FETCH_RESOURCE(dither, caca_dither_t*, &_zval, -1, PHP_CACA_DITHER_RES_NAME, le_caca_dither);
1185
1186    char const * const *list = caca_get_dither_antialias_list(dither);
1187    int i;
1188    array_init(return_value);
1189    for(i = 0; list[i]; i += 1)
1190        add_next_index_string(return_value, (char*) list[i], 1);
1191}
1192
1193PHP_FUNCTION(caca_get_dither_antialias) {
1194    zval *_zval;
1195    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) {
1196        RETURN_FALSE;
1197    }
1198    caca_dither_t *dither;
1199    ZEND_FETCH_RESOURCE(dither, caca_dither_t*, &_zval, -1, PHP_CACA_DITHER_RES_NAME, le_caca_dither);
1200    RETURN_STRING((char *) caca_get_dither_antialias(dither), 1);
1201}
1202
1203PHP_FUNCTION(caca_set_dither_color) {
1204    zval *_zval;
1205    int str_len;
1206    char *str;
1207    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &_zval, &str, &str_len) == FAILURE) {
1208        RETURN_FALSE;
1209    }
1210    caca_dither_t *dither;
1211    ZEND_FETCH_RESOURCE(dither, caca_dither_t*, &_zval, -1, PHP_CACA_DITHER_RES_NAME, le_caca_dither);
1212    RETURN_SUCCESS(caca_set_dither_color(dither, str));
1213}
1214
1215PHP_FUNCTION(caca_get_dither_color_list) {
1216    zval *_zval;
1217    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) {
1218        RETURN_FALSE;
1219    }
1220    caca_dither_t *dither;
1221    ZEND_FETCH_RESOURCE(dither, caca_dither_t*, &_zval, -1, PHP_CACA_DITHER_RES_NAME, le_caca_dither);
1222
1223    char const * const *list = caca_get_dither_antialias_list(dither);
1224    int i;
1225    array_init(return_value);
1226    for(i = 0; list[i]; i += 2)
1227        add_assoc_string(return_value, (char*) list[i], (char*) list[i + 1], 1);
1228}
1229
1230PHP_FUNCTION(caca_get_dither_color) {
1231    zval *_zval;
1232    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) {
1233        RETURN_FALSE;
1234    }
1235    caca_dither_t *dither;
1236    ZEND_FETCH_RESOURCE(dither, caca_dither_t*, &_zval, -1, PHP_CACA_DITHER_RES_NAME, le_caca_dither);
1237    RETURN_STRING((char *) caca_get_dither_color(dither), 1);
1238}
1239
1240PHP_FUNCTION(caca_set_dither_charset) {
1241    zval *_zval;
1242    int str_len;
1243    char *str;
1244    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &_zval, &str, &str_len) == FAILURE) {
1245        RETURN_FALSE;
1246    }
1247    caca_dither_t *dither;
1248    ZEND_FETCH_RESOURCE(dither, caca_dither_t*, &_zval, -1, PHP_CACA_DITHER_RES_NAME, le_caca_dither);
1249    RETURN_SUCCESS(caca_set_dither_charset(dither, str));
1250}
1251
1252PHP_FUNCTION(caca_get_dither_charset_list) {
1253    zval *_zval;
1254    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) {
1255        RETURN_FALSE;
1256    }
1257    caca_dither_t *dither;
1258    ZEND_FETCH_RESOURCE(dither, caca_dither_t*, &_zval, -1, PHP_CACA_DITHER_RES_NAME, le_caca_dither);
1259
1260    char const * const *list = caca_get_dither_charset_list(dither);
1261    int i;
1262    array_init(return_value);
1263    for(i = 0; list[i]; i += 2)
1264        add_assoc_string(return_value, (char*) list[i], (char*) list[i + 1], 1);
1265}
1266
1267PHP_FUNCTION(caca_get_dither_charset) {
1268    zval *_zval;
1269    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) {
1270        RETURN_FALSE;
1271    }
1272    caca_dither_t *dither;
1273    ZEND_FETCH_RESOURCE(dither, caca_dither_t*, &_zval, -1, PHP_CACA_DITHER_RES_NAME, le_caca_dither);
1274    RETURN_STRING((char *) caca_get_dither_charset(dither), 1);
1275}
1276
1277PHP_FUNCTION(caca_set_dither_algorithm) {
1278    zval *_zval;
1279    int str_len;
1280    char *str;
1281    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &_zval, &str, &str_len) == FAILURE) {
1282        RETURN_FALSE;
1283    }
1284    caca_dither_t *dither;
1285    ZEND_FETCH_RESOURCE(dither, caca_dither_t*, &_zval, -1, PHP_CACA_DITHER_RES_NAME, le_caca_dither);
1286    RETURN_SUCCESS(caca_set_dither_algorithm(dither, str));
1287}
1288
1289PHP_FUNCTION(caca_get_dither_algorithm_list) {
1290    zval *_zval;
1291    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) {
1292        RETURN_FALSE;
1293    }
1294    caca_dither_t *dither;
1295    ZEND_FETCH_RESOURCE(dither, caca_dither_t*, &_zval, -1, PHP_CACA_DITHER_RES_NAME, le_caca_dither);
1296
1297    char const * const *list = caca_get_dither_algorithm_list(dither);
1298    int i;
1299    array_init(return_value);
1300    for(i = 0; list[i]; i += 2)
1301        add_assoc_string(return_value, (char*) list[i], (char*) list[i + 1], 1);
1302}
1303
1304PHP_FUNCTION(caca_get_dither_algorithm) {
1305    zval *_zval;
1306    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) {
1307        RETURN_FALSE;
1308    }
1309    caca_dither_t *dither;
1310    ZEND_FETCH_RESOURCE(dither, caca_dither_t*, &_zval, -1, PHP_CACA_DITHER_RES_NAME, le_caca_dither);
1311    RETURN_STRING((char *) caca_get_dither_algorithm(dither), 1);
1312}
1313
1314PHP_FUNCTION(caca_dither_bitmap) {
1315    zval *_zval1, *_zval2, *_zval3;
1316    long x, y, w, h = 0;
1317    zend_bool load_palette = 1;
1318    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllllrr|b", &_zval1, &x, &y, &w, &h, &_zval2, &_zval3, &load_palette) == FAILURE) {
1319        RETURN_FALSE;
1320    }
1321
1322    caca_canvas_t *canvas;
1323    ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval1, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
1324    caca_dither_t *dither;
1325    ZEND_FETCH_RESOURCE(dither, caca_dither_t*, &_zval2, -1, PHP_CACA_DITHER_RES_NAME, le_caca_dither);
1326
1327#ifdef HAVE_GD
1328    gdImage *img = fetch_external_resource(_zval3, "gd");
1329    if (!img) {
1330        RETURN_FALSE;
1331    }
1332
1333    void *pixels = gd_get_pixels(img);
1334    if (!pixels) {
1335        RETURN_FALSE;
1336    }
1337
1338    //load palette if image is not true color
1339    if (load_palette && !img->trueColor && gd_load_palette(img, dither) != 0) {
1340        free(pixels);
1341        RETURN_FALSE;
1342    }
1343
1344    caca_dither_bitmap(canvas, x, y, w, h, dither, pixels);
1345    free(pixels);
1346    RETURN_TRUE;
1347#else
1348    RETURN_FALSE;
1349#endif
1350}
1351
1352PHP_FUNCTION(caca_load_font) {
1353    char *str;
1354    long str_len;
1355    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) {
1356        RETURN_FALSE;
1357    }
1358    caca_font_t *font = caca_load_font(str, str_len);
1359    if (!font) {
1360        RETURN_FALSE;
1361    }
1362    ZEND_REGISTER_RESOURCE(return_value, font, le_caca_font);
1363}
1364
1365PHP_FUNCTION(caca_load_builtin_font) {
1366    char *str;
1367    long str_len;
1368    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) {
1369        RETURN_FALSE;
1370    }
1371    caca_font_t *font = caca_load_font(str, 0);
1372    if (!font) {
1373        RETURN_FALSE;
1374    }
1375    ZEND_REGISTER_RESOURCE(return_value, font, le_caca_font);
1376}
1377
1378PHP_FUNCTION(caca_get_font_list) {
1379    if (ZEND_NUM_ARGS() != 0) {
1380        WRONG_PARAM_COUNT;
1381    }
1382    char const * const *list = caca_get_font_list();
1383    int i;
1384    array_init(return_value);
1385    for(i = 0; list[i]; i += 1)
1386        add_next_index_string(return_value, (char*) list[i], 1);
1387}
1388
1389PHP_FUNCTION(caca_get_font_width) {
1390    zval *_zval;
1391    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) {
1392        RETURN_FALSE;
1393    }
1394    caca_font_t *font;
1395    ZEND_FETCH_RESOURCE(font, caca_font_t*, &_zval, -1, PHP_CACA_FONT_RES_NAME, le_caca_font);
1396    RETURN_LONG(caca_get_font_width(font));
1397}
1398
1399PHP_FUNCTION(caca_get_font_height) {
1400    zval *_zval;
1401    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) {
1402        RETURN_FALSE;
1403    }
1404    caca_font_t *font;
1405    ZEND_FETCH_RESOURCE(font, caca_font_t*, &_zval, -1, PHP_CACA_FONT_RES_NAME, le_caca_font);
1406    RETURN_LONG(caca_get_font_height(font));
1407}
1408
1409PHP_FUNCTION(caca_get_font_blocks) {
1410    zval *_zval;
1411    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) {
1412        RETURN_FALSE;
1413    }
1414    caca_font_t *font;
1415    ZEND_FETCH_RESOURCE(font, caca_font_t*, &_zval, -1, PHP_CACA_FONT_RES_NAME, le_caca_font);
1416
1417    uint32_t const *list = caca_get_font_blocks(font);
1418
1419    int i;
1420    array_init(return_value);
1421    for(i = 0; list[i]; i += 1)
1422        add_next_index_long(return_value, list[i]);
1423}
1424
1425PHP_FUNCTION(caca_render_canvas) {
1426    zval *_zval1, *_zval2, *_zval3;
1427    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrr", &_zval1, &_zval2, &_zval3) == FAILURE) {
1428        RETURN_FALSE;
1429    }
1430    caca_canvas_t *canvas;
1431    ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval1, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
1432    caca_font_t *font;
1433    ZEND_FETCH_RESOURCE(font, caca_font_t*, &_zval2, -1, PHP_CACA_FONT_RES_NAME, le_caca_font);
1434
1435#ifdef HAVE_GD
1436    gdImage *img = fetch_external_resource(_zval3, "gd");
1437    if (!img || !img->trueColor) {
1438        RETURN_FALSE;
1439    }
1440
1441    int pitch = img->sx * 4;
1442    uint8_t *buffer = malloc(pitch * img->sy);
1443    if (!buffer) {
1444        RETURN_FALSE;
1445    }
1446
1447    caca_render_canvas(canvas, font, (void *) buffer, img->sx, img->sy, pitch);
1448    int i, j;
1449    for (i = 0; i < img->sy; i++) {
1450        for (j = 0; j < img->sx; j++) {
1451            uint8_t *src = buffer + i * pitch + j * 4;
1452            img->tpixels[i][j] = ((int) src[3]) | (((int) src[2]) << 8) | (((int) src[1]) << 16) | (((255 - (int) src[0]) & 0xfe) << 23);
1453        }
1454    }
1455
1456    free(buffer);
1457    RETURN_TRUE;
1458#else
1459    RETURN_FALSE;
1460#endif
1461}
1462
1463PHP_FUNCTION(caca_canvas_set_figfont) {
1464    zval *_zval;
1465    char *font;
1466    long font_len;
1467    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &_zval, &font, &font_len) == FAILURE) {
1468        RETURN_FALSE;
1469    }
1470    caca_canvas_t *canvas;
1471    ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
1472    RETURN_SUCCESS(caca_canvas_set_figfont(canvas, font));
1473}
1474
1475PHP_FUNCTION(caca_put_figchar) {
1476    zval *_zval;
1477    long c;
1478    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &_zval, &c) == FAILURE) {
1479        RETURN_FALSE;
1480    }
1481    caca_canvas_t *canvas;
1482    ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
1483
1484    RETURN_SUCCESS(caca_put_figchar(canvas, c));
1485}
1486
1487PHP_FUNCTION(caca_flush_figlet) {
1488    zval *_zval;
1489    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) {
1490        RETURN_FALSE;
1491    }
1492    caca_canvas_t *canvas;
1493    ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
1494    RETURN_SUCCESS(caca_flush_figlet(canvas));
1495}
1496
1497PHP_FUNCTION(caca_file_open) {
1498    char *path, *mode;
1499    long path_len, mode_len;
1500    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &path, &path_len, &mode, &mode_len) == FAILURE) {
1501        RETURN_FALSE;
1502    }
1503    caca_file_t *file = caca_file_open(path, mode);
1504    if (!file) {
1505        RETURN_FALSE;
1506    }
1507    ZEND_REGISTER_RESOURCE(return_value, file, le_caca_file);
1508}
1509
1510PHP_FUNCTION(caca_file_close) {
1511    zval *_zval;
1512    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) {
1513        RETURN_FALSE;
1514    }
1515    caca_file_t *file;
1516    ZEND_FETCH_RESOURCE(file, caca_file_t*, &_zval, -1, PHP_CACA_FILE_RES_NAME, le_caca_file);
1517
1518    int res = caca_file_close(file);
1519
1520    //Delete php resource
1521    zend_list_delete(_zval->value.lval);
1522    RETURN_SUCCESS(res);
1523}
1524
1525PHP_FUNCTION(caca_file_tell) {
1526    zval *_zval;
1527    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) {
1528        RETURN_FALSE;
1529    }
1530    caca_file_t *file;
1531    ZEND_FETCH_RESOURCE(file, caca_file_t*, &_zval, -1, PHP_CACA_FILE_RES_NAME, le_caca_file);
1532    RETURN_LONG(caca_file_tell(file));
1533}
1534
1535PHP_FUNCTION(caca_file_read) {
1536    zval *_zval;
1537    long len;
1538    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &_zval, &len) == FAILURE) {
1539        RETURN_FALSE;
1540    }
1541    caca_file_t *file;
1542    ZEND_FETCH_RESOURCE(file, caca_file_t*, &_zval, -1, PHP_CACA_FILE_RES_NAME, le_caca_file);
1543
1544    if (len < 1) {
1545        RETURN_FALSE;
1546    }
1547    char *buffer = emalloc(len);
1548    if (!buffer) {
1549        RETURN_FALSE;
1550    }
1551    caca_file_read(file, buffer, len);
1552
1553    RETURN_STRINGL(buffer, len, 1);
1554}
1555
1556PHP_FUNCTION(caca_file_write) {
1557    zval *_zval;
1558    char *buf;
1559    long buf_len = 0;
1560    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &_zval, &buf, &buf_len) == FAILURE) {
1561        RETURN_FALSE;
1562    }
1563    caca_file_t *file;
1564    ZEND_FETCH_RESOURCE(file, caca_file_t*, &_zval, -1, PHP_CACA_FILE_RES_NAME, le_caca_file);
1565    RETURN_LONG(caca_file_write(file, buf, buf_len));
1566}
1567
1568PHP_FUNCTION(caca_file_gets) {
1569    zval *_zval;
1570    long len = 0;
1571    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &_zval, &len) == FAILURE) {
1572        RETURN_FALSE;
1573    }
1574    caca_file_t *file;
1575    ZEND_FETCH_RESOURCE(file, caca_file_t*, &_zval, -1, PHP_CACA_FILE_RES_NAME, le_caca_file);
1576
1577    if (len < 1) {
1578        RETURN_FALSE;
1579    }
1580    char *buffer = emalloc(len);
1581    if (!buffer) {
1582        RETURN_FALSE;
1583    }
1584    char *result = caca_file_gets(file, buffer, len);
1585    if (!result) {
1586        RETURN_FALSE;
1587    }
1588    RETURN_STRINGL(result, len, 1);
1589}
1590
1591PHP_FUNCTION(caca_file_eof) {
1592    zval *_zval;
1593    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) {
1594        RETURN_FALSE;
1595    }
1596    caca_file_t *file;
1597    ZEND_FETCH_RESOURCE(file, caca_file_t*, &_zval, -1, PHP_CACA_FILE_RES_NAME, le_caca_file);
1598    RETURN_BOOL(caca_file_eof(file) != 0);
1599}
1600
1601PHP_FUNCTION(caca_import_string) {
1602    zval *_zval;
1603    char *src, *format;
1604    long src_len, format_len = 0;
1605    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &_zval, &src, &src_len, &format, &format_len) == FAILURE) {
1606        RETURN_FALSE;
1607    }
1608    caca_canvas_t *canvas;
1609    ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
1610
1611    RETURN_LONG(caca_import_canvas_from_memory(canvas, src, src_len, format));
1612}
1613
1614PHP_FUNCTION(caca_import_file) {
1615    zval *_zval;
1616    char *filename, *format;
1617    long filename_len, format_len = 0;
1618    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &_zval, &filename, &filename_len, &format, &format_len) == FAILURE) {
1619        RETURN_FALSE;
1620    }
1621    caca_canvas_t *canvas;
1622    ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
1623
1624    RETURN_LONG(caca_import_canvas_from_file(canvas, filename, format));
1625}
1626
1627PHP_FUNCTION(caca_get_import_list) {
1628    if (ZEND_NUM_ARGS() != 0) {
1629        WRONG_PARAM_COUNT;
1630    }
1631    char const * const *list = caca_get_import_list();
1632    int i;
1633    array_init(return_value);
1634    for(i = 0; list[i]; i += 2)
1635        add_assoc_string(return_value, (char*) list[i], (char*) list[i + 1], 1);
1636}
1637
1638PHP_FUNCTION(caca_export_string) {
1639    zval *_zval;
1640    char *type;
1641    long type_len;
1642    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &_zval, &type, &type_len) == FAILURE) {
1643        RETURN_FALSE;
1644    }
1645    caca_canvas_t *canvas;
1646    ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
1647
1648    void *buffer;
1649    size_t len = 0;
1650    buffer = caca_export_canvas_to_memory(canvas, type, &len);
1651    if (!buffer) {
1652        RETURN_FALSE;
1653    }
1654
1655    RETVAL_STRINGL((char*) buffer, len, 1);
1656    free(buffer);
1657}
1658
1659PHP_FUNCTION(caca_get_export_list) {
1660    if (ZEND_NUM_ARGS() != 0) {
1661        WRONG_PARAM_COUNT;
1662    }
1663    char const * const *list = caca_get_export_list();
1664    int i;
1665    array_init(return_value);
1666    for(i = 0; list[i]; i += 2)
1667        add_assoc_string(return_value, (char*) list[i], (char*) list[i + 1], 1);
1668}
1669
1670PHP_FUNCTION(caca_create_display) {
1671    caca_canvas_t *canvas;
1672    FETCH_CANVAS(canvas);
1673
1674    caca_display_t *display = caca_create_display(canvas);
1675    if (!display) {
1676        RETURN_FALSE;
1677    }
1678    ZEND_REGISTER_RESOURCE(return_value, display, le_caca_display);
1679}
1680
1681PHP_FUNCTION(caca_create_display_with_driver) {
1682    zval *_zval;
1683    char *str;
1684    long str_len = 0;
1685    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &_zval, &str, &str_len) == FAILURE) {
1686        RETURN_FALSE;
1687    }
1688    caca_canvas_t *canvas;
1689    ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
1690
1691    caca_display_t *display = caca_create_display_with_driver(canvas, str);
1692    if (!display) {
1693        RETURN_FALSE;
1694    }
1695    ZEND_REGISTER_RESOURCE(return_value, display, le_caca_display);
1696}
1697
1698PHP_FUNCTION(caca_get_display_driver_list) {
1699    if (ZEND_NUM_ARGS() != 0) {
1700        WRONG_PARAM_COUNT;
1701    }
1702    char const * const *list = caca_get_display_driver_list();
1703    int i;
1704    array_init(return_value);
1705    for(i = 0; list[i]; i += 2)
1706        add_assoc_string(return_value, (char*) list[i], (char*) list[i + 1], 1);
1707}
1708
1709PHP_FUNCTION(caca_get_display_driver) {
1710    zval *_zval;
1711    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) {
1712        RETURN_FALSE;
1713    }
1714    caca_display_t *display;
1715    ZEND_FETCH_RESOURCE(display, caca_display_t*, &_zval, -1, PHP_CACA_DISPLAY_RES_NAME, le_caca_display);
1716    RETURN_STRING((char *) caca_get_display_driver(display), 1);
1717}
1718
1719PHP_FUNCTION(caca_set_display_driver) {
1720    zval *_zval;
1721    char *str;
1722    long str_len;
1723    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &_zval, &str, &str_len) == FAILURE) {
1724        RETURN_FALSE;
1725    }
1726    caca_display_t *display;
1727    ZEND_FETCH_RESOURCE(display, caca_display_t*, &_zval, -1, PHP_CACA_DISPLAY_RES_NAME, le_caca_display);
1728    RETURN_SUCESS(caca_set_display_driver(display, str));
1729}
1730
1731PHP_FUNCTION(caca_get_canvas) {
1732    zval *_zval;
1733    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) {
1734        RETURN_FALSE;
1735    }
1736    caca_display_t *display;
1737    ZEND_FETCH_RESOURCE(display, caca_display_t*, &_zval, -1, PHP_CACA_DISPLAY_RES_NAME, le_caca_display);
1738    caca_canvas_t *canvas = caca_get_canvas(display);
1739    if (!canvas) {
1740        RETURN_FALSE;
1741    }
1742    ZEND_REGISTER_RESOURCE(return_value, canvas, le_caca_canvas);
1743}
1744
1745PHP_FUNCTION(caca_refresh_display) {
1746    caca_display_t *display;
1747    FETCH_DISPLAY(display);
1748    RETURN_SUCCESS(caca_refresh_display(display));
1749}
1750
1751PHP_FUNCTION(caca_set_display_time) {
1752    zval *_zval;
1753    long value = 0;
1754    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &_zval, &value) == FAILURE) {
1755        RETURN_FALSE;
1756    }
1757    caca_display_t *display;
1758    ZEND_FETCH_RESOURCE(display, caca_display_t*, &_zval, -1, PHP_CACA_DISPLAY_RES_NAME, le_caca_display);
1759    RETURN_SUCCESS(caca_set_display_time(display, value));
1760}
1761
1762PHP_FUNCTION(caca_get_display_time) {
1763    caca_display_t *display;
1764    FETCH_DISPLAY(display);
1765    RETURN_LONG(caca_get_display_time(display));
1766}
1767
1768PHP_FUNCTION(caca_get_display_width) {
1769    caca_display_t *display;
1770    FETCH_DISPLAY(display);
1771    RETURN_LONG(caca_get_display_width(display));
1772}
1773
1774PHP_FUNCTION(caca_get_display_height) {
1775    caca_display_t *display;
1776    FETCH_DISPLAY(display);
1777    RETURN_LONG(caca_get_display_height(display));
1778}
1779
1780PHP_FUNCTION(caca_set_display_title) {
1781    zval *_zval;
1782    char *str;
1783    long str_len = 0;
1784    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &_zval, &str, &str_len) == FAILURE) {
1785        RETURN_FALSE;
1786    }
1787    caca_display_t *display;
1788    ZEND_FETCH_RESOURCE(display, caca_display_t*, &_zval, -1, PHP_CACA_DISPLAY_RES_NAME, le_caca_display);
1789    RETURN_SUCCESS(caca_set_display_title(display, str));
1790}
1791
1792PHP_FUNCTION(caca_set_mouse) {
1793    zval *_zval;
1794    long value = 0;
1795    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &_zval, &value) == FAILURE) {
1796        RETURN_FALSE;
1797    }
1798    caca_display_t *display;
1799    ZEND_FETCH_RESOURCE(display, caca_display_t*, &_zval, -1, PHP_CACA_DISPLAY_RES_NAME, le_caca_display);
1800    RETURN_SUCCESS(caca_set_mouse(display, value));
1801}
1802
1803PHP_FUNCTION(caca_set_cursor) {
1804    zval *_zval;
1805    long value = 0;
1806    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &_zval, &value) == FAILURE) {
1807        RETURN_FALSE;
1808    }
1809    caca_display_t *display;
1810    ZEND_FETCH_RESOURCE(display, caca_display_t*, &_zval, -1, PHP_CACA_DISPLAY_RES_NAME, le_caca_display);
1811    RETURN_SUCCESS(caca_set_cursor(display, value));
1812}
1813
1814PHP_FUNCTION(caca_get_event) {
1815    zval *_zval = NULL;
1816    long g, aa = 0;
1817    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|l", &_zval, &g, &aa) == FAILURE) {
1818        RETURN_FALSE;
1819    }
1820    caca_display_t *display;
1821    ZEND_FETCH_RESOURCE(display, caca_display_t*, &_zval, -1, PHP_CACA_DISPLAY_RES_NAME, le_caca_display);
1822
1823    caca_event_t *event = emalloc(sizeof(caca_event_t));
1824    if (!event) {
1825        RETURN_FALSE;
1826    }
1827
1828    caca_get_event(display, g, event, aa);
1829
1830    if (caca_get_event_type(event) == CACA_EVENT_NONE) {
1831        efree(event);
1832        RETURN_FALSE;
1833    }
1834    ZEND_REGISTER_RESOURCE(return_value, event, le_caca_event);
1835}
1836
1837PHP_FUNCTION(caca_get_mouse_x) {
1838    caca_display_t *display;
1839    FETCH_DISPLAY(display);
1840    RETURN_LONG(caca_get_mouse_x(display));
1841}
1842
1843PHP_FUNCTION(caca_get_mouse_y) {
1844    caca_display_t *display;
1845    FETCH_DISPLAY(display);
1846    RETURN_LONG(caca_get_mouse_y(display));
1847}
1848
1849PHP_FUNCTION(caca_get_event_type) {
1850    caca_event_t *event;
1851    FETCH_EVENT(event);
1852    RETURN_LONG(caca_get_event_type(event));
1853}
1854
1855PHP_FUNCTION(caca_get_event_key_ch) {
1856    caca_event_t *event;
1857    FETCH_EVENT(event);
1858    RETURN_LONG(caca_get_event_key_ch(event));
1859}
1860
1861PHP_FUNCTION(caca_get_event_mouse_button) {
1862    caca_event_t *event;
1863    FETCH_EVENT(event);
1864    RETURN_LONG(caca_get_event_mouse_button(event));
1865}
1866
1867PHP_FUNCTION(caca_get_event_mouse_x) {
1868    caca_event_t *event;
1869    FETCH_EVENT(event);
1870    RETURN_LONG(caca_get_event_mouse_x(event));
1871}
1872
1873PHP_FUNCTION(caca_get_event_mouse_y) {
1874    caca_event_t *event;
1875    FETCH_EVENT(event);
1876    RETURN_LONG(caca_get_event_mouse_y(event));
1877}
1878
1879PHP_FUNCTION(caca_get_event_resize_width) {
1880    caca_event_t *event;
1881    FETCH_EVENT(event);
1882    RETURN_LONG(caca_get_event_resize_width(event));
1883}
1884
1885PHP_FUNCTION(caca_get_event_resize_height) {
1886    caca_event_t *event;
1887    FETCH_EVENT(event);
1888    RETURN_LONG(caca_get_event_resize_height(event));
1889}
1890
Note: See TracBrowser for help on using the repository browser.