-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathphp_sdl_image.c
110 lines (88 loc) · 2.35 KB
/
php_sdl_image.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/* sdl_image extension for PHP */
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "php_sdl_image.h"
#define SDL_RENDERER_RES_NAME "SDL Renderer"
extern int le_sdl_renderer;
extern int le_sdl_texture;
extern zend_bool sdl_surface_to_zval(SDL_Surface *surface, zval *z_val);
/* {{{ proto SDL_Texture IMG_LoadTexture(string file)
PHP note: stream are supported
* Load a texture from a file.
extern DECLSPEC SDL_Texture * SDLCALL IMG_LoadTexture(SDL_Renderer *renderer, const char *file);
*/
PHP_FUNCTION(IMG_LoadTexture)
{
zend_string *file;
SDL_Texture *texture = NULL;
zval *z_renderer = NULL;
SDL_Renderer *renderer = NULL;
ZEND_PARSE_PARAMETERS_START(2, 2)
Z_PARAM_ZVAL(z_renderer)
Z_PARAM_STR(file)
ZEND_PARSE_PARAMETERS_END();
renderer = (SDL_Renderer*)zend_fetch_resource(Z_RES_P(z_renderer), SDL_RENDERER_RES_NAME, le_sdl_renderer);
texture = IMG_LoadTexture(renderer, ZSTR_VAL(file));
if (!texture) {
RETURN_NULL();
}
RETURN_RES(zend_register_resource(texture, le_sdl_texture));
}
/* }}} */
PHP_FUNCTION(IMG_Load)
{
zend_string *file;
SDL_Surface *surface = NULL;
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_STR(file)
ZEND_PARSE_PARAMETERS_END();
surface = IMG_Load(ZSTR_VAL(file));
if (!surface) {
RETURN_NULL();
}
sdl_surface_to_zval(surface, return_value);
}
/* {{{ PHP_MINIT_FUNCTION
*/
PHP_MINIT_FUNCTION(sdl_image)
{
#if defined(ZTS) && defined(COMPILE_DL_SDL_IMAGE)
ZEND_TSRMLS_CACHE_UPDATE();
#endif
return SUCCESS;
}
/* }}} */
/* {{{ PHP_MINFO_FUNCTION
*/
PHP_MINFO_FUNCTION(sdl_image)
{
php_info_print_table_start();
php_info_print_table_header(2, "sdl_image support", "enabled");
php_info_print_table_end();
}
/* }}} */
static const zend_module_dep ext_deps[] = {
ZEND_MOD_REQUIRED("sdl")
ZEND_MOD_END
};
zend_module_entry sdl_image_module_entry = {
STANDARD_MODULE_HEADER_EX,
NULL,
ext_deps,
"SDL_image",
ext_functions, /* zend_function_entry */
PHP_MINIT(sdl_image), /* PHP_MINIT - Module initialization */
NULL, /* PHP_MSHUTDOWN - Module shutdown */
NULL, /* PHP_RINIT - Request initialization */
NULL, /* PHP_RSHUTDOWN - Request shutdown */
PHP_MINFO(sdl_image), /* PHP_MINFO - Module info */
PHP_SDL_IMAGE_VERSION, /* Version */
STANDARD_MODULE_PROPERTIES
};
#ifdef COMPILE_DL_SDL_IMAGE
# ifdef ZTS
ZEND_TSRMLS_CACHE_DEFINE()
# endif
ZEND_GET_MODULE(sdl_image)
#endif