On Tue, 12 Nov 2002, Pierre-Alain Joye wrote: > 1. php syntax > After a short discussion on #php, I choose to implement a generic > function: > bool imagefilter(resssource img, int filtertype [,arg1,argn,...]); > where > int filtertype are predefined constant (IMAGE_FILTER_BRIGHTNESS, > IMAGE_FILTER_EDGEDETECT,...) > > and argN depends on the used filter. > > Is this syntax sounds good to you ?
It does to me. > > > 2. The implementation > It was clear that a generic imagefilter function is easier to use than N > different functions (inside php). So here I went. But I did not find a > cool way to do it. One goal of that is to make as easy as possible to > add filters (in ext/gd/gd.c). > > Currently I do: > > 3701 if (ZEND_NUM_ARGS()<2 || ZEND_NUM_ARGS()>5 || > 3702 zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args) == > FAILURE) 3703 ZEND_WRONG_PARAM_COUNT(); > 3704 > 3705 FILTERTYPE = args[1]; > 3706 > 3707 convert_to_long_ex(FILTERTYPE); > 3708 filtertype = Z_LVAL_PP(FILTERTYPE); > > .... > 3716 switch (filtertype) { > 3717 case IMAGE_FILTER_NEGATE: > 3718 if (ZEND_NUM_ARGS()>2) { > 3719 ZEND_WRONG_PARAM_COUNT(); > 3720 } > 3721 if (gdImageNegate(im_src)==1) { > 3722 RETURN_TRUE; > 3723 } > 3724 break; > .... > > I do not like the switch, I prefer to see something like an array of > the available filters, an array of function pointers to which we pass > the php arguments(INTERNAL_FUNCTION_PARAM_PASSTHRU). It will be easier > to add new filters. > > I try to do it but I ve failed. the problem is I need to call a function > passing to it all php args and allowing it to return > errors/warnings/notices to the user. This function does not have to be > available from php. > > I hope I was clear enough :-) > > any comments, ideas ? You can do something like this: #define FILTER_NONE 0 #define FILTER_NEGATE 1 #define FILTER_BLUR 2 #define FILTER_MAX 2 typedef image_filter { void (function*)(INTERNAL_FUNCTION_PARAMETERS); } image_filter; image_filter filters[] = { { image_filter_none }, { image_filter_negate }, { image_filter_blur } }; PHP_FUNCTION(image_filter_none) { /* do stuff */ } and then have: filters[filter_type]->function(INTERNAL_FUNCTION_PARAMETERS); which can return errors and stuff just like a normal functon can do. regards, Derick PS.: This is from mind, might not work :-) Derick > -- --------------------------------------------------------------------------- Derick Rethans http://derickrethans.nl/ JDI Media Solutions --------------[ if you hold a unix shell to your ear, do you hear the c? ]- -- PHP Development Mailing List <http://www.php.net/> To unsubscribe, visit: http://www.php.net/unsub.php