Skip to content

Commit 969da88

Browse files
committed
CV\createTrackbar callback
1 parent 4f46a4f commit 969da88

File tree

1 file changed

+26
-24
lines changed

1 file changed

+26
-24
lines changed

source/opencv2/opencv_highgui.cc

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -102,29 +102,45 @@ PHP_FUNCTION(opencv_named_window){
102102
RETURN_NULL();
103103
}
104104

105-
struct opencv_fcall_info_struct{
105+
struct opencv_fcall_info_cb{
106106
zend_fcall_info *fci;
107107
zend_fcall_info_cache *fci_cache;
108108
};
109109

110+
111+
opencv_fcall_info_cb * opencv_fcall_info_cb_create(zend_fcall_info *fci_ptr, zend_fcall_info_cache *fci_cache_ptr) {
112+
opencv_fcall_info_cb *cb = new opencv_fcall_info_cb;
113+
cb->fci = new zend_fcall_info;
114+
cb->fci_cache = new zend_fcall_info_cache;
115+
116+
memcpy(cb->fci, fci_ptr, sizeof(zend_fcall_info));
117+
memcpy(cb->fci_cache, fci_cache_ptr, sizeof(zend_fcall_info_cache));
118+
Z_TRY_ADDREF(cb->fci->function_name);
119+
cb->fci->param_count = 0;
120+
cb->fci->no_separation = 1;
121+
cb->fci->retval = NULL;
122+
123+
return cb;
124+
}
125+
110126
void opencv_create_trackbar_callback(int pos, void* userdata){
111-
opencv_fcall_info_struct *fci_s=(opencv_fcall_info_struct*)userdata;
127+
opencv_fcall_info_cb *fci_s=(opencv_fcall_info_cb*)userdata;
112128

113129
zval retval;
114130
zval args[1];
115-
ZVAL_LONG(&args[0], (long)pos);
131+
ZVAL_LONG(&args[0], (long)pos);//将滑动条滑动的值传入到闭包参数中
116132
fci_s->fci->param_count = 1;
117133
fci_s->fci->params = args;
118134
fci_s->fci->retval = &retval;
119135

120-
//todo zend_call_function: Assertion `((zend_object*)func->op_array.prototype)->gc.u.v.type == 8' failed.
121136
zend_call_function(fci_s->fci, fci_s->fci_cache);
122137
zval_ptr_dtor(&args[0]);
123138
}
124139

125140

141+
126142
/**
127-
* //todo c++ createTrackbar 跳转事件调用php传入的闭包:1php全局变量,2c++闭包
143+
* todo Total 1 memory leaks detected
128144
* CV\createTrackbar
129145
* @param execute_data
130146
* @param return_value
@@ -134,35 +150,21 @@ PHP_FUNCTION(opencv_create_trackbar){
134150
long value, count, trackbarname_len,winname_len;
135151
zval retval;
136152

137-
zend_fcall_info *fci = new zend_fcall_info;
138-
zend_fcall_info_cache *fci_cache = new zend_fcall_info_cache;
153+
zend_fcall_info fci;
154+
zend_fcall_info_cache fci_cache;
139155
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ssll|f",
140156
&trackbarname, &trackbarname_len,
141157
&winname,&winname_len,
142158
&value,&count,
143-
fci, fci_cache) == FAILURE) {
159+
&fci, &fci_cache) == FAILURE) {
144160
return;
145161
}
146162

147163
int *trackbar_value_ptr = new int(value);
148164

149-
opencv_fcall_info_struct *fci_s = new opencv_fcall_info_struct;
150-
fci_s->fci=fci;
151-
fci_s->fci_cache = fci_cache;
152-
createTrackbar(trackbarname, winname, trackbar_value_ptr, (int)count,opencv_create_trackbar_callback,fci_s);
153-
opencv_create_trackbar_callback(*trackbar_value_ptr,fci_s);
154-
// createTrackbar(trackbarname, winname, trackbar_value_ptr, (int)count);
155-
// zend_call_function(fci_s->fci, fci_s->fci_cache);
165+
opencv_fcall_info_cb *cb = opencv_fcall_info_cb_create(&fci, &fci_cache);
166+
createTrackbar(trackbarname, winname, trackbar_value_ptr, (int)count,opencv_create_trackbar_callback,cb);
156167
RETURN_NULL();
157-
158-
// if (zend_call_function(fci, fci_cache) == SUCCESS && Z_TYPE(retval) != IS_UNDEF) {
159-
// zval_ptr_dtor(&args[0]);
160-
// RETURN_ZVAL(&retval,1,1);
161-
// ZVAL_COPY_VALUE(return_value, &retval);
162-
// } else {
163-
// RETURN_FALSE;
164-
// }
165-
166168
}
167169

168170
PHP_FUNCTION(opencv_destroy_window){

0 commit comments

Comments
 (0)