From 6930ff5994521df43e29b4d7ba90f583a5343f07 Mon Sep 17 00:00:00 2001 From: pp Date: Tue, 2 Nov 2010 12:49:14 +0000 Subject: - updated for PHP 5.3, fixed compilation, removed deprecated API calls git-svn-id: https://siedziba.pl:790/svn/repos/php-imlib/trunk@333 455248ca-bdda-0310-9134-f4ebb693071a --- php_imlib.c | 950 +++++++++++++++++++++--------------------------------------- 1 file changed, 324 insertions(+), 626 deletions(-) diff --git a/php_imlib.c b/php_imlib.c index 0d437d9..383fddd 100644 --- a/php_imlib.c +++ b/php_imlib.c @@ -37,7 +37,17 @@ int gd_imlib_id; zend_imlib_globals imlib_globals; #endif -static + ZEND_BEGIN_ARG_INFO(second_arg_force_ref, 0) + ZEND_ARG_PASS_INFO(0) + ZEND_ARG_PASS_INFO(1) + ZEND_END_ARG_INFO(); + + ZEND_BEGIN_ARG_INFO(third_arg_force_ref, 0) + ZEND_ARG_PASS_INFO(0) + ZEND_ARG_PASS_INFO(0) + ZEND_ARG_PASS_INFO(1) + ZEND_END_ARG_INFO(); + ZEND_BEGIN_ARG_INFO(third_and_fourth_arg_force_ref, 0) ZEND_ARG_PASS_INFO(0) ZEND_ARG_PASS_INFO(0) @@ -45,7 +55,6 @@ static ZEND_ARG_PASS_INFO(1) ZEND_END_ARG_INFO(); -static ZEND_BEGIN_ARG_INFO(second_through_fifth_arg_force_ref, 0) ZEND_ARG_PASS_INFO(0) ZEND_ARG_PASS_INFO(1) @@ -54,7 +63,6 @@ static ZEND_ARG_PASS_INFO(1) ZEND_END_ARG_INFO(); -static ZEND_BEGIN_ARG_INFO(third_through_sixth_arg_force_ref, 0) ZEND_ARG_PASS_INFO(0) ZEND_ARG_PASS_INFO(0) @@ -936,19 +944,18 @@ static int _php_handle_imlib_error(INTERNAL_FUNCTION_PARAMETERS, static void _php_imlib_draw_something(INTERNAL_FUNCTION_PARAMETERS, void (*func)(), char *func_name) { - zval **img, **d1, **d2, **d3, **d4, **dr, **dg, **db, **da, **dbox; - int x,y,w,h,r,g,b,a,cx,cy,cw,ch,argc; + int argc; + int cx, cy, cw, ch; + zval *img, *dbox; + long x,y,w,h,r,g,b,a; Imlib_Image im; argc = ZEND_NUM_ARGS(); - if (argc < 9 || argc > 10 || zend_get_parameters_ex(argc, &img, &d1, &d2, &d3, &d4, &dr, &dg, &db, &da, &dbox) == FAILURE) { - WRONG_PARAM_COUNT; + if (zend_parse_parameters(argc TSRMLS_CC, "rllllllll|a", &img, &x, &y, &w, &h, &r, &g, &b, &a, &dbox) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(im, Imlib_Image, img, -1, "Imlib Image", le_imlib_img); - - _php_convert_four_longs(d1,d2,d3,d4,&x,&y,&w,&h); - _php_convert_four_longs(dr,dg,db,da,&r,&g,&b,&a); + ZEND_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); @@ -958,7 +965,7 @@ static void _php_imlib_draw_something(INTERNAL_FUNCTION_PARAMETERS, void (*func) if (argc > 9) { - if (!_php_handle_cliprect_array(dbox, func_name, &cx,&cy,&cw,&ch TSRMLS_CC)) + if (!_php_handle_cliprect_array(&dbox, func_name, &cx,&cy,&cw,&ch TSRMLS_CC)) RETURN_FALSE; imlib_context_set_cliprect(cx,cy,cw,ch); } @@ -970,14 +977,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; + zval *img; Imlib_Image im; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &img) == FAILURE) { - WRONG_PARAM_COUNT; - } + 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_FETCH_RESOURCE(im, Imlib_Image, &img, -1, "Imlib Image", le_imlib_img); imlib_context_set_image(im); (*func)(); @@ -995,19 +1000,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, **cx, **cr, **cg, **cb, **ca; - int x,r,g,b,a; + zval *crange; + long x,r,g,b,a; Imlib_Color_Range range; - if (ZEND_NUM_ARGS() != 6 || zend_get_parameters_ex(6, &crange, &cx, &cr, &cg, &cb, &ca) == FAILURE) { - WRONG_PARAM_COUNT; - } - - ZEND_FETCH_RESOURCE(range, Imlib_Color_Range, crange, -1, "Imlib Color Range", le_imlib_cr); + if (zend_parse_parameters(6 TSRMLS_CC, "rlllll", &crange, &x, &r, &g, &b, &a) == FAILURE) return; - convert_to_long_ex(cx); - x = Z_LVAL_PP(cx); - _php_convert_four_longs(cr,cg,cb,ca,&r,&g,&b,&a); + ZEND_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); @@ -1020,29 +1019,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, **malpha, **srcx, **srcy, **srcw, **srch, **dstx, **dsty, **dstw, **dsth, **dither, **blend, **alias; + zval *dstimg, *srcimg; Imlib_Image dst,src; - int sx,sy,sw,sh,dx,dy,dw,dh; - int calias, calpha, cblend, cdither; - - if (ZEND_NUM_ARGS() != 14 || zend_get_parameters_ex(14, &dstimg, &srcimg, &malpha, &srcx, &srcy, &srcw, &srch, &dstx, &dsty, &dstw, &dsth, &dither, &blend, &alias) == FAILURE) { - WRONG_PARAM_COUNT; - } - - 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); + long sx,sy,sw,sh,dx,dy,dw,dh; + long calias, calpha, cblend, cdither; - _php_convert_four_longs(srcx,srcy,srcw,srch,&sx,&sy,&sw,&sh); - _php_convert_four_longs(dstx,dsty,dstw,dsth,&dx,&dy,&dw,&dh); + if (zend_parse_parameters(14 TSRMLS_CC, "rrllllllllllll", &dstimg, &srcimg, &calpha, &sx, &sy, &sw, &sh, &dx, &dy, &dw, &dh, &cdither, &cblend, &calias) == FAILURE) return; - convert_to_long_ex(malpha); - convert_to_long_ex(dither); - convert_to_long_ex(blend); - convert_to_long_ex(alias); - calpha = Z_LVAL_PP(malpha); - cdither = Z_LVAL_PP(dither); - cblend = Z_LVAL_PP(blend); - calias = Z_LVAL_PP(alias); + 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_context_set_image(dst); imlib_context_set_anti_alias(calias); @@ -1058,14 +1043,12 @@ PHP_FUNCTION(imlib_blend_image_onto_image) Duplicate an image */ PHP_FUNCTION(imlib_clone_image) { - zval **img; + zval *img; Imlib_Image src,dst; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &img) == FAILURE) { - WRONG_PARAM_COUNT; - } + if (zend_parse_parameters(1 TSRMLS_CC, "r", &img) == FAILURE) return; - ZEND_FETCH_RESOURCE(src, Imlib_Image, img, -1, "Imlib Image", le_imlib_img); + ZEND_FETCH_RESOURCE(src, Imlib_Image, &img, -1, "Imlib Image", le_imlib_img); imlib_context_set_image(src); dst = imlib_clone_image(); @@ -1122,17 +1105,13 @@ PHP_FUNCTION(imlib_create_color_modifier) Create an image from a cropped region of another image */ PHP_FUNCTION(imlib_create_cropped_image) { - zval **img, **srcx, **srcy, **srcw, **srch; - int sx,sy,sw,sh; + zval *img; + long sx,sy,sw,sh; Imlib_Image src,dst; - if (ZEND_NUM_ARGS() != 5 || zend_get_parameters_ex(5, &img, &srcx, &srcy, &srcw, &srch) == FAILURE) { - WRONG_PARAM_COUNT; - } - - ZEND_FETCH_RESOURCE(src, Imlib_Image, img, -1, "Imlib Image", le_imlib_img); + if (zend_parse_parameters(5 TSRMLS_CC, "rllll", &img, &sx, &sy, &sw, &sh) == FAILURE) return; - _php_convert_four_longs(srcx,srcy,srcw,srch,&sx,&sy,&sw,&sh); + ZEND_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); @@ -1146,22 +1125,13 @@ 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, **srcx, **srcy, **srcw, **srch, **dstw, **dsth; - int sx,sy,sw,sh,dw,dh; + zval *img; + long sx,sy,sw,sh,dw,dh; Imlib_Image src,dst; - if (ZEND_NUM_ARGS() != 7 || zend_get_parameters_ex(7, &img, &srcx, &srcy, &srcw, - &srch, &dstw, &dsth) == FAILURE) { - WRONG_PARAM_COUNT; - } + 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); - - _php_convert_four_longs(srcx,srcy,srcw,srch,&sx,&sy,&sw,&sh); - convert_to_long_ex(dstw); - convert_to_long_ex(dsth); - dw = Z_LVAL_PP(dstw); - dh = Z_LVAL_PP(dsth); + ZEND_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); @@ -1175,18 +1145,10 @@ PHP_FUNCTION(imlib_create_cropped_scaled_image) Create a new image with the specified dimensions */ PHP_FUNCTION(imlib_create_image) { - zval **nx, **ny; Imlib_Image im; - int x,y; + long x,y; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &nx, &ny) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_long_ex(nx); - convert_to_long_ex(ny); - x = Z_LVAL_PP(nx); - y = Z_LVAL_PP(ny); + if (zend_parse_parameters(2 TSRMLS_CC, "ll", &x, &y) == FAILURE) return; im = imlib_create_image(x,y); @@ -1207,29 +1169,17 @@ PHP_FUNCTION(imlib_create_rotated_image) /* Contributed by Gareth Ardron */ - zval **srcimg, **cangle, **crads; - double angle, radians, pi = 3.141592654; + zval *srcimg; + double angle, radians; int argc; Imlib_Image src, dst; argc = ZEND_NUM_ARGS(); - if (argc < 2 || argc > 3 || zend_get_parameters_ex(argc, &srcimg, &cangle, &crads) == FAILURE) { - WRONG_PARAM_COUNT; - } + 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); + ZEND_FETCH_RESOURCE(src, Imlib_Image, &srcimg, -1, "Imlib Image", le_imlib_img); - if (argc > 2) - { - convert_to_double_ex(crads); - radians = Z_DVAL_PP(crads); - } - else - { - convert_to_double_ex(cangle); - angle = Z_DVAL_PP(cangle); - radians = angle * pi/180; - } + if (argc == 2) radians = angle * M_PI/180; imlib_context_set_image(src); dst = imlib_create_rotated_image(radians); @@ -1243,15 +1193,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, **dstw, **dsth; - int sw,sh,dw,dh; + zval *img; + zval **dstw, **dsth; + long sw,sh,dw,dh; Imlib_Image src,dst; - if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &img, &dstw, &dsth) == FAILURE) { - WRONG_PARAM_COUNT; - } + 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); + ZEND_FETCH_RESOURCE(src, Imlib_Image, &img, -1, "Imlib Image", le_imlib_img); convert_to_long_ex(dstw); convert_to_long_ex(dsth); @@ -1266,10 +1215,10 @@ PHP_FUNCTION(imlib_create_scaled_image) sw = imlib_image_get_width(); sh = imlib_image_get_height(); if (!dw) { - dw = (int) (((double)dh * sw) / sh); + dw = (long) (((double)dh * sw) / sh); } if (!dh) { - dh = (int) (((double) dw * sh) / sw); + dh = (long) (((double) dw * sh) / sw); } dst = imlib_create_cropped_scaled_image(0,0, sw,sh, dw,dh); @@ -1283,24 +1232,23 @@ PHP_FUNCTION(imlib_create_scaled_image) Output an image at an optional quality setting */ PHP_FUNCTION(imlib_dump_image) { - int argc, q, retval; + int argc, retval; + long q; FILE *tmp; char *tmpfile; - zval **img, **quality, **err; + zval *img, **err; Imlib_Image im; Imlib_Load_Error im_err; argc = ZEND_NUM_ARGS(); - if (argc < 1 || argc > 3 || zend_get_parameters_ex(argc, &img, &err, &quality) == FAILURE) { - WRONG_PARAM_COUNT; - } + if (zend_parse_parameters(argc TSRMLS_CC, "r|Zl", &img, &err, &q) == FAILURE) return; if (argc > 1) { zval_dtor(*err); ZVAL_LONG(*err,0); } - ZEND_FETCH_RESOURCE(im, Imlib_Image, img, -1, "Imlib Image", le_imlib_img); + ZEND_FETCH_RESOURCE(im, Imlib_Image, &img, -1, "Imlib Image", le_imlib_img); tmp = php_open_temporary_file("", "", &tmpfile TSRMLS_CC); if (tmp == NULL) { @@ -1315,8 +1263,6 @@ PHP_FUNCTION(imlib_dump_image) if (argc > 2) { - convert_to_long_ex(quality); - q = Z_LVAL_PP(quality); imlib_image_attach_data_value("quality",NULL,q,NULL); } @@ -1365,15 +1311,13 @@ PHP_FUNCTION(imlib_dump_image) Free a color range */ PHP_FUNCTION(imlib_free_color_range) { - zval **fcr; + zval *fcr; Imlib_Color_Range cr; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &fcr) == FAILURE) { - WRONG_PARAM_COUNT; - } + 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)); + ZEND_FETCH_RESOURCE(cr, Imlib_Color_Range, &fcr, -1, "Imlib Color Range", le_imlib_cr); + zend_list_delete(Z_LVAL_PP(&fcr)); } /* }}} */ @@ -1382,15 +1326,13 @@ PHP_FUNCTION(imlib_free_color_range) Free a color modifier */ PHP_FUNCTION(imlib_free_color_modifier) { - zval **fcm; + zval *fcm; PHP_Imlib_Color_Modifier cm; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &fcm) == FAILURE) { - WRONG_PARAM_COUNT; - } + 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)); + ZEND_FETCH_RESOURCE(cm, PHP_Imlib_Color_Modifier, &fcm, -1, "Imlib Color Modifier", le_imlib_cm); + zend_list_delete(Z_LVAL_PP(&fcm)); } /* }}} */ @@ -1398,15 +1340,13 @@ PHP_FUNCTION(imlib_free_color_modifier) Free a font */ PHP_FUNCTION(imlib_free_font) { - zval **font; + zval *font; PHP_Imlib_Font fn; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &font) == FAILURE) { - WRONG_PARAM_COUNT; - } + 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)); + ZEND_FETCH_RESOURCE(fn, PHP_Imlib_Font, &font, -1, "Imlib Font", le_imlib_font); + zend_list_delete(Z_LVAL_PP(&font)); } /* }}} */ @@ -1415,15 +1355,13 @@ PHP_FUNCTION(imlib_free_font) Free an image */ PHP_FUNCTION(imlib_free_image) { - zval **img; + zval *img; Imlib_Image im; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &img) == FAILURE) { - WRONG_PARAM_COUNT; - } + 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)); + ZEND_FETCH_RESOURCE(im, Imlib_Image, &img, -1, "Imlib Image", le_imlib_img); + zend_list_delete(Z_LVAL_PP(&img)); } /* }}} */ @@ -1432,33 +1370,23 @@ 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, **textstr, **thoriz_adv, **tvert_adv, **tdir; + zval *font; + zval **thoriz_adv, **tvert_adv; PHP_Imlib_Font fn; const char *text = NULL; - int horiz_adv, vert_adv, dir; - - if (ZEND_NUM_ARGS() != 5 || zend_get_parameters_ex(5, &font, &textstr, &thoriz_adv, &tvert_adv, &tdir) == FAILURE) { - WRONG_PARAM_COUNT; - } + int text_len, horiz_adv, vert_adv; + long dir; - ZEND_FETCH_RESOURCE(fn, PHP_Imlib_Font, font, -1, "Imlib Font", le_imlib_font); + if (zend_parse_parameters(5 TSRMLS_CC, "rsZZl", &font, &text, &text_len, &thoriz_adv, &tvert_adv, &dir) == FAILURE) return; - zval_dtor(*thoriz_adv); - zval_dtor(*tvert_adv); - - convert_to_string_ex(textstr); - convert_to_long_ex(thoriz_adv); - convert_to_long_ex(tvert_adv); - convert_to_long_ex(tdir); - text = Z_STRVAL_PP(textstr); - horiz_adv = Z_LVAL_PP(thoriz_adv); - vert_adv = Z_LVAL_PP(tvert_adv); - dir = Z_LVAL_PP(tdir); + ZEND_FETCH_RESOURCE(fn, PHP_Imlib_Font, &font, -1, "Imlib Font", le_imlib_font); imlib_context_set_font(fn->font); imlib_context_set_direction(dir); imlib_get_text_advance(text, &horiz_adv, &vert_adv); + zval_dtor(*thoriz_adv); + zval_dtor(*tvert_adv); ZVAL_LONG(*thoriz_adv,horiz_adv); ZVAL_LONG(*tvert_adv,vert_adv); } @@ -1469,29 +1397,20 @@ 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, **textstr, **tw, **th, **tdir; + zval *font; + zval **tw, **th; PHP_Imlib_Font fn; const char *text = NULL; - int w,h,dir; + int text_len, w,h; + long dir; - if (ZEND_NUM_ARGS() != 5 || zend_get_parameters_ex(5, &font, &textstr, &tw, &th, &tdir) == FAILURE) { - WRONG_PARAM_COUNT; - } + 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); + ZEND_FETCH_RESOURCE(fn, PHP_Imlib_Font, &font, -1, "Imlib Font", le_imlib_font); zval_dtor(*tw); zval_dtor(*th); - convert_to_string_ex(textstr); - convert_to_long_ex(tw); - convert_to_long_ex(th); - convert_to_long_ex(tdir); - text = Z_STRVAL_PP(textstr); - w = Z_LVAL_PP(tw); - h = Z_LVAL_PP(th); - dir = Z_LVAL_PP(tdir); - imlib_context_set_font(fn->font); imlib_context_set_direction(dir); imlib_get_text_size(text, &w, &h); @@ -1506,18 +1425,13 @@ PHP_FUNCTION(imlib_get_text_size) Blur an image with a given blur radius */ PHP_FUNCTION(imlib_image_blur) { - zval **img, **radius; - int r; + zval *img; + long r; Imlib_Image im; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &img, &radius) == FAILURE) { - WRONG_PARAM_COUNT; - } + 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); - - convert_to_long_ex(radius); - r = Z_LVAL_PP(radius); + ZEND_FETCH_RESOURCE(im, Imlib_Image, &img, -1, "Imlib Image", le_imlib_img); imlib_context_set_image(im); imlib_image_blur(r); @@ -1549,31 +1463,25 @@ PHP_FUNCTION(imlib_image_draw_line) Draw the defined polygon on an image */ PHP_FUNCTION(imlib_image_draw_polygon) { - zval **img, **polygon, **pclosed, **pr, **pg, **pb, **pa, **dbox; - int r,g,b,a,cx,cy,cw,ch,argc; + zval *img, *polygon, *dbox; + long r,g,b,a; + int cx,cy,cw,ch,argc; Imlib_Image im; ImlibPolygon poly; - int closed; + zend_bool closed; argc = ZEND_NUM_ARGS(); - if (argc < 7 || argc > 8 || zend_get_parameters_ex(argc, &img, &polygon, &pclosed, &pr, &pg, &pb, &pa, &dbox) == FAILURE) { - WRONG_PARAM_COUNT; - } - - 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); - - _php_convert_four_longs(pr,pg,pb,pa,&r,&g,&b,&a); + if (zend_parse_parameters(argc TSRMLS_CC, "rrbllll|a", &img, &polygon, &closed, &r, &g, &b, &a, &dbox) == FAILURE) return; - convert_to_long_ex(pclosed); - closed = Z_LVAL_PP(pclosed); + 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_context_set_image(im); imlib_context_set_color(r,g,b,a); if (argc > 7) { - if (!_php_handle_cliprect_array(dbox, "imlib_image_draw_polygon", &cx, &cy, &cw, &ch TSRMLS_CC)) + if (!_php_handle_cliprect_array(&dbox, "imlib_image_draw_polygon", &cx, &cy, &cw, &ch TSRMLS_CC)) RETURN_FALSE; imlib_context_set_cliprect(cx,cy,cw,ch); } @@ -1598,30 +1506,25 @@ 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, **fx, **fy, **fwidth, **fheight, **fangle, **fbox; - int x,y,width,height,argc,cx,cy,cw,ch; + zval *fim, *fcr, *fbox; + long x,y,width,height; + int argc,cx,cy,cw,ch; double angle; Imlib_Image im; Imlib_Color_Range cr; argc = ZEND_NUM_ARGS(); - if (argc < 7 || argc > 8 || zend_get_parameters_ex(argc, &fim, &fcr, &fx, &fy, &fwidth, &fheight, &fangle, &fbox) == FAILURE) { - WRONG_PARAM_COUNT; - } - - _php_convert_four_longs(fx,fy,fwidth,fheight,&x,&y,&width,&height); - convert_to_double_ex(fangle); - angle = Z_DVAL_PP(fangle); + 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); + 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_context_set_color_range(cr); imlib_context_set_image(im); if (argc > 7) { - if (!_php_handle_cliprect_array(fbox, "imlib_image_fill_color_range_rectangle", &cx,&cy,&cw,&ch TSRMLS_CC)) + if (!_php_handle_cliprect_array(&fbox, "imlib_image_fill_color_range_rectangle", &cx,&cy,&cw,&ch TSRMLS_CC)) RETURN_FALSE; imlib_context_set_cliprect(cx,cy,cw,ch); } @@ -1647,27 +1550,24 @@ PHP_FUNCTION(imlib_image_fill_ellipse) Draw and fill the defined polygon on an image */ PHP_FUNCTION(imlib_image_fill_polygon) { - zval **img, **polygon, **pr, **pg, **pb, **pa, **dbox; - int r,g,b,a,cx,cy,cw,ch,argc; + zval *img, *polygon, *dbox; + long r,g,b,a; + int cx,cy,cw,ch,argc; Imlib_Image im; ImlibPolygon poly; argc = ZEND_NUM_ARGS(); - if (argc < 6 || argc > 7 || zend_get_parameters_ex(argc, &img, &polygon, &pr, &pg, &pb, &pa, &dbox) == FAILURE) { - WRONG_PARAM_COUNT; - } + 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); - - _php_convert_four_longs(pr,pg,pb,pa,&r,&g,&b,&a); + 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_context_set_image(im); imlib_context_set_color(r,g,b,a); if (argc > 6) { - if (!_php_handle_cliprect_array(dbox, "imlib_image_fill_polygon", &cx, &cy, &cw, &ch TSRMLS_CC)) + if (!_php_handle_cliprect_array(&dbox, "imlib_image_fill_polygon", &cx, &cy, &cw, &ch TSRMLS_CC)) RETURN_FALSE; imlib_context_set_cliprect(cx,cy,cw,ch); } @@ -1723,18 +1623,15 @@ PHP_FUNCTION(imlib_image_orientate) /* Contributed by Gareth Ardron */ - zval **img, **stepping; - int r; + zval *img; + long r; Imlib_Image im; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &img, &stepping) == FAILURE) { - WRONG_PARAM_COUNT; - } + 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); + ZEND_FETCH_RESOURCE(im, Imlib_Image, &img, -1, "Imlib Image", le_imlib_img); imlib_context_set_image(im); - r = Z_LVAL_PP(stepping); imlib_image_orientate(r); } /* }}} */ @@ -1744,15 +1641,13 @@ PHP_FUNCTION(imlib_image_orientate) Returns the image format of an image */ PHP_FUNCTION(imlib_image_format) { - zval **img; + zval *img; Imlib_Image im; char *name; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &img) == FAILURE) { - WRONG_PARAM_COUNT; - } + 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_FETCH_RESOURCE(im, Imlib_Image, &img, -1, "Imlib Image", le_imlib_img); imlib_context_set_image(im); name = imlib_image_format(); @@ -1768,15 +1663,13 @@ PHP_FUNCTION(imlib_image_format) Returns the filename of an image */ PHP_FUNCTION(imlib_image_get_filename) { - zval **img; + zval *img; Imlib_Image im; const char *name = NULL; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &img) == FAILURE) { - WRONG_PARAM_COUNT; - } + 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_FETCH_RESOURCE(im, Imlib_Image, &img, -1, "Imlib Image", le_imlib_img); imlib_context_set_image(im); name = imlib_image_get_filename(); @@ -1792,15 +1685,13 @@ PHP_FUNCTION(imlib_image_get_filename) Returns the height of an image */ PHP_FUNCTION(imlib_image_get_height) { - zval **img; + zval *img; Imlib_Image im; int height; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &img) == FAILURE) { - WRONG_PARAM_COUNT; - } + 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_FETCH_RESOURCE(im, Imlib_Image, &img, -1, "Imlib Image", le_imlib_img); imlib_context_set_image(im); height = imlib_image_get_height(); @@ -1814,15 +1705,13 @@ PHP_FUNCTION(imlib_image_get_height) Returns the width of an image */ PHP_FUNCTION(imlib_image_get_width) { - zval **img; + zval *img; Imlib_Image im; int width; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &img) == FAILURE) { - WRONG_PARAM_COUNT; - } + 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_FETCH_RESOURCE(im, Imlib_Image, &img, -1, "Imlib Image", le_imlib_img); imlib_context_set_image(im); width = imlib_image_get_width(); @@ -1836,14 +1725,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; + zval *img; Imlib_Image im; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &img) == FAILURE) { - WRONG_PARAM_COUNT; - } + 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_FETCH_RESOURCE(im, Imlib_Image, &img, -1, "Imlib Image", le_imlib_img); imlib_context_set_image(im); if (imlib_image_has_alpha()) @@ -1862,21 +1749,18 @@ 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, **alpha; + zval *img; Imlib_Image im; DATA8 map[256]; Imlib_Color_Modifier *cmod; - int malpha, i; + long malpha; + int i; double ratio; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &img, &alpha) == FAILURE) { - WRONG_PARAM_COUNT; - } + 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); + ZEND_FETCH_RESOURCE(im, Imlib_Image, &img, -1, "Imlib Image", le_imlib_img); - convert_to_long_ex(alpha); - malpha = Z_LVAL_PP(alpha); ratio = ((double)malpha) / 255; imlib_context_set_image(im); @@ -1905,21 +1789,14 @@ PHP_FUNCTION(imlib_image_modify_alpha) Sets the image format of an image. */ PHP_FUNCTION(imlib_image_set_format) { - zval **img, **zformat; + zval *img; Imlib_Image im; char *format; + int format_len; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &img, &zformat) == FAILURE) { - WRONG_PARAM_COUNT; - } - - ZEND_FETCH_RESOURCE(im, Imlib_Image, img, -1, "Imlib Image", le_imlib_img); + if (zend_parse_parameters(2 TSRMLS_CC, "rs", &img, &format, &format_len) == FAILURE) return; - convert_to_string_ex(zformat); - format = Z_STRVAL_PP(zformat); - if (!format) { - RETURN_FALSE; - } + ZEND_FETCH_RESOURCE(im, Imlib_Image, &img, -1, "Imlib Image", le_imlib_img); imlib_context_set_image(im); imlib_image_set_format(format); @@ -1933,18 +1810,13 @@ PHP_FUNCTION(imlib_image_set_format) Sharpen an image with a given sharpen radius */ PHP_FUNCTION(imlib_image_sharpen) { - zval **img, **radius; - int r; + zval *img; + long r; Imlib_Image im; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &img, &radius) == FAILURE) { - WRONG_PARAM_COUNT; - } - - ZEND_FETCH_RESOURCE(im, Imlib_Image, img, -1, "Imlib Image", le_imlib_img); + if (zend_parse_parameters(2 TSRMLS_CC, "rl", &img, &r) == FAILURE) return; - convert_to_long_ex(radius); - r = Z_LVAL_PP(radius); + ZEND_FETCH_RESOURCE(im, Imlib_Image, &img, -1, "Imlib Image", le_imlib_img); imlib_context_set_image(im); imlib_image_sharpen(r); @@ -2009,26 +1881,22 @@ PHP_FUNCTION(imlib_list_fonts) Load a font */ PHP_FUNCTION(imlib_load_font) { - zval **fontname; + char *fontname; + int fontname_len; PHP_Imlib_Font fn; int argc; - argc=ZEND_NUM_ARGS(); - if (argc != 1 || zend_get_parameters_ex(argc, &fontname) == FAILURE) { - WRONG_PARAM_COUNT; - } + if (zend_parse_parameters(1 TSRMLS_CC, "s", &fontname, &fontname_len) == FAILURE) return; fn=(PHP_Imlib_Font)emalloc(sizeof(PHP_Imlib_Font_struct)); if (!fn) RETURN_FALSE; - convert_to_string_ex(fontname); - - fn->font = imlib_load_font(Z_STRVAL_PP(fontname)); + fn->font = imlib_load_font(fontname); if (!fn->font) { efree(fn); - php_error(E_WARNING, "%s - Could not load font.", Z_STRVAL_PP(fontname)); + php_error(E_WARNING, "%s - Could not load font.", fontname); RETURN_FALSE; } @@ -2041,25 +1909,24 @@ PHP_FUNCTION(imlib_load_font) Load a file into an image, optionally fetch an error parameter */ PHP_FUNCTION(imlib_load_image) { - zval **img, **err; + zval **err; int argc; Imlib_Image im; Imlib_Load_Error im_err; FILE* f; char* filename; + char* img; + int img_len; argc = ZEND_NUM_ARGS(); - if (argc < 1 || argc > 2 || zend_get_parameters_ex(argc, &img, &err) == FAILURE) { - WRONG_PARAM_COUNT; - } + if (zend_parse_parameters(argc TSRMLS_CC, "s|Z", &img, &img_len, &err) == FAILURE) return; - convert_to_string_ex(img); if (argc == 2) { zval_dtor(*err); ZVAL_LONG(*err,0); } - f = php_stream_open_wrapper_as_file(Z_STRVAL_PP(img), "rb", IGNORE_PATH | ENFORCE_SAFE_MODE | REPORT_ERRORS, &filename); + 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); @@ -2073,7 +1940,7 @@ PHP_FUNCTION(imlib_load_image) ZVAL_LONG(*err,im_err); } _php_handle_imlib_error(INTERNAL_FUNCTION_PARAM_PASSTHRU, - im_err,Z_STRVAL_PP(img)); + im_err,img); RETURN_FALSE; } else @@ -2088,20 +1955,13 @@ PHP_FUNCTION(imlib_load_image) Add a point to a given polygon */ PHP_FUNCTION(imlib_polygon_add_point) { - zval **polygon, **px, **py; - int x,y; + zval *polygon; + long x,y; ImlibPolygon poly; - if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &polygon, &px, &py) == FAILURE) { - WRONG_PARAM_COUNT; - } - - ZEND_FETCH_RESOURCE(poly, ImlibPolygon, polygon, -1, "Imlib Polygon", le_imlib_poly); + if (zend_parse_parameters(3 TSRMLS_CC, "rll", &polygon, &x, &y) == FAILURE) return; - convert_to_long_ex(px); - convert_to_long_ex(py); - x = Z_LVAL_PP(px); - y = Z_LVAL_PP(py); + ZEND_FETCH_RESOURCE(poly, ImlibPolygon, &polygon, -1, "Imlib Polygon", le_imlib_poly); imlib_polygon_add_point(poly,x,y); } @@ -2112,20 +1972,14 @@ PHP_FUNCTION(imlib_polygon_add_point) Check if a give point is inside a polygon */ PHP_FUNCTION(imlib_polygon_contains_point) { - zval **polygon, **px, **py; - int x,y,ret; + zval *polygon; + long x,y; + int ret; ImlibPolygon poly; - if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &polygon, &px, &py) == FAILURE) { - WRONG_PARAM_COUNT; - } + 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); - - convert_to_long_ex(px); - convert_to_long_ex(py); - x = Z_LVAL_PP(px); - y = Z_LVAL_PP(py); + ZEND_FETCH_RESOURCE(poly, ImlibPolygon, &polygon, -1, "Imlib Polygon", le_imlib_poly); ret = imlib_polygon_contains_point(poly,x,y); @@ -2145,15 +1999,13 @@ PHP_FUNCTION(imlib_polygon_contains_point) Free a polygon */ PHP_FUNCTION(imlib_polygon_free) { - zval **polygon; + zval *polygon; ImlibPolygon poly; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &polygon) == FAILURE) { - WRONG_PARAM_COUNT; - } + 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)); + ZEND_FETCH_RESOURCE(poly, ImlibPolygon, &polygon, -1, "Imlib Polygon", le_imlib_poly); + zend_list_delete(Z_LVAL_PP(&polygon)); } /* }}} */ @@ -2162,15 +2014,14 @@ PHP_FUNCTION(imlib_polygon_free) Get the bounding coords of a polygon */ PHP_FUNCTION(imlib_polygon_get_bounds) { - zval **polygon, **px1, **py1, **px2, **py2; + zval *polygon; + zval **px1, **py1, **px2, **py2; int x1,y1,x2,y2; ImlibPolygon poly; - if (ZEND_NUM_ARGS() != 5 || zend_get_parameters_ex(5, &polygon, &px1, &py1, &px2, &py2) == FAILURE) { - WRONG_PARAM_COUNT; - } + 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); + ZEND_FETCH_RESOURCE(poly, ImlibPolygon, &polygon, -1, "Imlib Polygon", le_imlib_poly); zval_dtor(*px1); zval_dtor(*py1); @@ -2207,21 +2058,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, **name, **quality, **err; + zval *img, **err; + char* name; + int name_len; Imlib_Image im; Imlib_Load_Error im_err; - int argc, q; + int argc; + long q; char* filename; FILE* f; argc = ZEND_NUM_ARGS(); - if (argc < 2 || argc > 4 || zend_get_parameters_ex(argc, &img, &name, &err, &quality) == FAILURE) { - WRONG_PARAM_COUNT; - } + 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); + ZEND_FETCH_RESOURCE(im, Imlib_Image, &img, -1, "Imlib Image", le_imlib_img); - convert_to_string_ex(name); imlib_context_set_image(im); if (argc > 2) { @@ -2231,12 +2082,10 @@ PHP_FUNCTION(imlib_save_image) if (argc > 3) { - convert_to_long_ex(quality); - q = Z_LVAL_PP(quality); imlib_image_attach_data_value("quality",NULL,q,NULL); } - f = php_stream_open_wrapper_as_file(Z_STRVAL_PP(name), "wb", IGNORE_PATH | ENFORCE_SAFE_MODE | REPORT_ERRORS, &filename); + 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); @@ -2251,7 +2100,7 @@ PHP_FUNCTION(imlib_save_image) ZVAL_LONG(*err,im_err); } _php_handle_imlib_error(INTERNAL_FUNCTION_PARAM_PASSTHRU, - im_err,Z_STRVAL_PP(name)); + im_err,name); RETURN_FALSE; } @@ -2264,29 +2113,17 @@ PHP_FUNCTION(imlib_save_image) Draw a text string using a font onto an image */ PHP_FUNCTION(imlib_text_draw) { - zval **img, **font, **tx, **ty, **textstr, **tdir, **tr, **tg, **tb, **ta; + zval *img, *font; Imlib_Image im; PHP_Imlib_Font fn; char *text; - int x,y,dir,r,g,b,a; - - if (ZEND_NUM_ARGS() != 10 || zend_get_parameters_ex(10, &img, &font, &tx, &ty, &textstr, &tdir, &tr, &tg, &tb, &ta) == FAILURE) { - WRONG_PARAM_COUNT; - } - - 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); + int text_len; + long x,y,dir,r,g,b,a; - convert_to_long_ex(tx); - convert_to_long_ex(ty); - convert_to_long_ex(tdir); + if (zend_parse_parameters(10 TSRMLS_CC, "rrllslllll", &img, &font, &x, &y, &text, &text_len, &dir, &r, &g, &b, &a) == FAILURE) return; - convert_to_string_ex(textstr); - x = Z_LVAL_PP(tx); - y = Z_LVAL_PP(ty); - dir = Z_LVAL_PP(tdir); - text = Z_STRVAL_PP(textstr); - _php_convert_four_longs(tr,tg,tb,ta,&r,&g,&b,&a); + 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_context_set_image(im); imlib_context_set_color(r,g,b,a); @@ -2310,13 +2147,8 @@ PHP_FUNCTION(imlib_get_cache_size) Set the size of image cache */ PHP_FUNCTION(imlib_set_cache_size) { - zval** tsize; - int size; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &tsize) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long_ex(tsize); - size = Z_LVAL_PP(tsize); + long size; + if (zend_parse_parameters(1 TSRMLS_CC, "l", &size) == FAILURE) return; _php_imlib_set_cache_size(size TSRMLS_CC); RETURN_TRUE; } @@ -2326,18 +2158,15 @@ PHP_FUNCTION(imlib_set_cache_size) Apply external filter to an image */ PHP_FUNCTION(imlib_apply_filter) { - zval **img, **tfilter_name, **tparams; + zval *img, *tparams; Imlib_Image im; struct php_imlib_filter* filter; char* filter_name; + int filter_name_len; HashTable* arg_ht; - if (ZEND_NUM_ARGS() < 2 || ZEND_NUM_ARGS() > 3 || zend_get_parameters_ex(3, &img, &tfilter_name, &tparams) == FAILURE) { - WRONG_PARAM_COUNT; - } + 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); - convert_to_string_ex(tfilter_name); - filter_name = Z_STRVAL_PP(tfilter_name); + ZEND_FETCH_RESOURCE(im, Imlib_Image, &img, -1, "Imlib Image", le_imlib_img); filter = _php_imlib_find_filter(filter_name TSRMLS_CC); @@ -2346,8 +2175,7 @@ PHP_FUNCTION(imlib_apply_filter) RETURN_FALSE; } - convert_to_array_ex(tparams); - arg_ht=HASH_OF(*tparams); + arg_ht=HASH_OF(tparams); /* ID_PRINTF("Image before: %p",im); */ if (filter->exec(im, filter_name, arg_ht)==FAILURE) @@ -2382,15 +2210,13 @@ PHP_FUNCTION(imlib_create_filter) Free a filter */ PHP_FUNCTION(imlib_free_filter) { - zval **filter; + zval *filter; Imlib_Filter fil; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &filter) == FAILURE) { - WRONG_PARAM_COUNT; - } + if (zend_parse_parameters(1 TSRMLS_CC, "r", &filter) == FAILURE) return; - ZEND_FETCH_RESOURCE(fil, Imlib_Filter, filter, -1, "Imlib Filter", le_imlib_filter); - zend_list_delete(Z_LVAL_PP(filter)); + ZEND_FETCH_RESOURCE(fil, Imlib_Filter, &filter, -1, "Imlib Filter", le_imlib_filter); + zend_list_delete(Z_LVAL_PP(&filter)); } /* }}} */ @@ -2398,16 +2224,14 @@ PHP_FUNCTION(imlib_free_filter) Apply filter to an image */ PHP_FUNCTION(imlib_image_filter) { - zval **filter, **img; + zval *filter, *img; Imlib_Filter fil; Imlib_Image im; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &img, &filter) == FAILURE) { - WRONG_PARAM_COUNT; - } - ZEND_FETCH_RESOURCE(im, Imlib_Image, img, -1, "Imlib Image", le_imlib_img); - ZEND_FETCH_RESOURCE(fil, Imlib_Filter, filter, -1, "Imlib Filter", le_imlib_filter); + if (zend_parse_parameters(2 TSRMLS_CC, "rr", &img, &filter) == FAILURE) return; + + ZEND_FETCH_RESOURCE(im, Imlib_Image, &img, -1, "Imlib Image", le_imlib_img); + ZEND_FETCH_RESOURCE(fil, Imlib_Filter, &filter, -1, "Imlib Filter", le_imlib_filter); imlib_context_set_image(im); imlib_context_set_filter(fil); @@ -2417,31 +2241,15 @@ PHP_FUNCTION(imlib_image_filter) static void _php_imlib_filter_set(INTERNAL_FUNCTION_PARAMETERS, int type) { - zval **filter, **txoff, **tyoff, **ta, **tr, **tg, **tb; - int argc,xoff,yoff,a,r,g,b; + zval *filter; + int argc; + long xoff,yoff,a,r,g,b; Imlib_Filter fil; - argc=ZEND_NUM_ARGS(); - if (argc!=7 || zend_get_parameters_ex(argc, &filter, &txoff, &tyoff, &ta, &tr, &tg, &tb) == FAILURE) { - WRONG_PARAM_COUNT; - } + if (zend_parse_parameters(7 TSRMLS_CC, "rllllll", &filter, &xoff, &yoff, &a, &r, &g, &b) == FAILURE) return; - ZEND_FETCH_RESOURCE(fil, Imlib_Filter, filter, -1, "Imlib Filter", le_imlib_filter); + ZEND_FETCH_RESOURCE(fil, Imlib_Filter, &filter, -1, "Imlib Filter", le_imlib_filter); - convert_to_long_ex(txoff); - convert_to_long_ex(tyoff); - convert_to_long_ex(ta); - convert_to_long_ex(tr); - convert_to_long_ex(tg); - convert_to_long_ex(tb); - - r=Z_LVAL_PP(tr); - g=Z_LVAL_PP(tg); - b=Z_LVAL_PP(tb); - a=Z_LVAL_PP(ta); - xoff=Z_LVAL_PP(txoff); - yoff=Z_LVAL_PP(tyoff); - imlib_context_set_filter(fil); if (type==0) imlib_filter_set(xoff,yoff,a,r,g,b); @@ -2497,22 +2305,16 @@ PHP_FUNCTION(imlib_filter_set_alpha) Set filter constants */ PHP_FUNCTION(imlib_filter_constants) { - zval **filter, **a, **r, **g, **b; + zval *filter; + long a, r, g, b; Imlib_Filter fil; - if (ZEND_NUM_ARGS()!=5 || zend_get_parameters_ex(5, &filter, &a, &r, &g, &b) == FAILURE) { - WRONG_PARAM_COUNT; - } + if (zend_parse_parameters(5 TSRMLS_CC, "rllll", &filter, &a, &r, &g, &b) == FAILURE) return; - ZEND_FETCH_RESOURCE(fil, Imlib_Filter, filter, -1, "Imlib Filter", le_imlib_filter); + ZEND_FETCH_RESOURCE(fil, Imlib_Filter, &filter, -1, "Imlib Filter", le_imlib_filter); - convert_to_long_ex(a); - convert_to_long_ex(r); - convert_to_long_ex(g); - convert_to_long_ex(b); - imlib_context_set_filter(fil); - imlib_filter_constants(Z_LVAL_PP(a),Z_LVAL_PP(r),Z_LVAL_PP(g),Z_LVAL_PP(b)); + imlib_filter_constants(a,r,g,b); } /* }}} */ @@ -2520,22 +2322,16 @@ PHP_FUNCTION(imlib_filter_constants) Set filter divisors */ PHP_FUNCTION(imlib_filter_divisors) { - zval **filter, **a, **r, **g, **b; + zval *filter; + long a, r, g, b; Imlib_Filter fil; - if (ZEND_NUM_ARGS()!=5 || zend_get_parameters_ex(5, &filter, &a, &r, &g, &b) == FAILURE) { - WRONG_PARAM_COUNT; - } + if (zend_parse_parameters(5 TSRMLS_CC, "rllll", &filter, &a, &r, &g, &b) == FAILURE) return; - ZEND_FETCH_RESOURCE(fil, Imlib_Filter, filter, -1, "Imlib Filter", le_imlib_filter); + ZEND_FETCH_RESOURCE(fil, Imlib_Filter, &filter, -1, "Imlib Filter", le_imlib_filter); - convert_to_long_ex(a); - convert_to_long_ex(r); - convert_to_long_ex(g); - convert_to_long_ex(b); - imlib_context_set_filter(fil); - imlib_filter_divisors(Z_LVAL_PP(a),Z_LVAL_PP(r),Z_LVAL_PP(g),Z_LVAL_PP(b)); + imlib_filter_divisors(a,r,g,b); } /* }}} */ @@ -2544,18 +2340,16 @@ PHP_FUNCTION(imlib_filter_divisors) Adjust color modifier gamma */ PHP_FUNCTION(imlib_modify_color_modifier_gamma) { - zval **gamma, **color_modifier; + double gamma; + zval *color_modifier; PHP_Imlib_Color_Modifier cm; - if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(2, &color_modifier, &gamma) == FAILURE) { - WRONG_PARAM_COUNT; - } + if (zend_parse_parameters(2 TSRMLS_CC, "rd", &color_modifier, &gamma) == FAILURE) return; - ZEND_FETCH_RESOURCE(cm, PHP_Imlib_Color_Modifier, color_modifier, -1, "Imlib Color Modifier", le_imlib_cm); + ZEND_FETCH_RESOURCE(cm, PHP_Imlib_Color_Modifier, &color_modifier, -1, "Imlib Color Modifier", le_imlib_cm); if (cm->modified) _php_imlib_color_modifier_synch(cm); - convert_to_double_ex(gamma); imlib_context_set_color_modifier(cm->cm); - imlib_modify_color_modifier_gamma(Z_DVAL_PP(gamma)); + imlib_modify_color_modifier_gamma(gamma); imlib_context_set_color_modifier(NULL); cm->valid=0; } @@ -2566,18 +2360,16 @@ PHP_FUNCTION(imlib_modify_color_modifier_gamma) Adjust color modifier brightness */ PHP_FUNCTION(imlib_modify_color_modifier_brightness) { - zval **brightness, **color_modifier; + double brightness; + zval *color_modifier; PHP_Imlib_Color_Modifier cm; - if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(2, &color_modifier, &brightness) == FAILURE) { - WRONG_PARAM_COUNT; - } + if (zend_parse_parameters(2 TSRMLS_CC, "rd", &color_modifier, &brightness) == FAILURE) return; - ZEND_FETCH_RESOURCE(cm, Imlib_Color_Modifier, color_modifier, -1, "Imlib Color Modifier", le_imlib_cm); + ZEND_FETCH_RESOURCE(cm, Imlib_Color_Modifier, &color_modifier, -1, "Imlib Color Modifier", le_imlib_cm); if (cm->modified) _php_imlib_color_modifier_synch(cm); - convert_to_double_ex(brightness); imlib_context_set_color_modifier(cm->cm); - imlib_modify_color_modifier_brightness(Z_DVAL_PP(brightness)); + imlib_modify_color_modifier_brightness(brightness); imlib_context_set_color_modifier(NULL); cm->valid=0; } @@ -2588,18 +2380,16 @@ PHP_FUNCTION(imlib_modify_color_modifier_brightness) Adjust color modifier contrast */ PHP_FUNCTION(imlib_modify_color_modifier_contrast) { - zval **contrast, **color_modifier; + double contrast; + zval *color_modifier; PHP_Imlib_Color_Modifier cm; - if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(2, &color_modifier, &contrast) == FAILURE) { - WRONG_PARAM_COUNT; - } + if (zend_parse_parameters(2 TSRMLS_CC, "rd", &color_modifier, &contrast) == FAILURE) return; - ZEND_FETCH_RESOURCE(cm, PHP_Imlib_Color_Modifier, color_modifier, -1, "Imlib Color Modifier", le_imlib_cm); + ZEND_FETCH_RESOURCE(cm, PHP_Imlib_Color_Modifier, &color_modifier, -1, "Imlib Color Modifier", le_imlib_cm); if (cm->modified) _php_imlib_color_modifier_synch(cm); - convert_to_double_ex(contrast); imlib_context_set_color_modifier(cm->cm); - imlib_modify_color_modifier_contrast(Z_DVAL_PP(contrast)); + imlib_modify_color_modifier_contrast(contrast); imlib_context_set_color_modifier(NULL); cm->valid=0; } @@ -2610,14 +2400,12 @@ PHP_FUNCTION(imlib_modify_color_modifier_contrast) Reset color modifier to default (one-to-one) mapping */ PHP_FUNCTION(imlib_reset_color_modifier) { - zval **color_modifier; + zval *color_modifier; PHP_Imlib_Color_Modifier cm; - if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &color_modifier) == FAILURE) { - WRONG_PARAM_COUNT; - } + if (zend_parse_parameters(1 TSRMLS_CC, "r", &color_modifier) == FAILURE) return; - ZEND_FETCH_RESOURCE(cm, PHP_Imlib_Color_Modifier, color_modifier, -1, "Imlib Color Modifier", le_imlib_cm); + ZEND_FETCH_RESOURCE(cm, PHP_Imlib_Color_Modifier, &color_modifier, -1, "Imlib Color Modifier", le_imlib_cm); imlib_context_set_color_modifier(cm->cm); imlib_reset_color_modifier(); imlib_context_set_color_modifier(NULL); @@ -2630,18 +2418,17 @@ PHP_FUNCTION(imlib_reset_color_modifier) Apply color modifier to an image or its part */ PHP_FUNCTION(imlib_apply_color_modifier) { - zval **color_modifier, **image, **x, **y, **width, **height; + zval *color_modifier, *image; + long x, y, width, height; PHP_Imlib_Color_Modifier cm; Imlib_Image img; int argc; argc=ZEND_NUM_ARGS(); - if ((argc!=2 && argc!=6) || zend_get_parameters_ex(argc, &image, &color_modifier, &x, &y, &width, &height) == FAILURE) { - WRONG_PARAM_COUNT; - } + if (zend_parse_parameters(argc TSRMLS_CC, "rr|llll", &image, &color_modifier, &x, &y, &width, &height) == FAILURE) return; - ZEND_FETCH_RESOURCE(cm, PHP_Imlib_Color_Modifier, color_modifier, -1, "Imlib Color Modifier", le_imlib_cm); - ZEND_FETCH_RESOURCE(img, Imlib_Image, image, -1, "Imlib Image", le_imlib_img); + ZEND_FETCH_RESOURCE(cm, PHP_Imlib_Color_Modifier, &color_modifier, -1, "Imlib Color Modifier", le_imlib_cm); + ZEND_FETCH_RESOURCE(img, Imlib_Image, &image, -1, "Imlib Image", le_imlib_img); if (cm->modified) _php_imlib_color_modifier_synch(cm); imlib_context_set_image(img); @@ -2649,11 +2436,7 @@ PHP_FUNCTION(imlib_apply_color_modifier) if (argc==2) { imlib_apply_color_modifier(); } else { - convert_to_long_ex(x); - convert_to_long_ex(y); - convert_to_long_ex(width); - convert_to_long_ex(height); - imlib_apply_color_modifier_to_rectangle(Z_LVAL_PP(x),Z_LVAL_PP(y),Z_LVAL_PP(width),Z_LVAL_PP(height)); + imlib_apply_color_modifier_to_rectangle(x,y,width,height); } imlib_context_set_color_modifier(NULL); } @@ -2664,26 +2447,14 @@ PHP_FUNCTION(imlib_apply_color_modifier) PHP_FUNCTION(imlib_set_color_modifier) { - zval **color_modifier, **tindex, **tvalue, **tchannels; - unsigned char index, value, channels; + zval *color_modifier; + long index, value, channels = 15; PHP_Imlib_Color_Modifier cm; int argc,i=0; argc=ZEND_NUM_ARGS(); - if (argc < 3 || argc > 4 || zend_get_parameters_ex(argc, &color_modifier, &tindex, &tvalue, &tchannels) == FAILURE) { - WRONG_PARAM_COUNT; - } - ZEND_FETCH_RESOURCE(cm, PHP_Imlib_Color_Modifier, color_modifier, -1, "Imlib Color Modifier", le_imlib_cm); - convert_to_long_ex(tindex); - convert_to_long_ex(tvalue); - index=(unsigned char)Z_LVAL_PP(tindex); - value=(unsigned char)Z_LVAL_PP(tvalue); - if (argc==4) { - convert_to_long_ex(tchannels); - channels=(unsigned char)Z_LVAL_PP(tchannels); - } else { - channels=15; - }; + if (zend_parse_parameters(argc TSRMLS_CC, "rll|l", &color_modifier, &index, &value, &channels) == FAILURE) return; + ZEND_FETCH_RESOURCE(cm, PHP_Imlib_Color_Modifier, &color_modifier, -1, "Imlib Color Modifier", le_imlib_cm); if (!cm->valid) _php_imlib_color_modifier_synch(cm); while (i<4) { if (channels&1) { @@ -2702,16 +2473,13 @@ PHP_FUNCTION(imlib_set_color_modifier) PHP_FUNCTION(imlib_get_color_modifier) { - zval **color_modifier, **tindex, **tred, **tgreen, **tblue, **talpha; - unsigned char index; + zval *color_modifier; + zval **tred, **tgreen, **tblue, **talpha; + long index; PHP_Imlib_Color_Modifier cm; - if (ZEND_NUM_ARGS() != 6 || zend_get_parameters_ex(6, &color_modifier, &tindex, &tred, &tgreen, &tblue, &talpha) == FAILURE) { - WRONG_PARAM_COUNT; - } - ZEND_FETCH_RESOURCE(cm, PHP_Imlib_Color_Modifier, color_modifier, -1, "Imlib Color Modifier", le_imlib_cm); - convert_to_long_ex(tindex); - index=(unsigned char)Z_LVAL_PP(tindex); + if (zend_parse_parameters(6 TSRMLS_CC, "rlZZZZ", &color_modifier, &index, &tred, &tgreen, &tblue, &talpha) == FAILURE) return; + ZEND_FETCH_RESOURCE(cm, PHP_Imlib_Color_Modifier, &color_modifier, -1, "Imlib Color Modifier", le_imlib_cm); if (!cm->valid) _php_imlib_color_modifier_synch(cm); zval_dtor(*tred); @@ -2736,67 +2504,31 @@ PHP_FUNCTION(imlib_pstext) { #if HAVE_LIBT1 - zval **img, **str, **fnt, **sz, **fg, **px, **py, **tr, **tg, **tb, **ta, **aas, **wd, **ang, **sp; - int i, j, x, y, argc; - unsigned long r, g, b, a; + zval *img, *fnt; + int i, j, argc; + long x, y, sz, r, g, b, a, space = 0, width = 0, aa_steps = 4; unsigned long color; - int space; int *f_ind; int h_lines, v_lines, c_ind; - int aa[16], aa_steps; - int width, amount_kern, add_width; - double angle, extend; + int aa[16]; + int amount_kern, add_width; + double angle = 0, extend; unsigned long aa_greys[17]; Imlib_Image bg_img; GLYPH *str_img; T1_OUTLINE *char_path, *str_path; T1_TMATRIX *transform = NULL; - char *_str; + char *str; + int str_len; argc=ZEND_NUM_ARGS(); - if (argc<10 || argc>14 || zend_get_parameters_ex(argc, &img, &str, &fnt, &sz, &px, &py, &tr, &tg, &tb, &ta, &sp, &wd, &ang, &aas) == FAILURE) { - WRONG_PARAM_COUNT; - } + if (zend_parse_parameters(argc TSRMLS_CC, "rsrlllllll|lldl", &img, &str, &str_len, &fnt, &sz, &x, &y, &r, &g, &b, &a, &space, &width, &angle, &aa_steps) == FAILURE) return; - space = 0; - aa_steps = 4; - width = 0; - angle = 0; - - switch (argc) { - case 14: - convert_to_long_ex(aas); - aa_steps = Z_LVAL_PP(aas); - case 13: - convert_to_double_ex(ang); - angle = Z_DVAL_PP(ang); - case 12: - convert_to_long_ex(wd); - width = Z_LVAL_PP(wd); - case 11: - convert_to_long_ex(sp); - space = Z_LVAL_PP(sp); - case 10: - convert_to_string_ex(str); - convert_to_long_ex(sz); - convert_to_long_ex(px); - convert_to_long_ex(py); - convert_to_long_ex(tr); - convert_to_long_ex(tg); - convert_to_long_ex(tb); - convert_to_long_ex(ta); - x = Z_LVAL_PP(px); - y = Z_LVAL_PP(py); - r = Z_LVAL_PP(tr); - g = Z_LVAL_PP(tg); - b = Z_LVAL_PP(tb); - a = Z_LVAL_PP(ta); - color=(r<<16)|(g<<8)|b; - } + color=(r<<16)|(g<<8)|b; - ZEND_FETCH_RESOURCE(bg_img, Imlib_Image, img, -1, "Imlib Image", le_imlib_img); - ZEND_FETCH_RESOURCE(f_ind, int *, fnt, -1, "Type 1 font", le_ps_font); + ZEND_FETCH_RESOURCE(bg_img, Imlib_Image, &img, -1, "Imlib Image", le_imlib_img); + ZEND_FETCH_RESOURCE(f_ind, int *, &fnt, -1, "Type 1 font", le_ps_font); T1_AASetBitsPerPixel(32); @@ -2825,26 +2557,24 @@ PHP_FUNCTION(imlib_pstext) transform = T1_RotateMatrix(NULL, angle); } - _str = Z_STRVAL_PP(str); - if (width) { extend = T1_GetExtend(*f_ind); - str_path = T1_GetCharOutline(*f_ind, _str[0], Z_LVAL_PP(sz), transform); + str_path = T1_GetCharOutline(*f_ind, str[0], sz, transform); - for (i = 1; i < Z_STRLEN_PP(str); i++) { - amount_kern = (int) T1_GetKerning(*f_ind, _str[i-1], _str[i]); - amount_kern += _str[i-1] == ' ' ? space : 0; + for (i = 1; i < str_len; i++) { + amount_kern = (int) T1_GetKerning(*f_ind, str[i-1], str[i]); + amount_kern += str[i-1] == ' ' ? space : 0; add_width = (int) (amount_kern+width)/extend; - char_path = T1_GetMoveOutline(*f_ind, add_width, 0, 0, Z_LVAL_PP(sz), transform); + char_path = T1_GetMoveOutline(*f_ind, add_width, 0, 0, sz, transform); str_path = T1_ConcatOutlines(str_path, char_path); - char_path = T1_GetCharOutline(*f_ind, _str[i], Z_LVAL_PP(sz), transform); + char_path = T1_GetCharOutline(*f_ind, str[i], sz, transform); str_path = T1_ConcatOutlines(str_path, char_path); } str_img = T1_AAFillOutline(str_path, 0); } else { - str_img = T1_AASetString(*f_ind, _str, Z_STRLEN_PP(str), space, T1_KERNING, Z_LVAL_PP(sz), transform); + str_img = T1_AASetString(*f_ind, str, str_len, space, T1_KERNING, sz, transform); } if (T1_errno) { @@ -2897,18 +2627,15 @@ PHP_FUNCTION(imlib_pstext) PHP_FUNCTION(imlib_psloadfont) { #if HAVE_LIBT1 - zval **file; + char* file; + int file_len; int f_ind, *font; char* filename; FILE* f; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &file) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } + if (zend_parse_parameters(1 TSRMLS_CC, "s", &file, &file_len) == FAILURE) return; - convert_to_string_ex(file); - - f = php_stream_open_wrapper_as_file(Z_STRVAL_PP(file), "rb", IGNORE_PATH | ENFORCE_SAFE_MODE | REPORT_ERRORS, &filename); + f = php_stream_open_wrapper_as_file(file, "rb", IGNORE_PATH | ENFORCE_SAFE_MODE | REPORT_ERRORS, &filename); if (f == NULL) RETURN_FALSE; f_ind = T1_AddFont(filename); @@ -2953,16 +2680,14 @@ PHP_FUNCTION(imlib_psloadfont) PHP_FUNCTION(imlib_psfreefont) { #if HAVE_LIBT1 - zval **fnt; + zval *fnt; int *f_ind; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &fnt) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } + if (zend_parse_parameters(1 TSRMLS_CC, "r", &fnt) == FAILURE) return; - ZEND_FETCH_RESOURCE(f_ind, int *, fnt, -1, "Type 1 font", le_ps_font); + ZEND_FETCH_RESOURCE(f_ind, int *, &fnt, -1, "Type 1 font", le_ps_font); - zend_list_delete(Z_LVAL_PP(fnt)); + zend_list_delete(Z_LVAL_PP(&fnt)); RETURN_TRUE; #else php_error(E_WARNING, "imlib_psfreefont: No T1lib support in this PHP build"); @@ -2976,21 +2701,19 @@ PHP_FUNCTION(imlib_psfreefont) PHP_FUNCTION(imlib_psencodefont) { #if HAVE_LIBT1 - zval **fnt, **enc; + zval *fnt; + char *enc; + int enc_len; char **enc_vector; int *f_ind; char* filename; FILE* f; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &fnt, &enc) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } + if (zend_parse_parameters(2 TSRMLS_CC, "rs", &fnt, &enc, &enc_len) == FAILURE) return; - convert_to_string_ex(enc); + ZEND_FETCH_RESOURCE(f_ind, int *, &fnt, -1, "Type 1 font", le_ps_font); - ZEND_FETCH_RESOURCE(f_ind, int *, fnt, -1, "Type 1 font", le_ps_font); - - f = php_stream_open_wrapper_as_file(Z_STRVAL_PP(enc), "rb", IGNORE_PATH | ENFORCE_SAFE_MODE | REPORT_ERRORS, &filename); + f = php_stream_open_wrapper_as_file(enc, "rb", IGNORE_PATH | ENFORCE_SAFE_MODE | REPORT_ERRORS, &filename); if (f == NULL) RETURN_FALSE; enc_vector = T1_LoadEncoding(filename); @@ -2999,7 +2722,7 @@ PHP_FUNCTION(imlib_psencodefont) efree(filename); if (enc_vector == NULL) { - php_error(E_WARNING, "Couldn't load encoding vector from %s", Z_STRVAL_PP(enc)); + php_error(E_WARNING, "Couldn't load encoding vector from %s", enc); RETURN_FALSE; } @@ -3023,18 +2746,15 @@ PHP_FUNCTION(imlib_psencodefont) PHP_FUNCTION(imlib_psextendfont) { #if HAVE_LIBT1 - zval **fnt, **ext; + zval *fnt; + double ext; int *f_ind; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &fnt, &ext) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } + if (zend_parse_parameters(2 TSRMLS_CC, "rd", &fnt, &ext) == FAILURE) return; - convert_to_double_ex(ext); + ZEND_FETCH_RESOURCE(f_ind, int *, &fnt, -1, "Type 1 font", le_ps_font); - ZEND_FETCH_RESOURCE(f_ind, int *, fnt, -1, "Type 1 font", le_ps_font); - - if (T1_ExtendFont(*f_ind, Z_DVAL_PP(ext)) != 0) RETURN_FALSE; + if (T1_ExtendFont(*f_ind, ext) != 0) RETURN_FALSE; RETURN_TRUE; #else @@ -3049,18 +2769,15 @@ PHP_FUNCTION(imlib_psextendfont) PHP_FUNCTION(imlib_psslantfont) { #if HAVE_LIBT1 - zval **fnt, **slt; + zval *fnt; + double slt; int *f_ind; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &fnt, &slt) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } - - convert_to_double_ex(slt); + if (zend_parse_parameters(2 TSRMLS_CC, "rd", &fnt, &slt) == FAILURE) return; - ZEND_FETCH_RESOURCE(f_ind, int *, fnt, -1, "Type 1 font", le_ps_font); + ZEND_FETCH_RESOURCE(f_ind, int *, &fnt, -1, "Type 1 font", le_ps_font); - if (T1_SlantFont(*f_ind, Z_DVAL_PP(slt)) != 0) RETURN_FALSE; + if (T1_SlantFont(*f_ind, slt) != 0) RETURN_FALSE; RETURN_TRUE; #else php_error(E_WARNING, "imlib_psslantfont: No T1lib support in this PHP build"); @@ -3069,49 +2786,30 @@ PHP_FUNCTION(imlib_psslantfont) } /* }}} */ -/* {{{ proto array imlib_psbbox(string text, int font, int size [, int space, int tightness, int angle]) +/* {{{ proto array imlib_psbbox(string text, int font, int size [, int space, int tightness, double angle]) Return the bounding box needed by a string if rasterized */ PHP_FUNCTION(imlib_psbbox) { #if HAVE_LIBT1 - zval **str, **fnt, **sz, **sp, **wd, **ang; - int i, space, add_width = 0, char_width, amount_kern; + zval *fnt; + char* str; + int str_len; + long sz, space = 0, add_width = 0; + int i, char_width, amount_kern; int cur_x, cur_y, dx, dy; int x1, y1, x2, y2, x3, y3, x4, y4; int *f_ind; int per_char = 0; - double angle, sin_a = 0, cos_a = 0; + double angle = 0, sin_a = 0, cos_a = 0; BBox char_bbox, str_bbox = {0, 0, 0, 0}; - switch(ZEND_NUM_ARGS()) { - case 3: - if (zend_get_parameters_ex(3, &str, &fnt, &sz) == FAILURE) { - RETURN_FALSE; - } - space = 0; - break; - case 6: - if (zend_get_parameters_ex(6, &str, &fnt, &sz, &sp, &wd, &ang) == FAILURE) { - RETURN_FALSE; - } - convert_to_long_ex(sp); - convert_to_long_ex(wd); - convert_to_double_ex(ang); - space = Z_LVAL_PP(sp); - add_width = Z_LVAL_PP(wd); - angle = Z_DVAL_PP(ang) * M_PI / 180; - sin_a = sin(angle); - cos_a = cos(angle); - per_char = add_width || angle ? 1 : 0; - break; - default: - ZEND_WRONG_PARAM_COUNT(); - } - - ZEND_FETCH_RESOURCE(f_ind, int *, fnt, -1, "Type 1 font", le_ps_font); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "srl|lll", &str, &str_len, &fnt, &sz, &space, &add_width, &angle) == FAILURE) return; + angle = angle * M_PI / 180; + sin_a = sin(angle); + cos_a = cos(angle); + per_char = add_width || angle ? 1 : 0; - convert_to_string_ex(str); - convert_to_long_ex(sz); + ZEND_FETCH_RESOURCE(f_ind, int *, &fnt, -1, "Type 1 font", le_ps_font); #define max(a, b) (a > b ? a : b) #define min(a, b) (a < b ? a : b) @@ -3122,15 +2820,15 @@ PHP_FUNCTION(imlib_psbbox) space += T1_GetCharWidth(*f_ind, ' '); cur_x = cur_y = 0; - for (i = 0; i < (*str)->value.str.len; i++) { - if ((*str)->value.str.val[i] == ' ') { + for (i = 0; i < str_len; i++) { + if (str[i] == ' ') { char_bbox.llx = char_bbox.lly = char_bbox.ury = 0; char_bbox.urx = char_width = space; } else { - char_bbox = T1_GetCharBBox(*f_ind, (*str)->value.str.val[i]); - char_width = T1_GetCharWidth(*f_ind, (*str)->value.str.val[i]); + char_bbox = T1_GetCharBBox(*f_ind, str[i]); + char_width = T1_GetCharWidth(*f_ind, str[i]); } - amount_kern = i ? T1_GetKerning(*f_ind, (*str)->value.str.val[i-1], (*str)->value.str.val[i]) : 0; + amount_kern = i ? T1_GetKerning(*f_ind, str[i-1], str[i]) : 0; /* Transfer character bounding box to right place */ x1 = new_x(char_bbox.llx, char_bbox.lly) + cur_x; @@ -3159,7 +2857,7 @@ PHP_FUNCTION(imlib_psbbox) } } else { - str_bbox = T1_GetStringBBox(*f_ind, (*str)->value.str.val, (*str)->value.str.len, space, T1_KERNING); + str_bbox = T1_GetStringBBox(*f_ind, str, str_len, space, T1_KERNING); } if (T1_errno) RETURN_FALSE; @@ -3169,10 +2867,10 @@ PHP_FUNCTION(imlib_psbbox) /* printf("%d %d %d %d\n", str_bbox.llx, str_bbox.lly, str_bbox.urx, str_bbox.ury); */ - add_next_index_long(return_value, (int) ceil(((double) str_bbox.llx)*(*sz)->value.lval/1000)); - add_next_index_long(return_value, (int) ceil(((double) str_bbox.lly)*(*sz)->value.lval/1000)); - add_next_index_long(return_value, (int) ceil(((double) str_bbox.urx)*(*sz)->value.lval/1000)); - add_next_index_long(return_value, (int) ceil(((double) str_bbox.ury)*(*sz)->value.lval/1000)); + add_next_index_lon