From 87380c76cb1eb3644da7291d842281caaae63f2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Paw=C5=82ow?= Date: Thu, 8 Sep 2016 23:05:41 +0200 Subject: Quick and dirty PHP7 port. Using compatibility shims and macros. Compiles both on PHP5 and 7. Done in one afternoon without much testing, so use at your own risk! --- filters/php_bumpmap.c | 30 +++++++++----------- filters/php_colormatrix.c | 72 ++++++++++++++++++----------------------------- filters/php_colormod.c | 25 ++++++---------- filters/php_hsbcolor.c | 42 +++++++++++---------------- filters/php_testfilter.c | 35 +++++++++-------------- 5 files changed, 81 insertions(+), 123 deletions(-) (limited to 'filters') diff --git a/filters/php_bumpmap.c b/filters/php_bumpmap.c index 6910f82..24e548d 100644 --- a/filters/php_bumpmap.c +++ b/filters/php_bumpmap.c @@ -44,7 +44,9 @@ _php_bumpmap_exec(char* filter, HashTable* params,int index) int *paramtypes; char *script; Imlib_Image im=NULL; - HashPosition pos; + ulong num_index; + zend_string *str_index; + imlib_zval *data; paramnames=allpnames[index]; paramtypes=allptypes[index]; @@ -52,36 +54,28 @@ _php_bumpmap_exec(char* filter, HashTable* params,int index) script=estrdup(filter); script=_php_bumpmap_stradd(script,"("); - zend_hash_internal_pointer_reset_ex(params,&pos); - while (pos) - { - char *str_index; - ulong num_index; - int retval; - - retval=zend_hash_get_current_key_ex(params,&str_index,NULL,&num_index,0,&pos); - if (retval==HASH_KEY_IS_STRING) + 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,paramnames[index])==0) + if (strcmp(STR_VAL(str_index),paramnames[index])==0) { char val[32]; - zval **data; - zend_hash_get_current_data_ex(params,(void**)&data,&pos); switch(paramtypes[index]) { case 'I': - im=(Imlib_Image)_php_imlib_get_image(data); /* Why is cast to Imlib_Image needed? */ + im=(Imlib_Image)_php_imlib_get_image(Z_RES_P(data)); /* Why is cast to Imlib_Image needed? */ script=_php_bumpmap_stradd(script,"map=[]"); break; case 'i': convert_to_long_ex(data); sprintf(val,"%d",(int)Z_LVAL_PP(data)); - script=_php_bumpmap_stradd(script,str_index); + script=_php_bumpmap_stradd(script,STR_VAL(str_index)); script=_php_bumpmap_stradd(script,"="); script=_php_bumpmap_stradd(script,val); break; @@ -97,8 +91,7 @@ _php_bumpmap_exec(char* filter, HashTable* params,int index) php_error(E_NOTICE,"Unknown argument %s ignored",str_index); } } - zend_hash_move_forward_ex(params,&pos); - } + } ZEND_HASH_FOREACH_END(); if (script[strlen(script)-1]==',') script[strlen(script)-1]='\0'; script=_php_bumpmap_stradd(script,");"); @@ -121,6 +114,9 @@ php_filter_deinit() return; } +int +_php_bumpmap_getfilterindex(char*); + int php_filter_exec(Imlib_Image im, char *filter, HashTable *params) { diff --git a/filters/php_colormatrix.c b/filters/php_colormatrix.c index 1cd28b2..f5dab0e 100644 --- a/filters/php_colormatrix.c +++ b/filters/php_colormatrix.c @@ -264,42 +264,36 @@ static void _php_colormatrix_saturatemat(double mat[16], double sat) mat[15] = 1.0; } -static void _php_colormatrix_usermat(double mat[16], zval** data) +static void _php_colormatrix_usermat(double mat[16], imlib_zval* data) { HashTable* mat_ht; - HashPosition pos; - - convert_to_array_ex(data); - + ulong num_index; + zend_string *str_index; + imlib_zval *value; + + convert_to_array_ex(data); +#if PHP_VERSION_ID >= 70000 + mat_ht = HASH_OF(data); +#else mat_ht=(*data)->value.ht; // FIXME: should really use HASH_OF macro. // Filter API change needed to supply TSRMLS to filters - zend_hash_internal_pointer_reset_ex(mat_ht,&pos); - while (pos) +#endif + ZEND_HASH_FOREACH_KEY_VAL(mat_ht, num_index, str_index, value) { - char *str_index; - ulong num_index; - int retval; - zval **value; - - retval=zend_hash_get_current_key_ex(mat_ht,&str_index,NULL,&num_index,0,&pos); - if (retval==HASH_KEY_IS_LONG) + if ((num_index>=0)&&(num_index<16)) { - if ((num_index>=0)&&(num_index<16)) - { - zend_hash_get_current_data_ex(mat_ht,(void**)&value,&pos); - convert_to_double_ex(value); - mat[num_index]=Z_DVAL_PP(value); - } + convert_to_double_ex(value); + mat[num_index]=Z_DVAL_PP(value); } - - zend_hash_move_forward_ex(mat_ht,&pos); - } + } ZEND_HASH_FOREACH_END(); } static int _php_colormatrix_exec(Imlib_Image im, char* filter, HashTable* params) { - HashPosition pos; + ulong num_index; + zend_string *str_index; + imlib_zval *data; double mat[16]; int x=0,y=0,w,h,imgw,imgh; @@ -310,38 +304,28 @@ _php_colormatrix_exec(Imlib_Image im, char* filter, HashTable* params) w = imgw = imlib_image_get_width(); h = imgh = imlib_image_get_height(); - zend_hash_internal_pointer_reset_ex(params,&pos); - while (pos) + ZEND_HASH_FOREACH_KEY_VAL(params, num_index, str_index, data) { - char *str_index; - ulong num_index; - int retval; - - retval=zend_hash_get_current_key_ex(params,&str_index,NULL,&num_index,0,&pos); - if (retval==HASH_KEY_IS_STRING) + if (str_index) { - zval **data; - zend_hash_get_current_data_ex(params,(void**)&data,&pos); - - if (!strcmp(str_index,"x")) { convert_to_long_ex(data); x=Z_LVAL_PP(data); }; - if (!strcmp(str_index,"y")) { convert_to_long_ex(data); y=Z_LVAL_PP(data); }; - if (!strcmp(str_index,"w")) { convert_to_long_ex(data); w=Z_LVAL_PP(data); }; - if (!strcmp(str_index,"h")) { convert_to_long_ex(data); h=Z_LVAL_PP(data); }; + if (!strcmp(STR_VAL(str_index),"x")) { convert_to_long_ex(data); x=Z_LVAL_PP(data); }; + if (!strcmp(STR_VAL(str_index),"y")) { convert_to_long_ex(data); y=Z_LVAL_PP(data); }; + if (!strcmp(STR_VAL(str_index),"w")) { convert_to_long_ex(data); w=Z_LVAL_PP(data); }; + if (!strcmp(STR_VAL(str_index),"h")) { convert_to_long_ex(data); h=Z_LVAL_PP(data); }; if (!strcmp(filter,"cm_user")) { - if (!strcmp(str_index,"matrix")) _php_colormatrix_usermat(mat,data); + if (!strcmp(STR_VAL(str_index),"matrix")) _php_colormatrix_usermat(mat,data); } if (!strcmp(filter,"cm_saturation")) { - if (!strcmp(str_index,"sat")) { convert_to_double_ex(data); _php_colormatrix_saturatemat(mat,Z_DVAL_PP(data)); }; + if (!strcmp(STR_VAL(str_index),"sat")) { convert_to_double_ex(data); _php_colormatrix_saturatemat(mat,Z_DVAL_PP(data)); }; } if (!strcmp(filter,"cm_huerot")) { - if (!strcmp(str_index,"angle")) { convert_to_double_ex(data); _php_colormatrix_huerotatemat(mat,Z_DVAL_PP(data)); }; + if (!strcmp(STR_VAL(str_index),"angle")) { convert_to_double_ex(data); _php_colormatrix_huerotatemat(mat,Z_DVAL_PP(data)); }; } } - zend_hash_move_forward_ex(params,&pos); - } + } ZEND_HASH_FOREACH_END(); if (x<0) x=0; if (y<0) y=0; diff --git a/filters/php_colormod.c b/filters/php_colormod.c index c240f1f..a93ae84 100644 --- a/filters/php_colormod.c +++ b/filters/php_colormod.c @@ -32,43 +32,37 @@ _php_colormod_exec(HashTable* params) char *paramnames[]={"x","y","w","h","brightness","contrast","gamma","brightness_r","contrast_r","gamma_r","brightness_g","contrast_g","gamma_g","brightness_b","contrast_b","gamma_b","brightness_a","contrast_a","gamma_a","tint","tint_r","tint_g","tint_b","tint_a",0}; int paramtypes[]= {'i','i','i','i','d', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd' }; char *script; + ulong num_index; + zend_string *str_index; + imlib_zval *data; - HashPosition pos; script=estrdup("colormod("); - zend_hash_internal_pointer_reset_ex(params,&pos); - while (pos) + ZEND_HASH_FOREACH_KEY_VAL(params, num_index, str_index, data) { - char *str_index; - ulong num_index; - int retval; - - retval=zend_hash_get_current_key_ex(params,&str_index,NULL,&num_index,0,&pos); - if (retval==HASH_KEY_IS_STRING) + if (str_index) { int match=0; int index=0; while (paramnames[index]) { - if (strcmp(str_index,paramnames[index])==0) + if (strcmp(STR_VAL(str_index),paramnames[index])==0) { char val[32]; - zval **data; - zend_hash_get_current_data_ex(params,(void**)&data,&pos); switch(paramtypes[index]) { case 'i': convert_to_long_ex(data); sprintf(val,"%d",(int)Z_LVAL_PP(data)); - script=_php_colormod_stradd(script,str_index); + script=_php_colormod_stradd(script,STR_VAL(str_index)); script=_php_colormod_stradd(script,"="); script=_php_colormod_stradd(script,val); break; case 'd': convert_to_double_ex(data); sprintf(val,"%f",(double)Z_DVAL_PP(data)); - script=_php_colormod_stradd(script,str_index); + script=_php_colormod_stradd(script,STR_VAL(str_index)); script=_php_colormod_stradd(script,"="); script=_php_colormod_stradd(script,val); break; @@ -84,8 +78,7 @@ _php_colormod_exec(HashTable* params) php_error(E_NOTICE,"Unknown argument %s ignored",str_index); } } - zend_hash_move_forward_ex(params,&pos); - } + } ZEND_HASH_FOREACH_END(); if (script[strlen(script)-1]==',') script[strlen(script)-1]='\0'; script=_php_colormod_stradd(script,");"); diff --git a/filters/php_hsbcolor.c b/filters/php_hsbcolor.c index 577afc2..288c7c1 100644 --- a/filters/php_hsbcolor.c +++ b/filters/php_hsbcolor.c @@ -101,7 +101,9 @@ static void _php_hsbcolor_hsb2rgb(double hue, double saturation, double brightne static int _php_hsbcolor_exec(Imlib_Image im, HashTable* params) { - HashPosition pos; + ulong num_index; + zend_string *str_index; + imlib_zval *data; double h_add = 0, s_add = 0, b_add = 0; double h_mul = 1.0, s_mul = 1.0, b_mul = 1.0; @@ -111,33 +113,23 @@ _php_hsbcolor_exec(Imlib_Image im, HashTable* params) w = imgw = imlib_image_get_width(); h = imgh = imlib_image_get_height(); - zend_hash_internal_pointer_reset_ex(params,&pos); - while (pos) + ZEND_HASH_FOREACH_KEY_VAL(params, num_index, str_index, data) { - char *str_index; - ulong num_index; - int retval; - - retval=zend_hash_get_current_key_ex(params,&str_index,NULL,&num_index,0,&pos); - if (retval==HASH_KEY_IS_STRING) + if (str_index) { - zval **data; - zend_hash_get_current_data_ex(params,(void*)&data,&pos); - - if (!strcmp(str_index,"x")) { convert_to_long_ex(data); x=Z_LVAL_PP(data); }; - if (!strcmp(str_index,"y")) { convert_to_long_ex(data); y=Z_LVAL_PP(data); }; - if (!strcmp(str_index,"w")) { convert_to_long_ex(data); w=Z_LVAL_PP(data); }; - if (!strcmp(str_index,"h")) { convert_to_long_ex(data); h=Z_LVAL_PP(data); }; - - if (!strcmp(str_index,"h_add")) { convert_to_double_ex(data); h_add=Z_DVAL_PP(data); }; - if (!strcmp(str_index,"s_add")) { convert_to_double_ex(data); s_add=Z_DVAL_PP(data); }; - if (!strcmp(str_index,"b_add")) { convert_to_double_ex(data); b_add=Z_DVAL_PP(data); }; - if (!strcmp(str_index,"h_mul")) { convert_to_double_ex(data); h_mul=Z_DVAL_PP(data); }; - if (!strcmp(str_index,"s_mul")) { convert_to_double_ex(data); s_mul=Z_DVAL_PP(data); }; - if (!strcmp(str_index,"b_mul")) { convert_to_double_ex(data); b_mul=Z_DVAL_PP(data); }; + if (!strcmp(STR_VAL(str_index),"x")) { convert_to_long_ex(data); x=Z_LVAL_PP(data); }; + if (!strcmp(STR_VAL(str_index),"y")) { convert_to_long_ex(data); y=Z_LVAL_PP(data); }; + if (!strcmp(STR_VAL(str_index),"w")) { convert_to_long_ex(data); w=Z_LVAL_PP(data); }; + if (!strcmp(STR_VAL(str_index),"h")) { convert_to_long_ex(data); h=Z_LVAL_PP(data); }; + + if (!strcmp(STR_VAL(str_index),"h_add")) { convert_to_double_ex(data); h_add=Z_DVAL_PP(data); }; + if (!strcmp(STR_VAL(str_index),"s_add")) { convert_to_double_ex(data); s_add=Z_DVAL_PP(data); }; + if (!strcmp(STR_VAL(str_index),"b_add")) { convert_to_double_ex(data); b_add=Z_DVAL_PP(data); }; + if (!strcmp(STR_VAL(str_index),"h_mul")) { convert_to_double_ex(data); h_mul=Z_DVAL_PP(data); }; + if (!strcmp(STR_VAL(str_index),"s_mul")) { convert_to_double_ex(data); s_mul=Z_DVAL_PP(data); }; + if (!strcmp(STR_VAL(str_index),"b_mul")) { convert_to_double_ex(data); b_mul=Z_DVAL_PP(data); }; } - zend_hash_move_forward_ex(params,&pos); - } + } ZEND_HASH_FOREACH_END(); if (x<0) x=0; if (y<0) y=0; diff --git a/filters/php_testfilter.c b/filters/php_testfilter.c index ca844b3..c9e4b5b 100644 --- a/filters/php_testfilter.c +++ b/filters/php_testfilter.c @@ -14,7 +14,9 @@ _php_testfilter_tint(Imlib_Image im, HashTable* params) { Imlib_Image imge = im; Imlib_Image anoim; - HashPosition pos; + ulong num_index; + zend_string *str_index; + imlib_zval *data; Imlib_Color_Modifier cm; DATA8 atab[256]; @@ -28,30 +30,21 @@ _php_testfilter_tint(Imlib_Image im, HashTable* params) w = imlib_image_get_width(); h = imlib_image_get_height(); - zend_hash_internal_pointer_reset_ex(params,&pos); - while (pos) + ZEND_HASH_FOREACH_KEY_VAL(params, num_index, str_index, data) { - char *str_index; - ulong num_index; - int retval; - - retval=zend_hash_get_current_key_ex(params,&str_index,NULL,&num_index,0,&pos); - if (retval==HASH_KEY_IS_STRING) + if (str_index) { - zval **data; - zend_hash_get_current_data_ex(params,(void*)&data,&pos); convert_to_long_ex(data); - if (!strcmp(str_index,"red")) r=Z_LVAL_PP(data); - if (!strcmp(str_index,"blue")) b=Z_LVAL_PP(data); - if (!strcmp(str_index,"green")) g=Z_LVAL_PP(data); - if (!strcmp(str_index,"x")) x=Z_LVAL_PP(data); - if (!strcmp(str_index,"y")) y=Z_LVAL_PP(data); - if (!strcmp(str_index,"w")) w=Z_LVAL_PP(data); - if (!strcmp(str_index,"h")) h=Z_LVAL_PP(data); - if (!strcmp(str_index,"alpha")) a=Z_LVAL_PP(data); + if (!strcmp(STR_VAL(str_index),"red")) r=Z_LVAL_PP(data); + if (!strcmp(STR_VAL(str_index),"blue")) b=Z_LVAL_PP(data); + if (!strcmp(STR_VAL(str_index),"green")) g=Z_LVAL_PP(data); + if (!strcmp(STR_VAL(str_index),"x")) x=Z_LVAL_PP(data); + if (!strcmp(STR_VAL(str_index),"y")) y=Z_LVAL_PP(data); + if (!strcmp(STR_VAL(str_index),"w")) w=Z_LVAL_PP(data); + if (!strcmp(STR_VAL(str_index),"h")) h=Z_LVAL_PP(data); + if (!strcmp(STR_VAL(str_index),"alpha")) a=Z_LVAL_PP(data); } - zend_hash_move_forward_ex(params,&pos); - } + } ZEND_HASH_FOREACH_END(); /* zend_printf( "Using values red=%d,blue=%d,green=%d,x=%d,y=%d,height=%d,width=%d,alpha=%d\n", r,b,g,x,y,w,h,a ); */ -- cgit v1.2.3