diff options
| author | Piotr Pawłow <pp@siedziba.pl> | 2016-09-23 04:45:49 +0200 |
|---|---|---|
| committer | Piotr Pawłow <pp@siedziba.pl> | 2016-09-23 04:45:49 +0200 |
| commit | 2ceffea399ce81e2c94e6ecbf45cb48b70ee83db (patch) | |
| tree | af35c74a0424dfc6878d6c942755450ecd2b08e4 /php_imlib.c | |
| parent | fdb92460ecd945a37b5a830e781ab9e33e7c5e46 (diff) | |
Port remaining functions.
Diffstat (limited to 'php_imlib.c')
| -rw-r--r-- | php_imlib.c | 464 |
1 files changed, 264 insertions, 200 deletions
diff --git a/php_imlib.c b/php_imlib.c index f007ee8..b55c504 100644 --- a/php_imlib.c +++ b/php_imlib.c @@ -942,7 +942,7 @@ static void _php_imlib_draw_something(INTERNAL_FUNCTION_PARAMETERS, void (*func) int argc; int cx, cy, cw, ch; zval *img, *dbox; - long x,y,w,h,r,g,b,a; + zend_long x,y,w,h,r,g,b,a; Imlib_Image im; argc = ZEND_NUM_ARGS(); @@ -950,7 +950,8 @@ static void _php_imlib_draw_something(INTERNAL_FUNCTION_PARAMETERS, void (*func) return; } - ZEND_FETCH_RESOURCE(im, Imlib_Image, &img, -1, le_imlib_img_name, le_imlib_img); + if ((im = (Imlib_Image)zend_fetch_resource(Z_RES_P(img), le_imlib_img_name, le_imlib_img)) == NULL) + RETURN_FALSE; imlib_context_set_image(im); imlib_context_set_color(r,g,b,a); @@ -977,7 +978,8 @@ static void _php_imlib_single_arg(INTERNAL_FUNCTION_PARAMETERS, void (*func)()) if (zend_parse_parameters(1 TSRMLS_CC, "r", &img) == FAILURE) return; - ZEND_FETCH_RESOURCE(im, Imlib_Image, &img, -1, le_imlib_img_name, le_imlib_img); + if ((im = (Imlib_Image)zend_fetch_resource(Z_RES_P(img), le_imlib_img_name, le_imlib_img)) == NULL) + RETURN_FALSE; imlib_context_set_image(im); (*func)(); @@ -996,12 +998,13 @@ static void _php_wrap_draw_line(int x1, int y1, int x2, int y2) PHP_FUNCTION(imlib_add_color_to_color_range) { zval *crange; - long x,r,g,b,a; + zend_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, le_imlib_cr_name, le_imlib_cr); + if ((range = (Imlib_Color_Range)zend_fetch_resource(Z_RES_P(crange), le_imlib_cr_name, le_imlib_cr)) == NULL) + RETURN_FALSE; imlib_context_set_color_range(range); imlib_context_set_color(r,g,b,a); @@ -1016,13 +1019,15 @@ PHP_FUNCTION(imlib_blend_image_onto_image) { zval *dstimg, *srcimg; Imlib_Image dst,src; - long sx,sy,sw,sh,dx,dy,dw,dh; - long calias, calpha, cblend, cdither; + zend_long sx,sy,sw,sh,dx,dy,dw,dh; + zend_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, le_imlib_img_name, le_imlib_img); - ZEND_FETCH_RESOURCE(dst, Imlib_Image, &dstimg, -1, le_imlib_img_name, le_imlib_img); + if ((src = (Imlib_Image)zend_fetch_resource(Z_RES_P(srcimg), le_imlib_img_name, le_imlib_img)) == NULL) + RETURN_FALSE; + if ((dst = (Imlib_Image)zend_fetch_resource(Z_RES_P(dstimg), le_imlib_img_name, le_imlib_img)) == NULL) + RETURN_FALSE; imlib_context_set_image(dst); imlib_context_set_anti_alias(calias); @@ -1043,12 +1048,13 @@ PHP_FUNCTION(imlib_clone_image) if (zend_parse_parameters(1 TSRMLS_CC, "r", &img) == FAILURE) return; - ZEND_FETCH_RESOURCE(src, Imlib_Image, &img, -1, le_imlib_img_name, le_imlib_img); + if ((src = (Imlib_Image)zend_fetch_resource(Z_RES_P(img), le_imlib_img_name, le_imlib_img)) == NULL) + RETURN_FALSE; imlib_context_set_image(src); dst = imlib_clone_image(); - if (dst) ZEND_REGISTER_RESOURCE(return_value, dst, le_imlib_img); + if (dst) RETURN_RES(zend_register_resource(dst, le_imlib_img)); } /* }}} */ @@ -1065,7 +1071,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) RETURN_RES(zend_register_resource(cr, le_imlib_cr)); } /* }}} */ @@ -1092,7 +1098,7 @@ PHP_FUNCTION(imlib_create_color_modifier) RETURN_FALSE; } - ZEND_REGISTER_RESOURCE(return_value, cm, le_imlib_cm); + RETURN_RES(zend_register_resource(cm, le_imlib_cm)); } /* }}} */ @@ -1101,17 +1107,18 @@ PHP_FUNCTION(imlib_create_color_modifier) PHP_FUNCTION(imlib_create_cropped_image) { zval *img; - long sx,sy,sw,sh; + zend_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, le_imlib_img_name, le_imlib_img); + if ((src = (Imlib_Image)zend_fetch_resource(Z_RES_P(img), le_imlib_img_name, le_imlib_img)) == NULL) + RETURN_FALSE; 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) RETURN_RES(zend_register_resource(dst, le_imlib_img)); } /* }}} */ @@ -1121,17 +1128,18 @@ PHP_FUNCTION(imlib_create_cropped_image) PHP_FUNCTION(imlib_create_cropped_scaled_image) { zval *img; - long sx,sy,sw,sh,dw,dh; + zend_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, le_imlib_img_name, le_imlib_img); + if ((src = (Imlib_Image)zend_fetch_resource(Z_RES_P(img), le_imlib_img_name, le_imlib_img)) == NULL) + RETURN_FALSE; 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) RETURN_RES(zend_register_resource(dst, le_imlib_img)); } /* }}} */ @@ -1141,7 +1149,7 @@ PHP_FUNCTION(imlib_create_cropped_scaled_image) PHP_FUNCTION(imlib_create_image) { Imlib_Image im; - long x,y; + zend_long x,y; if (zend_parse_parameters(2 TSRMLS_CC, "ll", &x, &y) == FAILURE) return; @@ -1151,7 +1159,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); + RETURN_RES(zend_register_resource(im, le_imlib_img)); } } /* }}} */ @@ -1172,14 +1180,15 @@ 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, le_imlib_img_name, le_imlib_img); + if ((src = (Imlib_Image)zend_fetch_resource(Z_RES_P(srcimg), le_imlib_img_name, le_imlib_img)) == NULL) + RETURN_FALSE; 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) RETURN_RES(zend_register_resource(dst, le_imlib_img)); } /* }}} */ @@ -1189,18 +1198,19 @@ PHP_FUNCTION(imlib_create_rotated_image) PHP_FUNCTION(imlib_create_scaled_image) { zval *img; - zval **dstw, **dsth; + 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; + if (zend_parse_parameters(3 TSRMLS_CC, "rzz", &img, &dstw, &dsth) == FAILURE) return; - ZEND_FETCH_RESOURCE(src, Imlib_Image, &img, -1, le_imlib_img_name, le_imlib_img); + if ((src = (Imlib_Image)zend_fetch_resource(Z_RES_P(img), le_imlib_img_name, le_imlib_img)) == NULL) + RETURN_FALSE; convert_to_long_ex(dstw); convert_to_long_ex(dsth); - dw = Z_LVAL_PP(dstw); - dh = Z_LVAL_PP(dsth); + dw = Z_LVAL_P(dstw); + dh = Z_LVAL_P(dsth); if (!dw && !dh) { RETURN_FALSE; @@ -1218,7 +1228,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) RETURN_RES(zend_register_resource(dst, le_imlib_img)); } /* }}} */ @@ -1228,22 +1238,23 @@ PHP_FUNCTION(imlib_create_scaled_image) PHP_FUNCTION(imlib_dump_image) { int argc, retval; - long q; + zend_long q; FILE *tmp; - char *tmpfile; - zval *img, **err; + zend_string *tmpfile; + zval *img, *err; Imlib_Image im; Imlib_Load_Error im_err; argc = ZEND_NUM_ARGS(); - if (zend_parse_parameters(argc TSRMLS_CC, "r|Zl", &img, &err, &q) == FAILURE) return; + if (zend_parse_parameters(argc TSRMLS_CC, "r|zl", &img, &err, &q) == FAILURE) return; if (argc > 1) { - zval_dtor(*err); - ZVAL_LONG(*err,0); + zval_dtor(err); + ZVAL_LONG(err,0); } - ZEND_FETCH_RESOURCE(im, Imlib_Image, &img, -1, le_imlib_img_name, le_imlib_img); + if ((im = (Imlib_Image)zend_fetch_resource(Z_RES_P(img), le_imlib_img_name, le_imlib_img)) == NULL) + RETURN_FALSE; tmp = php_open_temporary_file("", "", &tmpfile TSRMLS_CC); if (tmp == NULL) { @@ -1261,19 +1272,19 @@ 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(tmpfile->val,&im_err); if (im_err) { if (argc > 1) { - ZVAL_LONG(*err,im_err); + ZVAL_LONG(err,im_err); } _php_handle_imlib_error(INTERNAL_FUNCTION_PARAM_PASSTHRU, - im_err,tmpfile); + im_err,tmpfile->val); fclose(tmp); - VCWD_UNLINK((const char *)tmpfile); /* make sure that the temporary file is removed */ - efree(tmpfile); + VCWD_UNLINK(tmpfile->val); /* make sure that the temporary file is removed */ + zend_string_release(tmpfile); RETURN_FALSE; } else @@ -1293,8 +1304,8 @@ PHP_FUNCTION(imlib_dump_image) } fclose(tmp); - VCWD_UNLINK((const char *)tmpfile); /* make sure that the temporary file is removed */ - efree(tmpfile); + VCWD_UNLINK(tmpfile->val); /* make sure that the temporary file is removed */ + zend_string_release(tmpfile); RETURN_TRUE; } @@ -1311,8 +1322,9 @@ PHP_FUNCTION(imlib_free_color_range) if (zend_parse_parameters(1 TSRMLS_CC, "r", &fcr) == FAILURE) return; - ZEND_FETCH_RESOURCE(cr, Imlib_Color_Range, &fcr, -1, le_imlib_cr_name, le_imlib_cr); - zend_list_delete(Z_LVAL_PP(&fcr)); + if ((cr = (Imlib_Color_Range)zend_fetch_resource(Z_RES_P(fcr), le_imlib_cr_name, le_imlib_cr)) == NULL) + RETURN_FALSE; + zend_list_close(Z_RES_P(fcr)); } /* }}} */ @@ -1326,8 +1338,9 @@ PHP_FUNCTION(imlib_free_color_modifier) if (zend_parse_parameters(1 TSRMLS_CC, "r", &fcm) == FAILURE) return; - ZEND_FETCH_RESOURCE(cm, PHP_Imlib_Color_Modifier, &fcm, -1, le_imlib_cm_name, le_imlib_cm); - zend_list_delete(Z_LVAL_PP(&fcm)); + if ((cm = (Imlib_Color_Modifier)zend_fetch_resource(Z_RES_P(fcm), le_imlib_cm_name, le_imlib_cm)) == NULL) + RETURN_FALSE; + zend_list_close(Z_RES_P(fcm)); } /* }}} */ @@ -1340,8 +1353,9 @@ PHP_FUNCTION(imlib_free_font) if (zend_parse_parameters(1 TSRMLS_CC, "r", &font) == FAILURE) return; - ZEND_FETCH_RESOURCE(fn, PHP_Imlib_Font, &font, -1, le_imlib_font_name, le_imlib_font); - zend_list_delete(Z_LVAL_PP(&font)); + if ((fn = (PHP_Imlib_Font)zend_fetch_resource(Z_RES_P(font), le_imlib_font_name, le_imlib_font)) == NULL) + RETURN_FALSE; + zend_list_close(Z_RES_P(font)); } /* }}} */ @@ -1355,8 +1369,9 @@ PHP_FUNCTION(imlib_free_image) if (zend_parse_parameters(1 TSRMLS_CC, "r", &img) == FAILURE) return; - ZEND_FETCH_RESOURCE(im, Imlib_Image, &img, -1, le_imlib_img_name, le_imlib_img); - zend_list_delete(Z_LVAL_PP(&img)); + if ((im = (Imlib_Image)zend_fetch_resource(Z_RES_P(img), le_imlib_img_name, le_imlib_img)) == NULL) + RETURN_FALSE; + zend_list_close(Z_RES_P(img)); } /* }}} */ @@ -1366,24 +1381,26 @@ PHP_FUNCTION(imlib_free_image) PHP_FUNCTION(imlib_get_text_advance) { zval *font; - zval **thoriz_adv, **tvert_adv; + zval *thoriz_adv, *tvert_adv; PHP_Imlib_Font fn; - const char *text = NULL; - int text_len, horiz_adv, vert_adv; - long dir; + char *text = NULL; + size_t text_len; + int horiz_adv, vert_adv; + zend_long dir; - if (zend_parse_parameters(5 TSRMLS_CC, "rsZZl", &font, &text, &text_len, &thoriz_adv, &tvert_adv, &dir) == FAILURE) return; + 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, le_imlib_font_name, le_imlib_font); + if ((fn = (PHP_Imlib_Font)zend_fetch_resource(Z_RES_P(font), le_imlib_font_name, le_imlib_font)) == NULL) + RETURN_FALSE; 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); + zval_dtor(thoriz_adv); + zval_dtor(tvert_adv); + ZVAL_LONG(thoriz_adv,horiz_adv); + ZVAL_LONG(tvert_adv,vert_adv); } /* }}} */ @@ -1393,25 +1410,27 @@ PHP_FUNCTION(imlib_get_text_advance) PHP_FUNCTION(imlib_get_text_size) { zval *font; - zval **tw, **th; + zval *tw, *th; PHP_Imlib_Font fn; - const char *text = NULL; - int text_len, w,h; - long dir; + char *text = NULL; + size_t text_len; + int w,h; + zend_long dir; - if (zend_parse_parameters(5 TSRMLS_CC, "rsZZl", &font, &text, &text_len, &tw, &th, &dir) == FAILURE) return; + 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, le_imlib_font_name, le_imlib_font); + if ((fn = (PHP_Imlib_Font)zend_fetch_resource(Z_RES_P(font), le_imlib_font_name, le_imlib_font)) == NULL) + RETURN_FALSE; - zval_dtor(*tw); - zval_dtor(*th); + zval_dtor(tw); + zval_dtor(th); imlib_context_set_font(fn->font); imlib_context_set_direction(dir); imlib_get_text_size(text, &w, &h); - ZVAL_LONG(*tw,w); - ZVAL_LONG(*th,h); + ZVAL_LONG(tw,w); + ZVAL_LONG(th,h); } /* }}} */ @@ -1421,12 +1440,13 @@ PHP_FUNCTION(imlib_get_text_size) PHP_FUNCTION(imlib_image_blur) { zval *img; - long r; + zend_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, le_imlib_img_name, le_imlib_img); + if ((im = (Imlib_Image)zend_fetch_resource(Z_RES_P(img), le_imlib_img_name, le_imlib_img)) == NULL) + RETURN_FALSE; imlib_context_set_image(im); imlib_image_blur(r); @@ -1459,7 +1479,7 @@ PHP_FUNCTION(imlib_image_draw_line) PHP_FUNCTION(imlib_image_draw_polygon) { zval *img, *polygon, *dbox; - long r,g,b,a; + zend_long r,g,b,a; int cx,cy,cw,ch,argc; Imlib_Image im; ImlibPolygon poly; @@ -1468,8 +1488,10 @@ 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, le_imlib_img_name, le_imlib_img); - ZEND_FETCH_RESOURCE(poly, ImlibPolygon, &polygon, -1, le_imlib_poly_name, le_imlib_poly); + if ((im = (Imlib_Image)zend_fetch_resource(Z_RES_P(img), le_imlib_img_name, le_imlib_img)) == NULL) + RETURN_FALSE; + if ((poly = (ImlibPolygon)zend_fetch_resource(Z_RES_P(polygon), le_imlib_poly_name, le_imlib_poly)) == NULL) + RETURN_FALSE; imlib_context_set_image(im); imlib_context_set_color(r,g,b,a); @@ -1502,7 +1524,7 @@ PHP_FUNCTION(imlib_image_draw_rectangle) PHP_FUNCTION(imlib_image_fill_color_range_rectangle) { zval *fim, *fcr, *fbox; - long x,y,width,height; + zend_long x,y,width,height; int argc,cx,cy,cw,ch; double angle; Imlib_Image im; @@ -1511,8 +1533,10 @@ 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, le_imlib_cr_name, le_imlib_cr); - ZEND_FETCH_RESOURCE(im, Imlib_Image, &fim, -1, le_imlib_img_name, le_imlib_img); + if ((cr = (Imlib_Color_Range)zend_fetch_resource(Z_RES_P(fcr), le_imlib_cr_name, le_imlib_cr)) == NULL) + RETURN_FALSE; + if ((im = (Imlib_Image)zend_fetch_resource(Z_RES_P(fim), le_imlib_img_name, le_imlib_img)) == NULL) + RETURN_FALSE; imlib_context_set_color_range(cr); imlib_context_set_image(im); @@ -1546,7 +1570,7 @@ PHP_FUNCTION(imlib_image_fill_ellipse) PHP_FUNCTION(imlib_image_fill_polygon) { zval *img, *polygon, *dbox; - long r,g,b,a; + zend_long r,g,b,a; int cx,cy,cw,ch,argc; Imlib_Image im; ImlibPolygon poly; @@ -1554,8 +1578,10 @@ 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, le_imlib_img_name, le_imlib_img); - ZEND_FETCH_RESOURCE(poly, ImlibPolygon, &polygon, -1, le_imlib_poly_name, le_imlib_poly); + if ((im = (Imlib_Image)zend_fetch_resource(Z_RES_P(img), le_imlib_img_name, le_imlib_img)) == NULL) + RETURN_FALSE; + if ((poly = (ImlibPolygon)zend_fetch_resource(Z_RES_P(polygon), le_imlib_poly_name, le_imlib_poly)) == NULL) + RETURN_FALSE; imlib_context_set_image(im); imlib_context_set_color(r,g,b,a); @@ -1619,12 +1645,13 @@ PHP_FUNCTION(imlib_image_orientate) /* Contributed by Gareth Ardron */ zval *img; - long r; + zend_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, le_imlib_img_name, le_imlib_img); + if ((im = (Imlib_Image)zend_fetch_resource(Z_RES_P(img), le_imlib_img_name, le_imlib_img)) == NULL) + RETURN_FALSE; imlib_context_set_image(im); imlib_image_orientate(r); @@ -1642,14 +1669,15 @@ PHP_FUNCTION(imlib_image_format) if (zend_parse_parameters(1 TSRMLS_CC, "r", &img) == FAILURE) return; - ZEND_FETCH_RESOURCE(im, Imlib_Image, &img, -1, le_imlib_img_name, le_imlib_img); + if ((im = (Imlib_Image)zend_fetch_resource(Z_RES_P(img), le_imlib_img_name, le_imlib_img)) == NULL) + RETURN_FALSE; imlib_context_set_image(im); name = imlib_image_format(); if (!name) RETURN_FALSE; - RETURN_STRING(name,strlen(name)); + RETURN_STRING(name); } /* }}} */ @@ -1664,14 +1692,15 @@ PHP_FUNCTION(imlib_image_get_filename) if (zend_parse_parameters(1 TSRMLS_CC, "r", &img) == FAILURE) return; - ZEND_FETCH_RESOURCE(im, Imlib_Image, &img, -1, le_imlib_img_name, le_imlib_img); + if ((im = (Imlib_Image)zend_fetch_resource(Z_RES_P(img), le_imlib_img_name, le_imlib_img)) == NULL) + RETURN_FALSE; imlib_context_set_image(im); name = imlib_image_get_filename(); if (!name) RETURN_FALSE; - RETURN_STRING((char*)name,strlen(name)); + RETURN_STRING((char*)name); } /* }}} */ @@ -1686,7 +1715,8 @@ PHP_FUNCTION(imlib_image_get_height) if (zend_parse_parameters(1 TSRMLS_CC, "r", &img) == FAILURE) return; - ZEND_FETCH_RESOURCE(im, Imlib_Image, &img, -1, le_imlib_img_name, le_imlib_img); + if ((im = (Imlib_Image)zend_fetch_resource(Z_RES_P(img), le_imlib_img_name, le_imlib_img)) == NULL) + RETURN_FALSE; imlib_context_set_image(im); height = imlib_image_get_height(); @@ -1706,7 +1736,8 @@ PHP_FUNCTION(imlib_image_get_width) if (zend_parse_parameters(1 TSRMLS_CC, "r", &img) == FAILURE) return; - ZEND_FETCH_RESOURCE(im, Imlib_Image, &img, -1, le_imlib_img_name, le_imlib_img); + if ((im = (Imlib_Image)zend_fetch_resource(Z_RES_P(img), le_imlib_img_name, le_imlib_img)) == NULL) + RETURN_FALSE; imlib_context_set_image(im); width = imlib_image_get_width(); @@ -1725,7 +1756,8 @@ PHP_FUNCTION(imlib_image_has_alpha) if (zend_parse_parameters(1 TSRMLS_CC, "r", &img) == FAILURE) return; - ZEND_FETCH_RESOURCE(im, Imlib_Image, &img, -1, le_imlib_img_name, le_imlib_img); + if ((im = (Imlib_Image)zend_fetch_resource(Z_RES_P(img), le_imlib_img_name, le_imlib_img)) == NULL) + RETURN_FALSE; imlib_context_set_image(im); if (imlib_image_has_alpha()) @@ -1748,13 +1780,14 @@ PHP_FUNCTION(imlib_image_modify_alpha) Imlib_Image im; DATA8 map[256]; Imlib_Color_Modifier *cmod; - long malpha; + zend_long malpha; int i; double ratio; if (zend_parse_parameters(2 TSRMLS_CC, "rl", &img, &malpha) == FAILURE) return; - ZEND_FETCH_RESOURCE(im, Imlib_Image, &img, -1, le_imlib_img_name, le_imlib_img); + if ((im = (Imlib_Image)zend_fetch_resource(Z_RES_P(img), le_imlib_img_name, le_imlib_img)) == NULL) + RETURN_FALSE; ratio = ((double)malpha) / 255; @@ -1787,11 +1820,12 @@ PHP_FUNCTION(imlib_image_set_format) zval *img; Imlib_Image im; char *format; - int format_len; + size_t format_len; if (zend_parse_parameters(2 TSRMLS_CC, "rs", &img, &format, &format_len) == FAILURE) return; - ZEND_FETCH_RESOURCE(im, Imlib_Image, &img, -1, le_imlib_img_name, le_imlib_img); + if ((im = (Imlib_Image)zend_fetch_resource(Z_RES_P(img), le_imlib_img_name, le_imlib_img)) == NULL) + RETURN_FALSE; imlib_context_set_image(im); imlib_image_set_format(format); @@ -1806,12 +1840,13 @@ PHP_FUNCTION(imlib_image_set_format) PHP_FUNCTION(imlib_image_sharpen) { zval *img; - long r; + zend_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, le_imlib_img_name, le_imlib_img); + if ((im = (Imlib_Image)zend_fetch_resource(Z_RES_P(img), le_imlib_img_name, le_imlib_img)) == NULL) + RETURN_FALSE; imlib_context_set_image(im); imlib_image_sharpen(r); @@ -1863,8 +1898,7 @@ PHP_FUNCTION(imlib_list_fonts) for (i = 0; i < fcount; i++) { - /* FIXME: Is 1 the right parameter here? */ - add_next_index_string(return_value, flist[i], 1); + add_next_index_string(return_value, flist[i]); } imlib_free_font_list(flist,fcount); @@ -1877,7 +1911,7 @@ PHP_FUNCTION(imlib_list_fonts) PHP_FUNCTION(imlib_load_font) { char *fontname; - int fontname_len; + size_t fontname_len; PHP_Imlib_Font fn; int argc; @@ -1895,7 +1929,7 @@ PHP_FUNCTION(imlib_load_font) RETURN_FALSE; } - ZEND_REGISTER_RESOURCE(return_value, fn, le_imlib_font); + RETURN_RES(zend_register_resource(fn, le_imlib_font)); } /* }}} */ @@ -1904,35 +1938,35 @@ PHP_FUNCTION(imlib_load_font) Load a file into an image, optionally fetch an error parameter */ PHP_FUNCTION(imlib_load_image) { - zval **err; + zval *err; int argc; Imlib_Image im; Imlib_Load_Error im_err; FILE* f; - char* filename; + zend_string* filename; char* img; - int img_len; + size_t img_len; argc = ZEND_NUM_ARGS(); - if (zend_parse_parameters(argc TSRMLS_CC, "s|Z", &img, &img_len, &err) == FAILURE) return; + if (zend_parse_parameters(argc TSRMLS_CC, "s|z", &img, &img_len, &err) == FAILURE) return; if (argc == 2) { - zval_dtor(*err); - ZVAL_LONG(*err,0); + zval_dtor(err); + ZVAL_LONG(err,0); } f = php_stream_open_wrapper_as_file(img, "rb", IGNORE_PATH | 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(filename->val, &im_err); fclose(f); - efree(filename); + zend_string_release(filename); if ((im_err) || (!im)) { if (argc == 2) { - ZVAL_LONG(*err,im_err); + ZVAL_LONG(err,im_err); } _php_handle_imlib_error(INTERNAL_FUNCTION_PARAM_PASSTHRU, im_err,img); @@ -1940,7 +1974,7 @@ PHP_FUNCTION(imlib_load_image) } else { - ZEND_REGISTER_RESOURCE(return_value, im, le_imlib_img); + RETURN_RES(zend_register_resource(im, le_imlib_img)); } } /* }}} */ @@ -1951,12 +1985,13 @@ PHP_FUNCTION(imlib_load_image) PHP_FUNCTION(imlib_polygon_add_point) { zval *polygon; - long x,y; + zend_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, le_imlib_poly_name, le_imlib_poly); + if ((poly = (ImlibPolygon)zend_fetch_resource(Z_RES_P(polygon), le_imlib_poly_name, le_imlib_poly)) == NULL) + RETURN_FALSE; imlib_polygon_add_point(poly,x,y); } @@ -1968,13 +2003,14 @@ PHP_FUNCTION(imlib_polygon_add_point) PHP_FUNCTION(imlib_polygon_contains_point) { zval *polygon; - long x,y; + zend_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, le_imlib_poly_name, le_imlib_poly); + if ((poly = (ImlibPolygon)zend_fetch_resource(Z_RES_P(polygon), le_imlib_poly_name, le_imlib_poly)) == NULL) + RETURN_FALSE; ret = imlib_polygon_contains_point(poly,x,y); @@ -1999,8 +2035,9 @@ PHP_FUNCTION(imlib_polygon_free) if (zend_parse_parameters(1 TSRMLS_CC, "r", &polygon) == FAILURE) return; - ZEND_FETCH_RESOURCE(poly, ImlibPolygon, &polygon, -1, le_imlib_poly_name, le_imlib_poly); - zend_list_delete(Z_LVAL_PP(&polygon)); + if ((poly = (ImlibPolygon)zend_fetch_resource(Z_RES_P(polygon), le_imlib_poly_name, le_imlib_poly)) == NULL) + RETURN_FALSE; + zend_list_close(Z_RES_P(polygon)); } /* }}} */ @@ -2010,25 +2047,26 @@ PHP_FUNCTION(imlib_polygon_free) PHP_FUNCTION(imlib_polygon_get_bounds) { zval *polygon; - zval **px1, **py1, **px2, **py2; + 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; + if (zend_parse_parameters(5 TSRMLS_CC, "rzzzz", &polygon, &px1, &py1, &px2, &py2) == FAILURE) return; - ZEND_FETCH_RESOURCE(poly, ImlibPolygon, &polygon, -1, le_imlib_poly_name, le_imlib_poly); + if ((poly = (ImlibPolygon)zend_fetch_resource(Z_RES_P(polygon), le_imlib_poly_name, le_imlib_poly)) == NULL) + RETURN_FALSE; - zval_dtor(*px1); - zval_dtor(*py1); - zval_dtor(*px2); - zval_dtor(*py2); + zval_dtor(px1); + zval_dtor(py1); + zval_dtor(px2); + zval_dtor(py2); imlib_polygon_get_bounds(poly,&x1,&y1,&x2,&y2); - ZVAL_LONG(*px1,x1); - ZVAL_LONG(*py1,y1); - ZVAL_LONG(*px2,x2); - ZVAL_LONG(*py2,y2); + ZVAL_LONG(px1,x1); + ZVAL_LONG(py1,y1); + ZVAL_LONG(px2,x2); + ZVAL_LONG(py2,y2); } /* }}} */ @@ -2044,7 +2082,7 @@ PHP_FUNCTION(imlib_polygon_new) } poly = imlib_polygon_new(); - if (poly) ZEND_REGISTER_RESOURCE(return_value, poly, le_imlib_poly); + if (poly) RETURN_RES(zend_register_resource(poly, le_imlib_poly)); } /* }}} */ @@ -2053,26 +2091,27 @@ 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; + zval *img, *err; char* name; - int name_len; + size_t name_len; Imlib_Image im; Imlib_Load_Error im_err; int argc; - long q; - char* filename; + zend_long q; + 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; + 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, le_imlib_img_name, le_imlib_img); + if ((im = (Imlib_Image)zend_fetch_resource(Z_RES_P(img), le_imlib_img_name, le_imlib_img)) == NULL) + RETURN_FALSE; imlib_context_set_image(im); if (argc > 2) { - zval_dtor(*err); - ZVAL_LONG(*err,0); + zval_dtor(err); + ZVAL_LONG(err,0); } if (argc > 3) @@ -2083,16 +2122,16 @@ PHP_FUNCTION(imlib_save_image) f = php_stream_open_wrapper_as_file(name, "wb", IGNORE_PATH | REPORT_ERRORS, &filename); if (f == NULL) RETURN_FALSE; - imlib_save_image_with_error_return(filename, &im_err); + imlib_save_image_with_error_return(filename->val, &im_err); fclose(f); - efree(filename); + zend_string_release(filename); if (im_err) { if (argc > 2) { - ZVAL_LONG(*err,im_err); + ZVAL_LONG(err,im_err); } _php_handle_imlib_error(INTERNAL_FUNCTION_PARAM_PASSTHRU, im_err,name); @@ -2112,13 +2151,15 @@ PHP_FUNCTION(imlib_text_draw) Imlib_Image im; PHP_Imlib_Font fn; char *text; - int text_len; - long x,y,dir,r,g,b,a; + size_t text_len; + zend_long x,y,dir,r,g,b,a; 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, le_imlib_img_name, le_imlib_img); - ZEND_FETCH_RESOURCE(fn, PHP_Imlib_Font, &font, -1, le_imlib_font_name, le_imlib_font); + if ((im = (Imlib_Image)zend_fetch_resource(Z_RES_P(img), le_imlib_img_name, le_imlib_img)) == NULL) + RETURN_FALSE; + if ((fn = (PHP_Imlib_Font)zend_fetch_resource(Z_RES_P(font), le_imlib_font_name, le_imlib_font)) == NULL) + RETURN_FALSE; imlib_context_set_image(im); imlib_context_set_color(r,g,b,a); @@ -2142,7 +2183,7 @@ PHP_FUNCTION(imlib_get_cache_size) Set the size of image cache */ PHP_FUNCTION(imlib_set_cache_size) { - long size; + zend_long size; if (zend_parse_parameters(1 TSRMLS_CC, "l", &size) == FAILURE) return; _php_imlib_set_cache_size(size TSRMLS_CC); RETURN_TRUE; @@ -2157,11 +2198,12 @@ PHP_FUNCTION(imlib_apply_filter) Imlib_Image im; struct php_imlib_filter* filter; char* filter_name; - int filter_name_len; + size_t filter_name_len; 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, le_imlib_img_name, le_imlib_img); + if ((im = (Imlib_Image)zend_fetch_resource(Z_RES_P(img), le_imlib_img_name, le_imlib_img)) == NULL) + RETURN_FALSE; filter = _php_imlib_find_filter(filter_name TSRMLS_CC); @@ -2196,7 +2238,7 @@ PHP_FUNCTION(imlib_create_filter) fil = imlib_create_filter(0); - if (fil) ZEND_REGISTER_RESOURCE(return_value, fil, le_imlib_filter); + if (fil) RETURN_RES(zend_register_resource(fil, le_imlib_filter)); } /* }}} */ @@ -2210,8 +2252,9 @@ PHP_FUNCTION(imlib_free_filter) if (zend_parse_parameters(1 TSRMLS_CC, "r", &filter) == FAILURE) return; - ZEND_FETCH_RESOURCE(fil, Imlib_Filter, &filter, -1, le_imlib_filter_name, le_imlib_filter); - zend_list_delete(Z_LVAL_PP(&filter)); + if ((fil = (Imlib_Filter)zend_fetch_resource(Z_RES_P(filter), le_imlib_filter_name, le_imlib_filter)) == NULL) + RETURN_FALSE; + zend_list_close(Z_RES_P(filter)); } /* }}} */ @@ -2225,8 +2268,10 @@ PHP_FUNCTION(imlib_image_filter) if (zend_parse_parameters(2 TSRMLS_CC, "rr", &img, &filter) == FAILURE) return; - ZEND_FETCH_RESOURCE(im, Imlib_Image, &img, -1, le_imlib_img_name, le_imlib_img); - ZEND_FETCH_RESOURCE(fil, Imlib_Filter, &filter, -1, le_imlib_filter_name, le_imlib_filter); + if ((im = (Imlib_Image)zend_fetch_resource(Z_RES_P(img), le_imlib_img_name, le_imlib_img)) == NULL) + RETURN_FALSE; + if ((fil = (Imlib_Filter)zend_fetch_resource(Z_RES_P(filter), le_imlib_filter_name, le_imlib_filter)) == NULL) + RETURN_FALSE; imlib_context_set_image(im); imlib_context_set_filter(fil); @@ -2238,12 +2283,13 @@ static void _php_imlib_filter_set(INTERNAL_FUNCTION_PARAMETERS, int type) { zval *filter; int argc; - long xoff,yoff,a,r,g,b; + zend_long xoff,yoff,a,r,g,b; Imlib_Filter fil; 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, le_imlib_filter_name, le_imlib_filter); + if ((fil = (Imlib_Filter)zend_fetch_resource(Z_RES_P(filter), le_imlib_filter_name, le_imlib_filter)) == NULL) + RETURN_FALSE; imlib_context_set_filter(fil); @@ -2301,12 +2347,13 @@ PHP_FUNCTION(imlib_filter_set_alpha) PHP_FUNCTION(imlib_filter_constants) { zval *filter; - long a, r, g, b; + zend_long a, r, g, b; Imlib_Filter fil; if (zend_parse_parameters(5 TSRMLS_CC, "rllll", &filter, &a, &r, &g, &b) == FAILURE) return; - ZEND_FETCH_RESOURCE(fil, Imlib_Filter, &filter, -1, le_imlib_filter_name, le_imlib_filter); + if ((fil = (Imlib_Filter)zend_fetch_resource(Z_RES_P(filter), le_imlib_filter_name, le_imlib_filter)) == NULL) + RETURN_FALSE; imlib_context_set_filter(fil); imlib_filter_constants(a,r,g,b); @@ -2318,12 +2365,14 @@ PHP_FUNCTION(imlib_filter_constants) PHP_FUNCTION(imlib_filter_divisors) { zval *filter; - long a, r, g, b; + zend_long a, r, g, b; Imlib_Filter fil; if (zend_parse_parameters(5 TSRMLS_CC, "rllll", &filter, &a, &r, &g, &b) == FAILURE) return; - ZEND_FETCH_RESOURCE(fil, Imlib_Filter, &filter, -1, le_imlib_filter_name, le_imlib_filter); + if ((fil = (Imlib_Filter)zend_fetch_resource(Z_RES_P(filter), le_imlib_filter_name, le_imlib_filter)) == NULL) + RETURN_FALSE; + imlib_context_set_filter(fil); imlib_filter_divisors(a,r,g,b); @@ -2341,7 +2390,8 @@ PHP_FUNCTION(imlib_modify_color_modifier_gamma) if (zend_parse_parameters(2 TSRMLS_CC, "rd", &color_modifier, &gamma) == FAILURE) return; - ZEND_FETCH_RESOURCE(cm, PHP_Imlib_Color_Modifier, &color_modifier, -1, le_imlib_cm_name, le_imlib_cm); + if ((cm = (PHP_Imlib_Color_Modifier)zend_fetch_resource(Z_RES_P(color_modifier), le_imlib_cm_name, le_imlib_cm)) == NULL) + RETURN_FALSE; if (cm->modified) _php_imlib_color_modifier_synch(cm); imlib_context_set_color_modifier(cm->cm); imlib_modify_color_modifier_gamma(gamma); @@ -2361,7 +2411,8 @@ PHP_FUNCTION(imlib_modify_color_modifier_brightness) if (zend_parse_parameters(2 TSRMLS_CC, "rd", &color_modifier, &brightness) == FAILURE) return; - ZEND_FETCH_RESOURCE(cm, Imlib_Color_Modifier, &color_modifier, -1, le_imlib_cm_name, le_imlib_cm); + if ((cm = (PHP_Imlib_Color_Modifier)zend_fetch_resource(Z_RES_P(color_modifier), le_imlib_cm_name, le_imlib_cm)) == NULL) + RETURN_FALSE; if (cm->modified) _php_imlib_color_modifier_synch(cm); imlib_context_set_color_modifier(cm->cm); imlib_modify_color_modifier_brightness(brightness); @@ -2381,7 +2432,8 @@ PHP_FUNCTION(imlib_modify_color_modifier_contrast) if (zend_parse_parameters(2 TSRMLS_CC, "rd", &color_modifier, &contrast) == FAILURE) return; - ZEND_FETCH_RESOURCE(cm, PHP_Imlib_Color_Modifier, &color_modifier, -1, le_imlib_cm_name, le_imlib_cm); + if ((cm = (PHP_Imlib_Color_Modifier)zend_fetch_resource(Z_RES_P(color_modifier), le_imlib_cm_name, le_imlib_cm)) == NULL) + RETURN_FALSE; if (cm->modified) _php_imlib_color_modifier_synch(cm); |
