summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorPiotr Pawłow <pp@siedziba.pl>2016-09-08 23:05:41 +0200
committerPiotr Pawłow <pp@siedziba.pl>2016-09-08 23:05:41 +0200
commit87380c76cb1eb3644da7291d842281caaae63f2d (patch)
tree8957300686e074c06f6f5d142093ef0e4c40d2be
parent469cf3df58f7d076a62c51c1df2163d23989f924 (diff)
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!
-rw-r--r--filters/php_bumpmap.c30
-rw-r--r--filters/php_colormatrix.c72
-rw-r--r--filters/php_colormod.c25
-rw-r--r--filters/php_hsbcolor.c42
-rw-r--r--filters/php_testfilter.c35
-rw-r--r--php_imlib.c407
-rw-r--r--php_imlib.h65
7 files changed, 342 insertions, 334 deletions
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,");");
@@ -122,6 +115,9 @@ php_filter_deinit()
}
int
+_php_bumpmap_getfilterindex(char*);
+
+int
php_filter_exec(Imlib_Image im, char *filter, HashTable *params)
{
int index=_php_bumpmap_getfilterindex(filter);
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 );
*/
diff --git a/php_imlib.c b/php_imlib.c
index e1a2828..2e387a1 100644
--- a/php_imlib.c
+++ b/php_imlib.c
@@ -22,6 +22,7 @@
#include "php_imlib.h"
#include "php_globals.h"
#include "php_open_temporary_file.h"
+#include "ext/standard/info.h"
/* #define IMLIB_DEBUG */
@@ -207,7 +208,7 @@ zend_module_entry imlib_module_entry = {
PHP_INI_MH(OnUpdateFontCacheSize)
{
int size;
- if (sscanf(new_value,"%d",&size)==1)
+ if (sscanf(STR_VAL(new_value),"%d",&size)==1)
{
imlib_set_font_cache_size(size);
return SUCCESS;
@@ -218,41 +219,41 @@ PHP_INI_MH(OnUpdateFontCacheSize)
}
}
-static void _php_imlib_free_cm(zend_rsrc_list_entry *rsrc TSRMLS_DC)
+IMLIB_RSRC_DTOR_FUNC(_php_imlib_free_cm)
{
- imlib_context_set_color_modifier(((PHP_Imlib_Color_Modifier)rsrc->ptr)->cm);
- efree(rsrc->ptr);
+ imlib_context_set_color_modifier(((PHP_Imlib_Color_Modifier)res->ptr)->cm);
+ efree(res->ptr);
imlib_free_color_modifier();
}
-static void _php_imlib_free_filter(zend_rsrc_list_entry *rsrc TSRMLS_DC)
+IMLIB_RSRC_DTOR_FUNC(_php_imlib_free_filter)
{
- imlib_context_set_filter(rsrc->ptr);
+ imlib_context_set_filter(res->ptr);
imlib_free_filter();
}
-static void _php_imlib_free_cr(zend_rsrc_list_entry *rsrc TSRMLS_DC)
+IMLIB_RSRC_DTOR_FUNC(_php_imlib_free_cr)
{
- imlib_context_set_color_range(rsrc->ptr);
+ imlib_context_set_color_range(res->ptr);
imlib_free_color_range();
}
-static void _php_imlib_free_font(zend_rsrc_list_entry *rsrc TSRMLS_DC)
+IMLIB_RSRC_DTOR_FUNC(_php_imlib_free_font)
{
- imlib_context_set_font(((PHP_Imlib_Font)rsrc->ptr)->font);
- efree(rsrc->ptr);
+ imlib_context_set_font(((PHP_Imlib_Font)res->ptr)->font);
+ efree(res->ptr);
imlib_free_font();
}
-static void _php_imlib_free_img(zend_rsrc_list_entry *rsrc TSRMLS_DC)
+IMLIB_RSRC_DTOR_FUNC(_php_imlib_free_img)
{
- imlib_context_set_image(rsrc->ptr);
+ imlib_context_set_image(res->ptr);
imlib_free_image();
}
-static void _php_imlib_free_poly(zend_rsrc_list_entry *rsrc TSRMLS_DC)
+IMLIB_RSRC_DTOR_FUNC(_php_imlib_free_poly)
{
- imlib_polygon_free(rsrc->ptr);
+ imlib_polygon_free(res->ptr);
}
void _php_imlib_set_cache_size(int size TSRMLS_DC)
@@ -485,19 +486,19 @@ struct php_imlib_filter* _php_imlib_find_filter(char *filter_name TSRMLS_DC)
return NULL;
}
-Imlib_Image _php_imlib_get_image(zval** im_resource)
+Imlib_Image _php_imlib_get_image(imlib_resource *im_resource)
{
Imlib_Image im;
TSRMLS_FETCH();
- MY_ZEND_FETCH_RESOURCE(im, Imlib_Image, im_resource, -1, "Imlib Image", le_imlib_img);
+ IMLIB_FETCH_RESOURCE(im, Imlib_Image, im_resource, -1, "Imlib Image", le_imlib_img);
return im;
}
-Imlib_Filter _php_imlib_get_filter(zval** fil_resource)
+Imlib_Filter _php_imlib_get_filter(imlib_resource *fil_resource)
{
Imlib_Filter fil;
TSRMLS_FETCH();
- MY_ZEND_FETCH_RESOURCE(fil, Imlib_Filter, fil_resource, -1, "Imlib Filter", le_imlib_filter);
+ IMLIB_FETCH_RESOURCE(fil, Imlib_Filter, fil_resource, -1, "Imlib Filter", le_imlib_filter);
return fil;
}
@@ -522,37 +523,37 @@ void _php_imlib_color_modifier_synch(PHP_Imlib_Color_Modifier cm)
imlib_context_set_color_modifier(NULL);
}
-Imlib_Color_Modifier _php_imlib_get_cm(zval** cm_resource)
+Imlib_Color_Modifier _php_imlib_get_cm(imlib_resource *cm_resource)
{
PHP_Imlib_Color_Modifier cm;
TSRMLS_FETCH();
- MY_ZEND_FETCH_RESOURCE(cm, Imlib_Color_Modifier, cm_resource, -1, "Imlib Color Modifier", le_imlib_cm);
+ IMLIB_FETCH_RESOURCE(cm, Imlib_Color_Modifier, cm_resource, -1, "Imlib Color Modifier", le_imlib_cm);
if (cm->modified) _php_imlib_color_modifier_synch(cm);
cm->valid=0;
return cm->cm;
}
-Imlib_Font _php_imlib_get_font(zval** font_resource)
+Imlib_Font _php_imlib_get_font(imlib_resource *font_resource)
{
PHP_Imlib_Font php_font;
TSRMLS_FETCH();
- MY_ZEND_FETCH_RESOURCE(php_font, PHP_Imlib_Font, font_resource, -1, "Imlib Font", le_imlib_font);
+ IMLIB_FETCH_RESOURCE(php_font, PHP_Imlib_Font, font_resource, -1, "Imlib Font", le_imlib_font);
return php_font->font;
}
-Imlib_Color_Range _php_imlib_get_cr(zval** cr_resource)
+Imlib_Color_Range _php_imlib_get_cr(imlib_resource *cr_resource)
{
Imlib_Color_Range cr;
TSRMLS_FETCH();
- MY_ZEND_FETCH_RESOURCE(cr, Imlib_Color_Range, cr_resource, -1, "Imlib Color Range", le_imlib_cr);
+ IMLIB_FETCH_RESOURCE(cr, Imlib_Color_Range, cr_resource, -1, "Imlib Color Range", le_imlib_cr);
return cr;
}
-ImlibPolygon _php_imlib_get_poly(zval** poly_resource)
+ImlibPolygon _php_imlib_get_poly(imlib_resource *poly_resource)
{
ImlibPolygon poly;
TSRMLS_FETCH();
- MY_ZEND_FETCH_RESOURCE(poly, ImlibPolygon, poly_resource, -1, "Imlib Polygon", le_imlib_poly);
+ IMLIB_FETCH_RESOURCE(poly, ImlibPolygon, poly_resource, -1, "Imlib Polygon", le_imlib_poly);
return poly;
}
@@ -560,9 +561,9 @@ ImlibPolygon _php_imlib_get_poly(zval** poly_resource)
/* {{{ _php_imlib_free_ps_font
*/
-void _php_imlib_free_ps_font(zend_rsrc_list_entry *rsrc TSRMLS_DC)
+IMLIB_RSRC_DTOR_FUNC(_php_imlib_free_ps_font)
{
- int *font = (int *)rsrc->ptr;
+ int *font = (int *)res->ptr;
T1_DeleteFont(*font);
efree(font);
@@ -571,9 +572,9 @@ void _php_imlib_free_ps_font(zend_rsrc_list_entry *rsrc TSRMLS_DC)
/* {{{ _php_imlib_free_ps_enc
*/
-void _php_imlib_free_ps_enc(zend_rsrc_list_entry *rsrc TSRMLS_DC)
+IMLIB_RSRC_DTOR_FUNC(_php_imlib_free_ps_enc)
{
- char **enc = (char **)rsrc->ptr;
+ char **enc = (char **)res->ptr;
T1_DeleteEncoding(enc);
}
@@ -819,24 +820,20 @@ PHP_MINFO_FUNCTION(imlib)
}
}
-static void _php_convert_four_longs(zval **zone, zval **ztwo, zval **zthree,
- zval **zfour, int *one, int *two,
- int *three, int *four)
+static inline int zend_hash_index_find_wrapper(HashTable *ht, int index, imlib_zval **value)
{
- convert_to_long_ex(zone);
- convert_to_long_ex(ztwo);
- convert_to_long_ex(zthree);
- convert_to_long_ex(zfour);
- *one = Z_LVAL_PP(zone);
- *two = Z_LVAL_PP(ztwo);
- *three = Z_LVAL_PP(zthree);
- *four = Z_LVAL_PP(zfour);
+#if PHP_VERSION_ID >= 70000
+ *value = zend_hash_index_find(ht, index);
+ return (*value != NULL ? SUCCESS : FAILURE);
+#else
+ return zend_hash_index_find(ht, index, (void **)value);
+#endif
}
static int _php_handle_cliprect_array(zval **dbox, char *func_name,
int *x, int *y, int *w, int *h TSRMLS_DC)
{
- zval **element, ***box_coords;
+ imlib_zval *element, **box_coords;
int i,arrcount;
HashTable *box;
@@ -853,11 +850,11 @@ static int _php_handle_cliprect_array(zval **dbox, char *func_name,
return 0;
}
- box_coords = (zval ***)emalloc(arrcount * sizeof(zval **));
+ box_coords = (imlib_zval **)emalloc(arrcount * sizeof(imlib_zval *));
for (i = 0; i < arrcount; i++)
{
- if (zend_hash_index_find(box, i, (void **)&element) == SUCCESS)
+ if (zend_hash_index_find_wrapper(box, i, &element) == SUCCESS)
{
convert_to_long_ex(element);
box_coords[i] = element;
@@ -946,7 +943,8 @@ static void _php_imlib_draw_something(INTERNAL_FUNCTION_PARAMETERS, void (*func)
{
int argc;
int cx, cy, cw, ch;
- zval *img, *dbox;
+ imlib_resource img;
+ zval *dbox;
long x,y,w,h,r,g,b,a;
Imlib_Image im;
@@ -955,7 +953,7 @@ static void _php_imlib_draw_something(INTERNAL_FUNCTION_PARAMETERS, void (*func)
return;
}
- ZEND_FETCH_RESOURCE(im, Imlib_Image, &img, -1, "Imlib Image", le_imlib_img);
+ IMLIB_FETCH_RESOURCE(im, Imlib_Image, &img, -1, "Imlib Image", le_imlib_img);
imlib_context_set_image(im);
imlib_context_set_color(r,g,b,a);
@@ -977,12 +975,12 @@ static void _php_imlib_draw_something(INTERNAL_FUNCTION_PARAMETERS, void (*func)
static void _php_imlib_single_arg(INTERNAL_FUNCTION_PARAMETERS, void (*func)())
{
- zval *img;
+ imlib_resource img;
Imlib_Image im;
if (zend_parse_parameters(1 TSRMLS_CC, "r", &img) == FAILURE) return;
- ZEND_FETCH_RESOURCE(im, Imlib_Image, &img, -1, "Imlib Image", le_imlib_img);
+ IMLIB_FETCH_RESOURCE(im, Imlib_Image, &img, -1, "Imlib Image", le_imlib_img);
imlib_context_set_image(im);
(*func)();
@@ -1000,13 +998,13 @@ static void _php_wrap_draw_line(int x1, int y1, int x2, int y2)
Add a color to a color range at a specified distance from the previous color in the range. A distance of 0 centers it */
PHP_FUNCTION(imlib_add_color_to_color_range)
{
- zval *crange;
+ imlib_resource crange;
long x,r,g,b,a;
Imlib_Color_Range range;
if (zend_parse_parameters(6 TSRMLS_CC, "rlllll", &crange, &x, &r, &g, &b, &a) == FAILURE) return;
- ZEND_FETCH_RESOURCE(range, Imlib_Color_Range, &crange, -1, "Imlib Color Range", le_imlib_cr);
+ IMLIB_FETCH_RESOURCE(range, Imlib_Color_Range, &crange, -1, "Imlib Color Range", le_imlib_cr);
imlib_context_set_color_range(range);
imlib_context_set_color(r,g,b,a);
@@ -1019,15 +1017,15 @@ PHP_FUNCTION(imlib_add_color_to_color_range)
Blend a rectangular area from an image onto an area of another image, scaling as necessary */
PHP_FUNCTION(imlib_blend_image_onto_image)
{
- zval *dstimg, *srcimg;
+ imlib_resource dstimg, srcimg;
Imlib_Image dst,src;
long sx,sy,sw,sh,dx,dy,dw,dh;
long calias, calpha, cblend, cdither;
if (zend_parse_parameters(14 TSRMLS_CC, "rrllllllllllll", &dstimg, &srcimg, &calpha, &sx, &sy, &sw, &sh, &dx, &dy, &dw, &dh, &cdither, &cblend, &calias) == FAILURE) return;
- ZEND_FETCH_RESOURCE(src, Imlib_Image, &srcimg, -1, "Imlib Image", le_imlib_img);
- ZEND_FETCH_RESOURCE(dst, Imlib_Image, &dstimg, -1, "Imlib Image", le_imlib_img);
+ IMLIB_FETCH_RESOURCE(src, Imlib_Image, &srcimg, -1, "Imlib Image", le_imlib_img);
+ IMLIB_FETCH_RESOURCE(dst, Imlib_Image, &dstimg, -1, "Imlib Image", le_imlib_img);
imlib_context_set_image(dst);
imlib_context_set_anti_alias(calias);
@@ -1043,17 +1041,17 @@ PHP_FUNCTION(imlib_blend_image_onto_image)
Duplicate an image */
PHP_FUNCTION(imlib_clone_image)
{
- zval *img;
+ imlib_resource img;
Imlib_Image src,dst;
if (zend_parse_parameters(1 TSRMLS_CC, "r", &img) == FAILURE) return;
- ZEND_FETCH_RESOURCE(src, Imlib_Image, &img, -1, "Imlib Image", le_imlib_img);
+ IMLIB_FETCH_RESOURCE(src, Imlib_Image, &img, -1, "Imlib Image", le_imlib_img);
imlib_context_set_image(src);
dst = imlib_clone_image();
- if (dst) ZEND_REGISTER_RESOURCE(return_value, dst, le_imlib_img);
+ if (dst) IMLIB_REGISTER_RESOURCE(dst, le_imlib_img);
}
/* }}} */
@@ -1070,7 +1068,7 @@ PHP_FUNCTION(imlib_create_color_range)
cr = imlib_create_color_range();
- if (cr) ZEND_REGISTER_RESOURCE(return_value, cr, le_imlib_cr);
+ if (cr) IMLIB_REGISTER_RESOURCE(cr, le_imlib_cr);
}
/* }}} */
@@ -1097,7 +1095,7 @@ PHP_FUNCTION(imlib_create_color_modifier)
RETURN_FALSE;
}
- ZEND_REGISTER_RESOURCE(return_value, cm, le_imlib_cm);
+ IMLIB_REGISTER_RESOURCE(cm, le_imlib_cm);
}
/* }}} */
@@ -1105,18 +1103,18 @@ PHP_FUNCTION(imlib_create_color_modifier)
Create an image from a cropped region of another image */
PHP_FUNCTION(imlib_create_cropped_image)
{
- zval *img;
+ imlib_resource img;
long sx,sy,sw,sh;
Imlib_Image src,dst;
if (zend_parse_parameters(5 TSRMLS_CC, "rllll", &img, &sx, &sy, &sw, &sh) == FAILURE) return;
- ZEND_FETCH_RESOURCE(src, Imlib_Image, &img, -1, "Imlib Image", le_imlib_img);
+ IMLIB_FETCH_RESOURCE(src, Imlib_Image, &img, -1, "Imlib Image", le_imlib_img);
imlib_context_set_image(src);
dst = imlib_create_cropped_image(sx,sy,sw,sh);
- if (dst) ZEND_REGISTER_RESOURCE(return_value, dst, le_imlib_img);
+ if (dst) IMLIB_REGISTER_RESOURCE(dst, le_imlib_img);
}
/* }}} */
@@ -1125,18 +1123,18 @@ PHP_FUNCTION(imlib_create_cropped_image)
Create a scaled image from a cropped region of another image */
PHP_FUNCTION(imlib_create_cropped_scaled_image)
{
- zval *img;
+ imlib_resource img;
long sx,sy,sw,sh,dw,dh;
Imlib_Image src,dst;
if (zend_parse_parameters(7 TSRMLS_CC, "rllllll", &img, &sx, &sy, &sw, &sh, &dw, &dh) == FAILURE) return;
- ZEND_FETCH_RESOURCE(src, Imlib_Image, &img, -1, "Imlib Image", le_imlib_img);
+ IMLIB_FETCH_RESOURCE(src, Imlib_Image, &img, -1, "Imlib Image", le_imlib_img);
imlib_context_set_image(src);
dst = imlib_create_cropped_scaled_image(sx,sy, sw,sh, dw,dh);
- if (dst) ZEND_REGISTER_RESOURCE(return_value, dst, le_imlib_img);
+ if (dst) IMLIB_REGISTER_RESOURCE(dst, le_imlib_img);
}
/* }}} */
@@ -1156,7 +1154,7 @@ PHP_FUNCTION(imlib_create_image)
imlib_context_set_image(im);
memset(imlib_image_get_data(), '\0', x * y * sizeof(DATA32));
- ZEND_REGISTER_RESOURCE(return_value, im, le_imlib_img);
+ IMLIB_REGISTER_RESOURCE(im, le_imlib_img);
}
}
/* }}} */
@@ -1169,7 +1167,7 @@ PHP_FUNCTION(imlib_create_rotated_image)
/* Contributed by Gareth Ardron */
- zval *srcimg;
+ imlib_resource srcimg;
double angle, radians;
int argc;
Imlib_Image src, dst;
@@ -1177,14 +1175,14 @@ PHP_FUNCTION(imlib_create_rotated_image)
argc = ZEND_NUM_ARGS();
if (zend_parse_parameters(argc TSRMLS_CC, "rd|d", &srcimg, &angle, &radians) == FAILURE) return;
- ZEND_FETCH_RESOURCE(src, Imlib_Image, &srcimg, -1, "Imlib Image", le_imlib_img);
+ IMLIB_FETCH_RESOURCE(src, Imlib_Image, &srcimg, -1, "Imlib Image", le_imlib_img);
if (argc == 2) radians = angle * M_PI/180;
imlib_context_set_image(src);
dst = imlib_create_rotated_image(radians);
- if (dst) ZEND_REGISTER_RESOURCE(return_value, dst, le_imlib_img);
+ if (dst) IMLIB_REGISTER_RESOURCE(dst, le_imlib_img);
}
/* }}} */
@@ -1193,14 +1191,14 @@ PHP_FUNCTION(imlib_create_rotated_image)
Create a scaled copy of an image. If dstw or dsth is left blank, the aspect ratio of the source image will be preserved. */
PHP_FUNCTION(imlib_create_scaled_image)
{
- zval *img;
- zval **dstw, **dsth;
+ imlib_resource img;
+ imlib_zval *dstw, *dsth;
long sw,sh,dw,dh;
Imlib_Image src,dst;
if (zend_parse_parameters(3 TSRMLS_CC, "rZZ", &img, &dstw, &dsth) == FAILURE) return;
- ZEND_FETCH_RESOURCE(src, Imlib_Image, &img, -1, "Imlib Image", le_imlib_img);
+ IMLIB_FETCH_RESOURCE(src, Imlib_Image, &img, -1, "Imlib Image", le_imlib_img);
convert_to_long_ex(dstw);
convert_to_long_ex(dsth);
@@ -1223,7 +1221,7 @@ PHP_FUNCTION(imlib_create_scaled_image)
dst = imlib_create_cropped_scaled_image(0,0, sw,sh, dw,dh);
- if (dst) ZEND_REGISTER_RESOURCE(return_value, dst, le_imlib_img);
+ if (dst) IMLIB_REGISTER_RESOURCE(dst, le_imlib_img);
}
/* }}} */
@@ -1235,8 +1233,9 @@ PHP_FUNCTION(imlib_dump_image)
int argc, retval;
long q;
FILE *tmp;
- char *tmpfile;
- zval *img, **err;
+ zend_string *tmpfile;
+ imlib_resource img;
+ zval **err;
Imlib_Image im;
Imlib_Load_Error im_err;
@@ -1248,7 +1247,7 @@ PHP_FUNCTION(imlib_dump_image)
ZVAL_LONG(*err,0);
}
- ZEND_FETCH_RESOURCE(im, Imlib_Image, &img, -1, "Imlib Image", le_imlib_img);
+ IMLIB_FETCH_RESOURCE(im, Imlib_Image, &img, -1, "Imlib Image", le_imlib_img);
tmp = php_open_temporary_file("", "", &tmpfile TSRMLS_CC);
if (tmp == NULL) {
@@ -1266,7 +1265,7 @@ PHP_FUNCTION(imlib_dump_image)
imlib_image_attach_data_value("quality",NULL,q,NULL);
}
- imlib_save_image_with_error_return(tmpfile,&im_err);
+ imlib_save_image_with_error_return(STR_VAL(tmpfile),&im_err);
if (im_err)
{
@@ -1275,7 +1274,7 @@ PHP_FUNCTION(imlib_dump_image)
ZVAL_LONG(*err,im_err);
}
_php_handle_imlib_error(INTERNAL_FUNCTION_PARAM_PASSTHRU,
- im_err,tmpfile);
+ im_err,STR_VAL(tmpfile));
fclose(tmp);
VCWD_UNLINK((const char *)tmpfile); /* make sure that the temporary file is removed */
efree(tmpfile);
@@ -1311,13 +1310,13 @@ PHP_FUNCTION(imlib_dump_image)
Free a color range */
PHP_FUNCTION(imlib_free_color_range)
{
- zval *fcr;
+ imlib_resource fcr;
Imlib_Color_Range cr;
if (zend_parse_parameters(1 TSRMLS_CC, "r", &fcr) == FAILURE) return;
- ZEND_FETCH_RESOURCE(cr, Imlib_Color_Range, &fcr, -1, "Imlib Color Range", le_imlib_cr);
- zend_list_delete(Z_LVAL_PP(&fcr));
+ IMLIB_FETCH_RESOURCE(cr, Imlib_Color_Range, &fcr, -1, "Imlib Color Range", le_imlib_cr);
+ IMLIB_DELETE_RESOURCE(&fcr);
}
/* }}} */
@@ -1326,13 +1325,13 @@ PHP_FUNCTION(imlib_free_color_range)
Free a color modifier */
PHP_FUNCTION(imlib_free_color_modifier)
{
- zval *fcm;
+ imlib_resource fcm;
PHP_Imlib_Color_Modifier cm;
if (zend_parse_parameters(1 TSRMLS_CC, "r", &fcm) == FAILURE) return;
- ZEND_FETCH_RESOURCE(cm, PHP_Imlib_Color_Modifier, &fcm, -1, "Imlib Color Modifier", le_imlib_cm);
- zend_list_delete(Z_LVAL_PP(&fcm));
+ IMLIB_FETCH_RESOURCE(cm, PHP_Imlib_Color_Modifier, &fcm, -1, "Imlib Color Modifier", le_imlib_cm);
+ IMLIB_DELETE_RESOURCE(&fcm);
}
/* }}} */
@@ -1340,13 +1339,13 @@ PHP_FUNCTION(imlib_free_color_modifier)
Free a font */
PHP_FUNCTION(imlib_free_font)
{
- zval *font;
+ imlib_resource font;
PHP_Imlib_Font fn;
if (zend_parse_parameters(1 TSRMLS_CC, "r", &font) == FAILURE) return;
- ZEND_FETCH_RESOURCE(fn, PHP_Imlib_Font, &font, -1, "Imlib Font", le_imlib_font);
- zend_list_delete(Z_LVAL_PP(&font));
+ IMLIB_FETCH_RESOURCE(fn, PHP_Imlib_Font, &font, -1, "Imlib Font", le_imlib_font);
+ IMLIB_DELETE_RESOURCE(&font);
}
/* }}} */
@@ -1355,13 +1354,13 @@ PHP_FUNCTION(imlib_free_font)
Free an image */
PHP_FUNCTION(imlib_free_image)
{
- zval *img;
+ imlib_resource img;
Imlib_Image im;
if (zend_parse_parameters(1 TSRMLS_CC, "r", &img) == FAILURE) return;
- ZEND_FETCH_RESOURCE(im, Imlib_Image, &img, -1, "Imlib Image", le_imlib_img);
- zend_list_delete(Z_LVAL_PP(&img));
+ IMLIB_FETCH_RESOURCE(im, Imlib_Image, &img, -1, "Imlib Image", le_imlib_img);
+ IMLIB_DELETE_RESOURCE(&img);
}
/* }}} */
@@ -1370,7 +1369,7 @@ PHP_FUNCTION(imlib_free_image)
Determines the horizontal and vertical advance of a string if drawn with a given font in the specified direction*/
PHP_FUNCTION(imlib_get_text_advance)
{
- zval *font;
+ imlib_resource font;
zval **thoriz_adv, **tvert_adv;
PHP_Imlib_Font fn;
const char *text = NULL;
@@ -1379,7 +1378,7 @@ PHP_FUNCTION(imlib_get_text_advance)
if (zend_parse_parameters(5 TSRMLS_CC, "rsZZl", &font, &text, &text_len, &thoriz_adv, &tvert_adv, &dir) == FAILURE) return;
- ZEND_FETCH_RESOURCE(fn, PHP_Imlib_Font, &font, -1, "Imlib Font", le_imlib_font);
+ IMLIB_FETCH_RESOURCE(fn, PHP_Imlib_Font, &font, -1, "Imlib Font", le_imlib_font);
imlib_context_set_font(fn->font);
imlib_context_set_direction(dir);
@@ -1397,7 +1396,7 @@ PHP_FUNCTION(imlib_get_text_advance)
Determines the width and height of a string if drawn with a given font in the specified direction */
PHP_FUNCTION(imlib_get_text_size)
{
- zval *font;
+ imlib_resour