summaryrefslogtreecommitdiffhomepage
path: root/php_imlib.c
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 /php_imlib.c
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!
Diffstat (limited to 'php_imlib.c')
-rw-r--r--php_imlib.c407
1 files changed, 208 insertions, 199 deletions
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_resource font;
zval **tw, **th;
PHP_Imlib_Font fn;
const char *text = NULL;
@@ -1406,7 +1405,7 @@ PHP_FUNCTION(imlib_get_text_size)
if (zend_parse_parameters(5 TSRMLS_CC, "rsZZl", &font, &text, &text_len, &tw, &th, &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);
zval_dtor(*tw);
zval_dtor(*th);
@@ -1425,13 +1424,13 @@ PHP_FUNCTION(imlib_get_text_size)
Blur an image with a given blur radius */
PHP_FUNCTION(imlib_image_blur)
{
- zval *img;
+ imlib_resource img;
long r;
Imlib_Image im;
if (zend_parse_parameters(2 TSRMLS_CC, "rl", &img, &r) == 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);
imlib_image_blur(r);
@@ -1463,7 +1462,8 @@ PHP_FUNCTION(imlib_image_draw_line)
Draw the defined polygon on an image */
PHP_FUNCTION(imlib_image_draw_polygon)
{
- zval *img, *polygon, *dbox;
+ imlib_resource img, polygon;
+ zval *dbox;
long r,g,b,a;
int cx,cy,cw,ch,argc;
Imlib_Image im;
@@ -1473,8 +1473,8 @@ PHP_FUNCTION(imlib_image_draw_polygon)
argc = ZEND_NUM_ARGS();
if (zend_parse_parameters(argc TSRMLS_CC, "rrbllll|a", &img, &polygon, &closed, &r, &g, &b, &a, &dbox) == FAILURE) return;
- ZEND_FETCH_RESOURCE(im, Imlib_Image, &img, -1, "Imlib Image", le_imlib_img);
- ZEND_FETCH_RESOURCE(poly, ImlibPolygon, &polygon, -1, "Imlib Polygon", le_imlib_poly);
+ IMLIB_FETCH_RESOURCE(im, Imlib_Image, &img, -1, "Imlib Image", le_imlib_img);
+ IMLIB_FETCH_RESOURCE(poly, ImlibPolygon, &polygon, -1, "Imlib Polygon", le_imlib_poly);
imlib_context_set_image(im);
imlib_context_set_color(r,g,b,a);
@@ -1506,7 +1506,8 @@ PHP_FUNCTION(imlib_image_draw_rectangle)
Fill a rectangle with a color range at a given angle on an image */
PHP_FUNCTION(imlib_image_fill_color_range_rectangle)
{
- zval *fim, *fcr, *fbox;
+ imlib_resource fim, fcr;
+ zval *fbox;
long x,y,width,height;
int argc,cx,cy,cw,ch;
double angle;
@@ -1516,8 +1517,8 @@ PHP_FUNCTION(imlib_image_fill_color_range_rectangle)
argc = ZEND_NUM_ARGS();
if (zend_parse_parameters(argc TSRMLS_CC, "rrlllld|a", &fim, &fcr, &x, &y, &width, &height, &angle, &fbox) == FAILURE) return;
- ZEND_FETCH_RESOURCE(cr, Imlib_Color_Range, &fcr, -1, "Imlib Color Range", le_imlib_cr);
- ZEND_FETCH_RESOURCE(im, Imlib_Image, &fim, -1, "Imlib Image", le_imlib_img);
+ IMLIB_FETCH_RESOURCE(cr, Imlib_Color_Range, &fcr, -1, "Imlib Color Range", le_imlib_cr);
+ IMLIB_FETCH_RESOURCE(im, Imlib_Image, &fim, -1, "Imlib Image", le_imlib_img);
imlib_context_set_color_range(cr);
imlib_context_set_image(im);
@@ -1550,7 +1551,8 @@ PHP_FUNCTION(imlib_image_fill_ellipse)
Draw and fill the defined polygon on an image */
PHP_FUNCTION(imlib_image_fill_polygon)
{
- zval *img, *polygon, *dbox;
+ imlib_resource img, polygon;
+ zval *dbox;
long r,g,b,a;
int cx,cy,cw,ch,argc;
Imlib_Image im;
@@ -1559,8 +1561,8 @@ PHP_FUNCTION(imlib_image_fill_polygon)
argc = ZEND_NUM_ARGS();
if (zend_parse_parameters(argc TSRMLS_CC, "rrllll|a", &img, &polygon, &r, &g, &b, &a, &dbox) == FAILURE) return;
- ZEND_FETCH_RESOURCE(im, Imlib_Image, &img, -1, "Imlib Image", le_imlib_img);
- ZEND_FETCH_RESOURCE(poly, ImlibPolygon, &polygon, -1, "Imlib Polygon", le_imlib_poly);
+ IMLIB_FETCH_RESOURCE(im, Imlib_Image, &img, -1, "Imlib Image", le_imlib_img);
+ IMLIB_FETCH_RESOURCE(poly, ImlibPolygon, &polygon, -1, "Imlib Polygon", le_imlib_poly);
imlib_context_set_image(im);
imlib_context_set_color(r,g,b,a);
@@ -1623,13 +1625,13 @@ PHP_FUNCTION(imlib_image_orientate)
/* Contributed by Gareth Ardron */
- zval *img;
+ imlib_resource img;
long r;
Imlib_Image im;
if (zend_parse_parameters(2 TSRMLS_CC, "rl", &img, &r) == 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);
imlib_image_orientate(r);
@@ -1641,20 +1643,20 @@ PHP_FUNCTION(imlib_image_orientate)
Returns the image format of an image */
PHP_FUNCTION(imlib_image_format)
{
- zval *img;
+ imlib_resource img;
Imlib_Image im;
char *name;
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);
name = imlib_image_format();
if (!name)
RETURN_FALSE;
- RETURN_STRING(name,strlen(name));
+ IMLIB_RETURN_STRING(name);
}
/* }}} */
@@ -1663,20 +1665,20 @@ PHP_FUNCTION(imlib_image_format)
Returns the filename of an image */
PHP_FUNCTION(imlib_image_get_filename)
{
- zval *img;
+ imlib_resource img;
Imlib_Image im;
const char *name = NULL;
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);
name = imlib_image_get_filename();
if (!name)
RETURN_FALSE;
- RETURN_STRING((char*)name,strlen(name));
+ IMLIB_RETURN_STRING((char*)name);
}
/* }}} */
@@ -1685,13 +1687,13 @@ PHP_FUNCTION(imlib_image_get_filename)
Returns the height of an image */
PHP_FUNCTION(imlib_image_get_height)
{
- zval *img;
+ imlib_resource img;
Imlib_Image im;
int height;
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);
height = imlib_image_get_height();
@@ -1705,13 +1707,13 @@ PHP_FUNCTION(imlib_image_get_height)
Returns the width of an image */
PHP_FUNCTION(imlib_image_get_width)
{
- zval *img;
+ imlib_resource img;
Imlib_Image im;
int width;
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);
width = imlib_image_get_width();
@@ -1725,12 +1727,12 @@ PHP_FUNCTION(imlib_image_get_width)
Return a boolean for whether or not an image has an alpha channel */
PHP_FUNCTION(imlib_image_has_alpha)
{
- 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);
if (imlib_image_has_alpha())
@@ -1749,7 +1751,7 @@ PHP_FUNCTION(imlib_image_has_alpha)
Set the alpha channel of an image, or modify it if one was already present */
PHP_FUNCTION(imlib_image_modify_alpha)
{
- zval *img;
+ imlib_resource img;
Imlib_Image im;
DATA8 map[256];
Imlib_Color_Modifier *cmod;
@@ -1759,7 +1761,7 @@ PHP_FUNCTION(imlib_image_modify_alpha)
if (zend_parse_parameters(2 TSRMLS_CC, "rl", &img, &malpha) == 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);
ratio = ((double)malpha) / 255;
@@ -1789,14 +1791,14 @@ PHP_FUNCTION(imlib_image_modify_alpha)
Sets the image format of an image. */
PHP_FUNCTION(imlib_image_set_format)
{
- zval *img;
+ imlib_resource img;
Imlib_Image im;
char *format;
int format_len;
if (zend_parse_parameters(2 TSRMLS_CC, "rs", &img, &format, &format_len) == 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);
imlib_image_set_format(format);
@@ -1810,13 +1812,13 @@ PHP_FUNCTION(imlib_image_set_format)
Sharpen an image with a given sharpen radius */
PHP_FUNCTION(imlib_image_sharpen)
{
- zval *img;
+ imlib_resource img;
long r;
Imlib_Image im;
if (zend_parse_parameters(2 TSRMLS_CC, "rl", &img, &r) == 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);
imlib_image_sharpen(r);
@@ -1869,7 +1871,11 @@ PHP_FUNCTION(imlib_list_fonts)
for (i = 0; i < fcount; i++)
{
/* FIXME: Is 1 the right parameter here? */
+#if PHP_VERSION_ID >= 70000
+ add_next_index_string(return_value, flist[i]);
+#else
add_next_index_string(return_value, flist[i], 1);
+#endif
}
imlib_free_font_list(flist,fcount);
@@ -1900,7 +1906,7 @@ PHP_FUNCTION(imlib_load_font)
RETURN_FALSE;
}
- ZEND_REGISTER_RESOURCE(return_value, fn, le_imlib_font);
+ IMLIB_REGISTER_RESOURCE(fn, le_imlib_font);
}
/* }}} */
@@ -1914,7 +1920,7 @@ PHP_FUNCTION(imlib_load_image)
Imlib_Image im;
Imlib_Load_Error im_err;
FILE* f;
- char* filename;
+ zend_string* filename;
char* img;
int img_len;
@@ -1929,10 +1935,10 @@ PHP_FUNCTION(imlib_load_image)
f = php_stream_open_wrapper_as_file(img, "rb", IGNORE_PATH | ENFORCE_SAFE_MODE | REPORT_ERRORS, &filename);
if (f == NULL) RETURN_FALSE;
- im = imlib_load_image_with_error_return(filename, &im_err);
+ im = imlib_load_image_with_error_return(STR_VAL(filename), &im_err);
fclose(f);
- efree(filename);
+ zend_string_release(filename);
if ((im_err) || (!im))
{
@@ -1945,7 +1951,7 @@ PHP_FUNCTION(imlib_load_image)
}
else
{
- ZEND_REGISTER_RESOURCE(return_value, im, le_imlib_img);
+ IMLIB_REGISTER_RESOURCE(im, le_imlib_img);
}
}
/* }}} */
@@ -1955,13 +1961,13 @@ PHP_FUNCTION(imlib_load_image)
Add a point to a given polygon */
PHP_FUNCTION(imlib_polygon_add_point)
{
- zval *polygon;
+ imlib_resource polygon;
long x,y;
ImlibPolygon poly;
if (zend_parse_parameters(3 TSRMLS_CC, "rll", &polygon, &x, &y) == FAILURE) return;
- ZEND_FETCH_RESOURCE(poly, ImlibPolygon, &polygon, -1, "Imlib Polygon", le_imlib_poly);
+ IMLIB_FETCH_RESOURCE(poly, ImlibPolygon, &polygon, -1, "Imlib Polygon", le_imlib_poly);
imlib_polygon_add_point(poly,x,y);
}
@@ -1972,14 +1978,14 @@ PHP_FUNCTION(imlib_polygon_add_point)
Check if a give point is inside a polygon */
PHP_FUNCTION(imlib_polygon_contains_point)
{
- zval *polygon;
+ imlib_resource polygon;
long x,y;
int ret;
ImlibPolygon poly;
if (zend_parse_parameters(3 TSRMLS_CC, "rll", &polygon, &x, &y) == FAILURE) return;
- ZEND_FETCH_RESOURCE(poly, ImlibPolygon, &polygon, -1, "Imlib Polygon", le_imlib_poly);
+ IMLIB_FETCH_RESOURCE(poly, ImlibPolygon, &polygon, -1, "Imlib Polygon", le_imlib_poly);
ret = imlib_polygon_contains_point(poly,x,y);
@@ -1999,13 +2005,13 @@ PHP_FUNCTION(imlib_polygon_contains_point)
Free a polygon */
PHP_FUNCTION(imlib_polygon_free)
{
- zval *polygon;
+ imlib_resource polygon;
ImlibPolygon poly;
if (zend_parse_parameters(1 TSRMLS_CC, "r", &polygon) == FAILURE) return;
- ZEND_FETCH_RESOURCE(poly, ImlibPolygon, &polygon, -1, "Imlib Polygon", le_imlib_poly);
- zend_list_delete(Z_LVAL_PP(&polygon));
+ IMLIB_FETCH_RESOURCE(poly, ImlibPolygon, &polygon, -1, "Imlib Polygon", le_imlib_poly);
+ IMLIB_DELETE_RESOURCE(&polygon);
}
/* }}} */
@@ -2014,14 +2020,14 @@ PHP_FUNCTION(imlib_polygon_free)
Get the bounding coords of a polygon */
PHP_FUNCTION(imlib_polygon_get_bounds)
{
- zval *polygon;
+ imlib_resource polygon;
zval **px1, **py1, **px2, **py2;
int x1,y1,x2,y2;
ImlibPolygon poly;
if (zend_parse_parameters(5 TSRMLS_CC, "rZZZZ", &polygon, &px1, &py1, &px2, &py2) == FAILURE) return;
- ZEND_FETCH_RESOURCE(poly, ImlibPolygon, &polygon, -1, "Imlib Polygon", le_imlib_poly);
+ IMLIB_FETCH_RESOURCE(poly, ImlibPolygon, &polygon, -1, "Imlib Polygon", le_imlib_poly);
zval_dtor(*px1);
zval_dtor(*py1);
@@ -2049,7 +2055,7 @@ PHP_FUNCTION(imlib_polygon_new)
}
poly = imlib_polygon_new();
- if (poly) ZEND_REGISTER_RESOURCE(return_value, poly, le_imlib_poly);
+ if (poly) IMLIB_REGISTER_RESOURCE( poly, le_imlib_poly);
}
/* }}} */
@@ -2058,20 +2064,21 @@ PHP_FUNCTION(imlib_polygon_new)
Save an image to a file, at an optional quality level (1-100) for jpegs. For pngs, the value will be converted to a compression level (0-9) */
PHP_FUNCTION(imlib_save_image)
{
- zval *img, **err;
+ imlib_resource img;
+ zval **err;
char* name;
int name_len;
Imlib_Image im;
Imlib_Load_Error im_err;
int argc;
long q;
- char* filename;
+ zend_string* filename;
FILE* f;
argc = ZEND_NUM_ARGS();
if (zend_parse_parameters(argc TSRMLS_CC, "rs|Zl", &img, &name, &name_len, &err, &q) == 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);
@@ -2088,10 +2095,11 @@ PHP_FUNCTION(imlib_save_image)
f = php_stream_open_wrapper_as_file(name, "wb", IGNORE_PATH | ENFORCE_SAFE_MODE | REPORT_ERRORS, &filename);
if (f == NULL) RETURN_FALSE;
- imlib_save_image_with_error_return(filename, &im_err);
+ imlib_save_image_with_error_return(STR_VAL(filename), &im_err);
fclose(f);
- efree(filename);
+
+ zend_string_release(filename);
if (im_err)
{
@@ -2113,7 +2121,7 @@ PHP_FUNCTION(imlib_save_image)
Draw a text string using a font onto an image */
PHP_FUNCTION(imlib_text_draw)
{
- zval *img, *font;
+ imlib_resource img, font;
Imlib_Image im;
PHP_Imlib_Font fn;
char *text;
@@ -2122,8 +2130,8 @@ PHP_FUNCTION(imlib_text_draw)
if (zend_parse_parameters(10 TSRMLS_CC, "rrllslllll", &img, &font, &x, &y, &text, &text_len, &dir, &r, &g, &b, &a) == FAILURE) return;
- ZEND_FETCH_RESOURCE(im, Imlib_Image, &img, -1, "Imlib Image", le_imlib_img);
- ZEND_FETCH_RESOURCE(fn, PHP_Imlib_Font, &font, -1, "Imlib Font", le_imlib_font);
+ IMLIB_FETCH_RESOURCE(im, Imlib_Image, &img, -1, "Imlib Image", le_imlib_img);
+ IMLIB_FETCH_RESOURCE(fn, PHP_Imlib_Font, &font, -1, "Imlib Font", le_imlib_font);
imlib_context_set_image(im);
imlib_context_set_color(r,g,b,a);
@@ -2158,7 +2166,8 @@ PHP_FUNCTION(imlib_set_cache_size)
Apply external filter to an image */
PHP_FUNCTION(imlib_apply_filter)
{
- zval *img, *tparams;
+ imlib_resource img;
+ zval *tparams;
Imlib_Image im;
struct php_imlib_filter* filter;
char* filter_name;
@@ -2166,7 +2175,7 @@ PHP_FUNCTION(imlib_apply_filter)
HashTable* arg_ht;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|a", &img, &filter_name, &filter_name_len, &tparams) == 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);
filter = _php_imlib_find_filter(filter_name TSRMLS_CC);
@@ -2201,7 +2210,7 @@ PHP_F