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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
#include "php.h"
#include "php_imlib.h"
/* aliases for the exported symbols */
#define php_filter_init php_bumpmap_LTX_php_filter_init
#define php_filter_deinit php_bumpmap_LTX_php_filter_deinit
#define php_filter_exec php_bumpmap_LTX_php_filter_exec
#define php_filter_getfiltercount php_bumpmap_LTX_php_filter_getfiltercount
#define php_filter_getfilternames php_bumpmap_LTX_php_filter_getfilternames
#define php_filter_getextinfo php_bumpmap_LTX_php_filter_getextinfo
#define php_filter_getparams php_bumpmap_LTX_php_filter_getparams
static char* _php_bumpmap_stradd(char* str1,char* str2)
{
char* retval;
if ((str1)&&(str2))
{
retval=emalloc((strlen(str1)+strlen(str2)+1)*sizeof(char));
if (retval)
{
strcpy(retval,str1);
strcat(retval,str2);
efree(str1);
return retval;
}
}
return str1;
}
static int
_php_bumpmap_exec(char* filter, HashTable* params,int index)
{
char *allpnames[][10]={
{"map","angle","elevation","depth","red","green","blue","ambient",0},
{"map","x","y","z","depth","red","green","blue","ambient",0}
};
int allptypes[][10]={
{'I','i','i','i','i','i','i','i'},
{'I','i','i','i','i','i','i','i','i'}
};
char **paramnames;
int *paramtypes;
char *script;
Imlib_Image im=NULL;
ulong num_index;
zend_string *str_index;
zval *data;
paramnames=allpnames[index];
paramtypes=allptypes[index];
script=estrdup(filter);
script=_php_bumpmap_stradd(script,"(");
ZEND_HASH_FOREACH_KEY_VAL(params, num_index, str_index, data)
{
if (str_index)
{
int match=0;
int index=0;
while (paramnames[index])
{
if (strcmp(str_index->val,paramnames[index])==0)
{
char val[32];
switch(paramtypes[index])
{
case 'I':
im=_php_imlib_get_image(data);
script=_php_bumpmap_stradd(script,"map=[]");
break;
case 'i':
convert_to_long_ex(data);
sprintf(val,"%d",(int)Z_LVAL_P(data));
script=_php_bumpmap_stradd(script,str_index->val);
script=_php_bumpmap_stradd(script,"=");
script=_php_bumpmap_stradd(script,val);
break;
}
script=_php_bumpmap_stradd(script,",");
match=1;
break;
}
index++;
}
if (!match)
{
php_error(E_NOTICE,"Unknown argument %s ignored",str_index);
}
}
} ZEND_HASH_FOREACH_END();
if (script[strlen(script)-1]==',') script[strlen(script)-1]='\0';
script=_php_bumpmap_stradd(script,");");
if (!script) return FAILURE;
/*zend_printf("Script: %s, map: %p<br>",script,im);*/
imlib_apply_filter(script,im);
efree(script);
return SUCCESS;
}
int
php_filter_init()
{
return SUCCESS;
}
void
php_filter_deinit()
{
return;
}
int
_php_bumpmap_getfilterindex(char*);
int
php_filter_exec(Imlib_Image im, char *filter, HashTable *params)
{
int index=_php_bumpmap_getfilterindex(filter);
if (index!=-1)
{
int rv;
imlib_context_set_image(im);
rv=_php_bumpmap_exec(filter,params,index);
return rv;
}
return FAILURE;
}
int
php_filter_getfiltercount()
{
return 2;
}
void
php_filter_getfilternames(char** filternames)
{
filternames[0]="bump_map";
filternames[1]="bump_map_point";
}
int
_php_bumpmap_getfilterindex(char* filtername)
{
char** filternames;
int i;
filternames=(char**)emalloc(php_filter_getfiltercount()*sizeof(char*));
php_filter_getfilternames(filternames);
for (i=0;i<php_filter_getfiltercount();i++)
{
if (strcmp(filtername,filternames[i])==0) return i;
}
return -1;
}
void
php_filter_getextinfo(char** info)
{
info[0]="Bump Mapping";
info[1]="Provides PHP interface to Willem Monsuwe's bump mapping filter.";
info[2]="Piotr Pawlow (pp@siedziba.pl)";
}
char*
php_filter_getparams(char* filter)
{
char* filterparams[]={
NULL,
"Image map, int angle=0, int elevation=30, int depth=0x200, int red=0x200, int green=0x200, int blue=0x200, int ambient=0",
"Image map, int x=0, int y=0, int z=30, int depth=0x200, int red=0x200, int green=0x200, int blue=0x200, int ambient=0"
};
return filterparams[_php_bumpmap_getfilterindex(filter)+1];
}
|