Re: cvs: pecl /freeimage freeimage.c
| From: | Andrey Hristov | Date: | Tue, 06 Jan 2004 12:30:18 +0000 |
| Subject: | Re: cvs: pecl /freeimage freeimage.c | ||
| References: | 1 | Groups: | php.pecl.cvs |
| Request: | Send a blank email to pecl-cvs+get-649@lists.php.net to get a copy of this message | ||
Hi,
zend_get_parameters_ex() is faster than zend_parse_parameters, but if you
don't need performance it's ok to use zend_parse_parameters. And if the code
is already working there is probably no need to slow it down :)
Also one point more :
Consider code like this :
if (ZEND_NUM_ARGS() != 2 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rd", &z_dib, &percentage) == FAILURE) {
WRONG_PARAM_COUNT;
}
Except for performance reasons you don't need to check ZEND_NUM_ARGS explicitly. It will be done by zend_parse_params(). The latter will emit a warning in cases when the call is
eroneous and then you don't need to use WRONG_PARAM_COUNT but just return; (which will return NULL to the userland. if you need FALSE, then you can RETURN_FALSE).
Regards,
Andrey
Wenlong Wu wrote:
wenlong Tue Jan 6 05:58:45 2004 EDTModified files: /pecl/freeimage freeimage.c Log:Added FreeImage_GetColorType(), FreeImage_SetTransparent(), FreeImage_ConvertToRawBits(), FreeImage_GetTransparencyTable(), FreeImage_GetScanLine() use zend_parse_parameters() instead of zend_get_parameters_ex() ------------------------------------------------------------------------ Index: pecl/freeimage/freeimage.c diff -u pecl/freeimage/freeimage.c:1.3 pecl/freeimage/freeimage.c:1.4 --- pecl/freeimage/freeimage.c:1.3 Mon Jan 5 11:59:27 2004 +++ pecl/freeimage/freeimage.c Tue Jan 6 05:58:45 2004 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: freeimage.c,v 1.3 2004/01/05 16:59:27 rasmus Exp $ */ +/* $Id: freeimage.c,v 1.4 2004/01/06 10:58:45 wenlong Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -38,6 +38,9 @@ static int le_freeimage; #define le_freeimage_name "FreeImage" +static unsigned char second_args_force_ref[] = { 3, BYREF_NONE, BYREF_FORCE, BYREF_NONE }; +static unsigned char bits_force_ref[] = {9, BYREF_FORCE, BYREF_NONE, BYREF_NONE, BYREF_NONE, BYREF_NONE, BYREF_NONE, BYREF_NONE, BYREF_NONE, BYREF_NONE}; + /* {{{ freeimage_functions[] * * Every user visible function must have an entry in freeimage_functions[]. @@ -88,7 +91,7 @@ PHP_FE(freeimage_convertto24bits, NULL) PHP_FE(freeimage_convertto32bits, NULL) PHP_FE(freeimage_convertto8bits, NULL) - PHP_FE(freeimage_converttorawbits, NULL) + PHP_FE(freeimage_converttorawbits, bits_force_ref) PHP_FE(freeimage_copy, NULL) PHP_FE(freeimage_createiccprofile, NULL) PHP_FE(freeimage_deletepage, NULL) @@ -122,7 +125,7 @@ PHP_FE(freeimage_getformatfromfif, NULL) PHP_FE(freeimage_getgreenmask, NULL) PHP_FE(freeimage_getheight, NULL) - PHP_FE(freeimage_gethistogram, NULL) + PHP_FE(freeimage_gethistogram, second_args_force_ref) PHP_FE(freeimage_geticcprofile, NULL) PHP_FE(freeimage_getinfo, NULL) PHP_FE(freeimage_getinfoheader, NULL) @@ -356,20 +359,20 @@ } /* }}} */ -/* {{{ proto bool freeimage_adjustbrightness(int dib, double percentage) +/* {{{ proto bool freeimage_adjustbrightness(resource dib, double percentage)returns TRUE on success, FALSE otherwise (e.g. when the bitdepth of the source dib cannot be handled). */PHP_FUNCTION(freeimage_adjustbrightness) { - zval **z_dib=NULL, **z_percentage=NULL; + zval *z_dib=NULL; FIBITMAP *bitmap; + double percentage; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &z_dib, &z_percentage) == FAILURE) { + if (ZEND_NUM_ARGS() != 2 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rd", &z_dib, &percentage) == FAILURE) { WRONG_PARAM_COUNT; } - convert_to_double_ex(z_percentage); - ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, z_dib, -1, le_freeimage_name, le_freeimage); - if (FreeImage_AdjustBrightness(bitmap, Z_DVAL_PP(z_percentage))) { + ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, &z_dib, -1, le_freeimage_name, le_freeimage); + if (FreeImage_AdjustBrightness(bitmap, percentage)) { RETURN_TRUE; } else { RETURN_FALSE; @@ -377,20 +380,20 @@ } /* }}} */ -/* {{{ proto bool freeimage_adjustcontrast(int dib, double percentage) +/* {{{ proto bool freeimage_adjustcontrast(resource dib, double percentage)returns TRUE on success, FALSE otherwise (e.g. when the bitdepth of the source dib cannot be handled). */PHP_FUNCTION(freeimage_adjustcontrast) { - zval **z_dib=NULL, **z_percentage=NULL; + zval *z_dib=NULL; FIBITMAP *bitmap; + double percentage; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &z_dib, &z_percentage) == FAILURE) { + if (ZEND_NUM_ARGS() != 2 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rd", &z_dib, &percentage) == FAILURE) { WRONG_PARAM_COUNT; } - convert_to_double_ex(z_percentage); - ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, z_dib, -1, le_freeimage_name, le_freeimage); - if (FreeImage_AdjustContrast(bitmap, Z_DVAL_PP(z_percentage))) { + ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, &z_dib, -1, le_freeimage_name, le_freeimage); + if (FreeImage_AdjustContrast(bitmap, percentage)) { RETURN_TRUE; } else { RETURN_FALSE; @@ -406,20 +409,20 @@ } /* }}} */ -/* {{{ proto bool freeimage_adjustgamma(int dib, double gamma) +/* {{{ proto bool freeimage_adjustgamma(resource dib, double gamma)returns TRUE on success. It returns FALSE when gamma is less than or equal to zero or when the bitdepth of the source dib cannot be handled.*/PHP_FUNCTION(freeimage_adjustgamma) { - zval **z_dib=NULL, **z_gamma=NULL; + zval *z_dib=NULL; FIBITMAP *bitmap; + double gamma; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &z_dib, &z_gamma) == FAILURE) { + if (ZEND_NUM_ARGS() != 2 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rd", &z_dib, &gamma) == FAILURE) { WRONG_PARAM_COUNT; } - convert_to_double_ex(z_gamma); - ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, z_dib, -1, le_freeimage_name, le_freeimage); - if (FreeImage_AdjustGamma(bitmap, Z_DVAL_PP(z_gamma))) { + ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, &z_dib, -1, le_freeimage_name, le_freeimage); + if (FreeImage_AdjustGamma(bitmap, gamma)) { RETURN_TRUE; } else { RETURN_FALSE; @@ -431,71 +434,12 @@allocates an empty bitmap. */PHP_FUNCTION(freeimage_allocate) { - zval **z_width=NULL, **z_height=NULL, **z_bpp=NULL, **z_redmask=NULL, **z_greenmask=NULL, **z_bluemask=NULL; int width, height, bpp; unsigned red_mask=0, green_mask=0, blue_mask=0; FIBITMAP *bitmap; - switch(ZEND_NUM_ARGS()) { - case 3: - if (zend_get_parameters_ex(3, &z_width, &z_height, &z_bpp) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long_ex(z_width); - width = (int)Z_LVAL_PP(z_width); - convert_to_long_ex(z_height); - height = (int)Z_LVAL_PP(z_height); - convert_to_long_ex(z_bpp); - bpp = (int)Z_LVAL_PP(z_bpp); - break; - case 4: - if (zend_get_parameters_ex(4, &z_width, &z_height, &z_bpp, &z_redmask) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long_ex(z_width); - width = (int)Z_LVAL_PP(z_width); - convert_to_long_ex(z_height); - height = (int)Z_LVAL_PP(z_height); - convert_to_long_ex(z_bpp); - bpp = (int)Z_LVAL_PP(z_bpp); - convert_to_long_ex(z_redmask); - red_mask = (unsigned)Z_LVAL_PP(z_redmask); - break; - case 5: - if (zend_get_parameters_ex(5, &z_width, &z_height, &z_bpp, &z_redmask, &z_greenmask) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long_ex(z_width); - width = (int)Z_LVAL_PP(z_width); - convert_to_long_ex(z_height); - height = (int)Z_LVAL_PP(z_height); - convert_to_long_ex(z_bpp); - bpp = (int)Z_LVAL_PP(z_bpp); - convert_to_long_ex(z_redmask); - red_mask = (unsigned)Z_LVAL_PP(z_redmask); - convert_to_long_ex(z_greenmask); - green_mask = (unsigned)Z_LVAL_PP(z_greenmask); - break; - case 6: - if (zend_get_parameters_ex(6, &z_width, &z_height, &z_bpp, &z_redmask, &z_greenmask, &z_bluemask) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long_ex(z_width); - width = (int)Z_LVAL_PP(z_width); - convert_to_long_ex(z_height); - height = (int)Z_LVAL_PP(z_height); - convert_to_long_ex(z_bpp); - bpp = (int)Z_LVAL_PP(z_bpp); - convert_to_long_ex(z_redmask); - red_mask = (unsigned)Z_LVAL_PP(z_redmask); - convert_to_long_ex(z_greenmask); - green_mask = (unsigned)Z_LVAL_PP(z_greenmask); - convert_to_long_ex(z_bluemask); - blue_mask = (unsigned)Z_LVAL_PP(z_bluemask); - break; - default: - WRONG_PARAM_COUNT; - break; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll|lll", &width, &height, &bpp, &red_mask, &green_mask, &blue_mask) == FAILURE) { + RETURN_FALSE; } bitmap = FreeImage_Allocate(width, height, bpp, red_mask, green_mask, blue_mask); if (bitmap) { @@ -515,17 +459,17 @@ } /* }}} */ -/* {{{ proto void freeimage_clone(int dib) +/* {{{ proto void freeimage_clone(resource dib)Makes an exact reproduction of an existing bitmap. */PHP_FUNCTION(freeimage_clone) { - zval **z_dib=NULL; + zval *z_dib=NULL; FIBITMAP *bitmap, *clone; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &z_dib) == FAILURE) { + if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_dib) == FAILURE) { WRONG_PARAM_COUNT; } - ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, z_dib, -1, le_freeimage_name, le_freeimage); + ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, &z_dib, -1, le_freeimage_name, le_freeimage); clone = FreeImage_Clone(bitmap); if (clone) { ZEND_REGISTER_RESOURCE(return_value, clone, le_freeimage); @@ -540,28 +484,15 @@Closes a previously opened multi-page bitmap. */PHP_FUNCTION(freeimage_closemultibitmap) { - zval **z_bitmap=NULL, **z_flags=NULL; + zval *z_bitmap=NULL; FIMULTIBITMAP *multibitmap; int flags = 0; - switch(ZEND_NUM_ARGS()) { - case 1: - if (zend_get_parameters_ex(1, &z_bitmap) == FAILURE) { - WRONG_PARAM_COUNT; - } - break; - case 2: - if (zend_get_parameters_ex(2, &z_bitmap, &z_flags) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long_ex(z_flags); - flags = (int)Z_LVAL_PP(z_flags); - break; - default: - WRONG_PARAM_COUNT; - break; + if (ZEND_NUM_ARGS() != 2 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &z_bitmap, &flags) == FAILURE) { + WRONG_PARAM_COUNT; } - ZEND_FETCH_RESOURCE(multibitmap, FIMULTIBITMAP *, z_bitmap, -1, le_freeimage_name, le_freeimage); + + ZEND_FETCH_RESOURCE(multibitmap, FIMULTIBITMAP *, &z_bitmap, -1, le_freeimage_name, le_freeimage); if (FreeImage_CloseMultiBitmap(multibitmap, flags)) { RETURN_TRUE; } else { @@ -570,20 +501,20 @@ } /* }}} */ -/* {{{ proto int freeimage_colorquantize(int dib, int qan) +/* {{{ proto int freeimage_colorquantize(resource dib, int quantize)Quantizes a high-color 24-bit bitmap to an 8-bit palette color bitmap. */PHP_FUNCTION(freeimage_colorquantize) { - zval **z_dib,**z_qan; + zval *z_dib=NULL; + int quantize; FIBITMAP *bitmap, *conv_bitmap; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &z_dib, &z_qan) == FAILURE) { + if (ZEND_NUM_ARGS() != 2 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &z_dib, &quantize) == FAILURE) { WRONG_PARAM_COUNT; } - convert_to_long_ex(z_qan); - ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, z_dib, -1, le_freeimage_name, le_freeimage); - conv_bitmap = FreeImage_ColorQuantize(bitmap, (FREE_IMAGE_QUANTIZE)Z_LVAL_PP(z_qan)); + ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, &z_dib, -1, le_freeimage_name, le_freeimage); + conv_bitmap = FreeImage_ColorQuantize(bitmap, (FREE_IMAGE_QUANTIZE)quantize); if (conv_bitmap) { ZEND_REGISTER_RESOURCE(return_value, conv_bitmap, le_freeimage); } else { @@ -597,43 +528,17 @@Converts a raw bitmap somewhere in memory to a FIBITMAP. */PHP_FUNCTION(freeimage_convertfromrawbits) { - zval **z_width, **z_height, **z_pitch, **z_bpp, **z_redmask, **z_greenmask, **z_bluemask, **z_topdown; + zval *z_bits=NULL, *z_dib=NULL; + int width, height, pitch, topdown=0; + unsigned bpp, red_mask, green_mask, blue_mask; FIBITMAP *bitmap; BYTE *bits; - int topdown=0; - switch(ZEND_NUM_ARGS()) { - case 7: - if (zend_get_parameters_ex(7, &z_width, &z_height, &z_pitch, &z_bpp, &z_redmask, &z_greenmask, &z_bluemask) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long_ex(z_width); - convert_to_long_ex(z_height); - convert_to_long_ex(z_pitch); - convert_to_long_ex(z_bpp); - convert_to_long_ex(z_redmask); - convert_to_long_ex(z_greenmask); - convert_to_long_ex(z_bluemask); - break; - case 8: - if (zend_get_parameters_ex(8, &z_width, &z_height, &z_pitch, &z_bpp, &z_redmask, &z_greenmask, &z_bluemask, &z_topdown) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_boolean_ex(z_topdown); - topdown = (int)Z_LVAL_PP(z_topdown); - break; - default: - WRONG_PARAM_COUNT; - break; - } - convert_to_long_ex(z_width); - convert_to_long_ex(z_height); - convert_to_long_ex(z_pitch); - convert_to_long_ex(z_bpp); - convert_to_long_ex(z_redmask); - convert_to_long_ex(z_greenmask); - convert_to_long_ex(z_bluemask); - bits = (BYTE*)emalloc(Z_LVAL_PP(z_height) * Z_LVAL_PP(z_pitch)); - bitmap = FreeImage_ConvertFromRawBits(bits, Z_LVAL_PP(z_width), Z_LVAL_PP(z_height), Z_LVAL_PP(z_pitch), Z_LVAL_PP(z_bpp), Z_LVAL_PP(z_redmask), Z_LVAL_PP(z_greenmask), Z_LVAL_PP(z_bluemask), topdown); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lllllllb", &width, &height, &pitch, &bpp, &red_mask, &green_mask, &blue_mask, &topdown) == FAILURE) { + RETURN_FALSE; + } + + bits = (BYTE*)emalloc(height * pitch); + bitmap = FreeImage_ConvertFromRawBits(bits, width, height, pitch, bpp, red_mask, green_mask, blue_mask, topdown); if (bitmap) { ZEND_REGISTER_RESOURCE(return_value, bitmap, le_freeimage); } else { @@ -882,18 +787,18 @@ } /* }}} */ -/* {{{ proto int freeimage_convertto16bits555(int dib) +/* {{{ proto int freeimage_convertto16bits555(resource dib)Converts a bitmap to 16 bits, where each pixel has a color pattern of 5 bits red, 5 bits green and 5 bits blue. */PHP_FUNCTION(freeimage_convertto16bits555) { - zval **z_dib; + zval *z_dib=NULL; FIBITMAP *bitmap, *conv_bitmap; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &z_dib) == FAILURE) { + if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_dib) == FAILURE) { WRONG_PARAM_COUNT; } - ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, z_dib, -1, le_freeimage_name, le_freeimage); + ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, &z_dib, -1, le_freeimage_name, le_freeimage); conv_bitmap = FreeImage_ConvertTo16Bits555(bitmap); if (conv_bitmap) { ZEND_REGISTER_RESOURCE(return_value, conv_bitmap, le_freeimage); @@ -904,18 +809,18 @@ } /* }}} */ -/* {{{ proto int freeimage_convertto16bits565(int dib) +/* {{{ proto int freeimage_convertto16bits565(resource dib)Converts a bitmap to 16 bits, where each pixel has a color pattern of 5 bits red, 6 bits green and 5 bits blue.*/PHP_FUNCTION(freeimage_convertto16bits565) { - zval **z_dib; + zval *z_dib=NULL; FIBITMAP *bitmap, *conv_bitmap; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &z_dib) == FAILURE) { + if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_dib) == FAILURE) { WRONG_PARAM_COUNT; } - ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, z_dib, -1, le_freeimage_name, le_freeimage); + ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, &z_dib, -1, le_freeimage_name, le_freeimage); conv_bitmap = FreeImage_ConvertTo16Bits565(bitmap); if (conv_bitmap) { ZEND_REGISTER_RESOURCE(return_value, conv_bitmap, le_freeimage); @@ -926,18 +831,18 @@ } /* }}} */ -/* {{{ proto int freeimage_convertto24bits(int dib) +/* {{{ proto int freeimage_convertto24bits(resource dib)Converts a bitmap to 24 bits. A clone of the input bitmap is returned for 24-bit bitmaps.*/PHP_FUNCTION(freeimage_convertto24bits) { - zval **z_dib; + zval *z_dib=NULL; FIBITMAP *bitmap, *conv_bitmap; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &z_dib) == FAILURE) { + if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_dib) == FAILURE) { WRONG_PARAM_COUNT; } - ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, z_dib, -1, le_freeimage_name, le_freeimage); + ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, &z_dib, -1, le_freeimage_name, le_freeimage); conv_bitmap = FreeImage_ConvertTo24Bits(bitmap); if (conv_bitmap) { ZEND_REGISTER_RESOURCE(return_value, conv_bitmap, le_freeimage); @@ -948,19 +853,19 @@ } /* }}} */ -/* {{{ proto int freeimage_convertto32bits(int dib) +/* {{{ proto int freeimage_convertto32bits(resource dib)Converts a bitmap to 32 bits. A clone of the input bitmap is returned for 32-bit bitmaps.*/PHP_FUNCTION(freeimage_convertto32bits) { - zval **z_dib; + zval *z_dib=NULL; FIBITMAP *bitmap, *conv_bitmap; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &z_dib) == FAILURE) { + if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_dib) == FAILURE) { WRONG_PARAM_COUNT; } - ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, z_dib, -1, le_freeimage_name, le_freeimage); + ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, &z_dib, -1, le_freeimage_name, le_freeimage); conv_bitmap = FreeImage_ConvertTo32Bits(bitmap); if (conv_bitmap) { ZEND_REGISTER_RESOURCE(return_value, conv_bitmap, le_freeimage); @@ -971,18 +876,18 @@ } /* }}} */ -/* {{{ proto int freeimage_convertto8bits(int dib) +/* {{{ proto int freeimage_convertto8bits(resource dib)Converts a bitmap to 8 bits. */PHP_FUNCTION(freeimage_convertto8bits) { - zval **z_dib; + zval *z_dib=NULL; FIBITMAP *bitmap, *conv_bitmap; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &z_dib) == FAILURE) { + if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_dib) == FAILURE) { WRONG_PARAM_COUNT; } - ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, z_dib, -1, le_freeimage_name, le_freeimage); + ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, &z_dib, -1, le_freeimage_name, le_freeimage); conv_bitmap = FreeImage_ConvertTo8Bits(bitmap); if (conv_bitmap) { ZEND_REGISTER_RESOURCE(return_value, conv_bitmap, le_freeimage); @@ -993,26 +898,39 @@ } /* }}} */ -/* {{{ proto freeimage_converttorawbits() - */ +/* {{{ proto void freeimage_converttorawbits(&bits, resource dib, int pitch, int bpp, int red_mask, int green_mask, int blue_mask [, topdown]) + Converts a FIBITMAP to a raw piece of memory. */ PHP_FUNCTION(freeimage_converttorawbits) { - RETURN_TRUE; + zval *z_bits=NULL, *z_dib=NULL; + int pitch, topdown=0; + unsigned bpp, red_mask, green_mask, blue_mask; + FIBITMAP *bitmap; + BYTE *bits; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z/rlllllb", &z_bits, &z_dib, &pitch, &bpp, &red_mask, &green_mask, &blue_mask, &topdown) == FAILURE) { + RETURN_FALSE; + } + ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, &z_dib, -1, le_freeimage_name, le_freeimage); + bits = (BYTE*)emalloc(FreeImage_GetHeight(bitmap) * FreeImage_GetPitch(bitmap)); + FreeImage_ConvertToRawBits(bits, bitmap, pitch, bpp, red_mask, green_mask, blue_mask, topdown); + zval_dtor(z_bits); + ZVAL_STRING(z_bits, bits, 1); } /* }}} */ -/* {{{ proto int freeimage_copy(int dib, int left, int top, int right, int bottom) +/* {{{ proto int freeimage_copy(resource dib, int left, int top, int right, int bottom)returns the subimage if successful, NULL otherwise. */PHP_FUNCTION(freeimage_copy) { - zval **z_dib, **z_left=0, **z_top=0, **z_right=0, **z_bottom=0; + zval *z_dib=NULL; FIBITMAP *bitmap, *conv_bitmap; + int left=0, top=0, right=0, bottom=0; - if (ZEND_NUM_ARGS() != 5 || zend_get_parameters_ex(5, &z_dib, &z_left, &z_top, &z_right, &z_bottom) == FAILURE) { + if (ZEND_NUM_ARGS() != 5 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll", &z_dib, &left, &top, &right, &bottom) == FAILURE) { WRONG_PARAM_COUNT; } - ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, z_dib, -1, le_freeimage_name, le_freeimage); - conv_bitmap = FreeImage_Copy(bitmap, (int)Z_LVAL_PP(z_left), (int)Z_LVAL_PP(z_top), (int)Z_LVAL_PP(z_right), (int)Z_LVAL_PP(z_bottom)); + ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, &z_dib, -1, le_freeimage_name, le_freeimage); + conv_bitmap = FreeImage_Copy(bitmap, left, top, right, bottom); if (conv_bitmap) { ZEND_REGISTER_RESOURCE(return_value, conv_bitmap, le_freeimage); } else { @@ -1034,47 +952,47 @@Deletes the page on the given position. */PHP_FUNCTION(freeimage_deletepage) { - zval **z_bitmap=NULL, **z_page=NULL; + zval *z_bitmap=NULL; FIMULTIBITMAP *multibitmap; + int page=0; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &z_bitmap, &z_page) == FAILURE) { + if (ZEND_NUM_ARGS() != 2 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &z_bitmap, &page) == FAILURE) { WRONG_PARAM_COUNT; } - convert_to_long_ex(z_page); - ZEND_FETCH_RESOURCE(multibitmap, FIMULTIBITMAP *, z_bitmap, -1, le_freeimage_name, le_freeimage); - FreeImage_CloseMultiBitmap(multibitmap, Z_LVAL_PP(z_page)); + ZEND_FETCH_RESOURCE(multibitmap, FIMULTIBITMAP *, &z_bitmap, -1, le_freeimage_name, le_freeimage); + FreeImage_CloseMultiBitmap(multibitmap, page); } /* }}} */ -/* {{{ proto void freeimage_destroyiccprofile(int dib) +/* {{{ proto void freeimage_destroyiccprofile(resource dib)destroys an FIICCPROFILE previously created by. */PHP_FUNCTION(freeimage_destroyiccprofile) { - zval **z_dib; + zval *z_dib=NULL; FIBITMAP *bitmap; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &z_dib) == FAILURE) { + if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_dib) == FAILURE) { WRONG_PARAM_COUNT; } - ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, z_dib, -1, le_freeimage_name, le_freeimage); + ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, &z_dib, -1, le_freeimage_name, le_freeimage); FreeImage_DestroyICCProfile(bitmap); } /* }}} */ -/* {{{ proto freeimage_dither() - */ +/* {{{ proto resource freeimage_dither(resource dib, int algorithm) + Converts a bitmap to 1-bit monochrome bitmap using a dithering algorithm. */ PHP_FUNCTION(freeimage_dither) { - zval **z_dib,**z_alg; + zval *z_dib=NULL; + FREE_IMAGE_DITHER algorithm; FIBITMAP *bitmap, *conv_bitmap; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &z_dib, &z_alg) == FAILURE) { + if (ZEND_NUM_ARGS() != 2 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &z_dib, &algorithm) == FAILURE) { WRONG_PARAM_COUNT; } - convert_to_long_ex(z_alg); - ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, z_dib, -1, le_freeimage_name, le_freeimage); - conv_bitmap = FreeImage_Dither(bitmap, (FREE_IMAGE_DITHER)Z_LVAL_PP(z_alg)); + ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, &z_dib, -1, le_freeimage_name, le_freeimage); + conv_bitmap = FreeImage_Dither(bitmap, (FREE_IMAGE_DITHER)algorithm); if (conv_bitmap) { ZEND_REGISTER_RESOURCE(return_value, conv_bitmap, le_freeimage); } else { @@ -1089,13 +1007,11 @@desired bit depth, FALSE otherwise.*/PHP_FUNCTION(freeimage_fifsupportsexportbpp) { - zval **z_fif, **z_bpp; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &z_fif, &z_bpp) == FAILURE) { + int fif, bpp; + if (ZEND_NUM_ARGS() != 2 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &fif, &bpp) == FAILURE) { WRONG_PARAM_COUNT; } - convert_to_long_ex(z_fif); - convert_to_long_ex(z_bpp); - if (FreeImage_FIFSupportsExportBPP((FREE_IMAGE_FORMAT)Z_LVAL_PP(z_fif), Z_LVAL_PP(z_bpp))) { + if (FreeImage_FIFSupportsExportBPP((FREE_IMAGE_FORMAT)fif, bpp)) { RETURN_TRUE; } else { RETURN_FALSE; @@ -1108,12 +1024,11 @@profile, FALSE otherwise.*/PHP_FUNCTION(freeimage_fifsupportsiccprofiles) { - zval **z_fif; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &z_fif) == FAILURE) { + int fif; + if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &fif) == FAILURE) { WRONG_PARAM_COUNT; } - convert_to_long_ex(z_fif); - if (FreeImage_FIFSupportsICCProfiles((FREE_IMAGE_FORMAT)Z_LVAL_PP(z_fif))) { + if (FreeImage_FIFSupportsICCProfiles((FREE_IMAGE_FORMAT)fif)) { RETURN_TRUE; } else { RETURN_FALSE; @@ -1126,12 +1041,11 @@FALSE otherwise.*/PHP_FUNCTION(freeimage_fifsupportsreading) { - zval **z_fif; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &z_fif) == FAILURE) { + int fif; + if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &fif) == FAILURE) { WRONG_PARAM_COUNT; } - convert_to_long_ex(z_fif); - if (FreeImage_FIFSupportsReading((FREE_IMAGE_FORMAT)Z_LVAL_PP(z_fif))) { + if (FreeImage_FIFSupportsReading((FREE_IMAGE_FORMAT)fif)) { RETURN_TRUE; } else { RETURN_FALSE; @@ -1144,12 +1058,11 @@FALSE otherwise.*/PHP_FUNCTION(freeimage_fifsupportswriting) { - zval **z_fif; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &z_fif) == FAILURE) { + int fif; + if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &fif) == FAILURE) { WRONG_PARAM_COUNT; } - convert_to_long_ex(z_fif); - if (FreeImage_FIFSupportsWriting((FREE_IMAGE_FORMAT)Z_LVAL_PP(z_fif))) { + if (FreeImage_FIFSupportsWriting((FREE_IMAGE_FORMAT)fif)) { RETURN_TRUE; } else { RETURN_FALSE; @@ -1157,17 +1070,17 @@ } /* }}} */ -/* {{{ proto bool freeimage_fliphorizontal(int dib) +/* {{{ proto bool freeimage_fliphorizontal(resource dib)Flip the input dib horizontally along the vertical axis. */PHP_FUNCTION(freeimage_fliphorizontal) { - zval **z_dib=NULL; + zval *z_dib=NULL; FIBITMAP *bitmap; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &z_dib) == FAILURE) { + if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_dib) == FAILURE) { WRONG_PARAM_COUNT; } - ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, z_dib, -1, le_freeimage_name, le_freeimage); + ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, &z_dib, -1, le_freeimage_name, le_freeimage); if (FreeImage_FlipHorizontal(bitmap)) { RETURN_TRUE; @@ -1177,17 +1090,17 @@ } /* }}} */ -/* {{{ proto bool freeimage_flipvertical(int dib) +/* {{{ proto bool freeimage_flipvertical(resource dib)Flip the input dib vertically along the horizontal axis. */PHP_FUNCTION(freeimage_flipvertical) { - zval **z_dib=NULL; + zval *z_dib=NULL; FIBITMAP *bitmap; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &z_dib) == FAILURE) { + if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_dib) == FAILURE) { WRONG_PARAM_COUNT; } - ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, z_dib, -1, le_freeimage_name, le_freeimage); + ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, &z_dib, -1, le_freeimage_name, le_freeimage); if (FreeImage_FlipVertical(bitmap)) { RETURN_TRUE; @@ -1197,34 +1110,34 @@ } /* }}} */ -/* {{{ proto long freeimage_getbpp(int dib) +/* {{{ proto long freeimage_getbpp(resource dib)Returns the size of one pixel in the bitmap in bits. */PHP_FUNCTION(freeimage_getbpp) { - zval **z_dib; + zval *z_dib=NULL; FIBITMAP *bitmap; - unsigned int bpp; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &z_dib) == FAILURE) { + unsigned bpp; + if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_dib) == FAILURE) { WRONG_PARAM_COUNT; } - ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, z_dib, -1, le_freeimage_name, le_freeimage); + ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, &z_dib, -1, le_freeimage_name, le_freeimage); bpp = (long)FreeImage_GetBPP(bitmap); RETURN_LONG(bpp); } /* }}} */ -/* {{{ proto freeimage_getbits() - */ +/* {{{ proto string freeimage_getbits(resource dib) + Returns a pointer to the data-bits of the bitmap. */ PHP_FUNCTION(freeimage_getbits) { - zval **z_dib; + zval *z_dib=NULL; FIBITMAP *bitmap; BYTE *ptr; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &z_dib) == FAILURE) { + if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_dib) == FAILURE) { WRONG_PARAM_COUNT; } - ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, z_dib, -1, le_freeimage_name, le_freeimage); + ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, &z_dib, -1, le_freeimage_name, le_freeimage); ptr = (BYTE *)FreeImage_GetBits(bitmap); if (ptr) { RETURN_STRING(ptr, 1); @@ -1235,64 +1148,79 @@ } /* }}} */ -/* {{{ proto long freeimage_getbluemask(int dib) +/* {{{ proto long freeimage_getbluemask(resource dib)Returns a bit pattern describing the blue color component of a pixel in a FIBITMAP. */PHP_FUNCTION(freeimage_getbluemask) { - zval **z_dib; + zval *z_dib=NULL; FIBITMAP *bitmap; unsigned mask; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &z_dib) == FAILURE) { + if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_dib) == FAILURE) { WRONG_PARAM_COUNT; } - ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, z_dib, -1, le_freeimage_name, le_freeimage); + ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, &z_dib, -1, le_freeimage_name, le_freeimage); mask = (unsigned)FreeImage_GetBlueMask(bitmap); RETURN_LONG(mask); } /* }}} */ -/* {{{ proto int freeimage_getchannel(int dib, int channel) +/* {{{ proto int freeimage_getchannel(resource dib, int channel)Retrieves the red, green, blue or alpha channel of a 24- or 32-bit BGR[A] image. returns the extracted channel if successful and returns NULL otherwise. */PHP_FUNCTION(freeimage_getchannel) { - zval **z_dib=NULL, **z_channel=NULL; - FIBITMAP *bitmap, *channel; + zval *z_dib=NULL; + FIBITMAP *bitmap, *channel_bitmap; + int channel; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &z_dib, &z_channel) == FAILURE) { + if (ZEND_NUM_ARGS() != 2 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &z_dib, &channel) == FAILURE) { WRONG_PARAM_COUNT; } - - convert_to_long_ex(z_channel); - ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, z_dib, -1, le_freeimage_name, le_freeimage); - channel = (FIBITMAP *)FreeImage_GetChannel(bitmap, (FREE_IMAGE_COLOR_CHANNEL)Z_LVAL_PP(z_channel)); - if (channel) { - ZEND_REGISTER_RESOURCE(return_value, channel, le_freeimage); + ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, &z_dib, -1, le_freeimage_name, le_freeimage); + channel_bitmap = (FIBITMAP *)FreeImage_GetChannel(bitmap, (FREE_IMAGE_COLOR_CHANNEL)channel); + if (channel_bitmap) { + ZEND_REGISTER_RESOURCE(return_value, channel_bitmap, le_freeimage); } else { RETURN_FALSE; } } /* }}} */ -/* {{{ proto freeimage_getcolortype() - */ +/* {{{ proto int freeimage_getcolortype(resource dib) + Investigates the color type of the bitmap. + FreeImage_GetColorType can returns one of the following values: + FIC_MINISBLACK --- Monochrome bitmap (1-bit) : first palette entry is black. Palletised bitmap (4 or 8-bit) : the bitmap has a greyscale palette + FIC_MINISWHITE --- Monochrome bitmap: first palette entry is white (1-bit) + FIC_PALETTE --- Palletised bitmap (1, 4 or 8-bit) + FIC_RGB --- High-color bitmap (16, 24 or 32-bit) + FIC_RGBALPHA --- High-color bitmap with an alpha channel (32-bit only) + FIC_CMYK --- CMYK bitmap (32-bit only) + */ PHP_FUNCTION(freeimage_getcolortype) { - RETURN_TRUE; + zval *z_dib=NULL; + FIBITMAP *bitmap; + unsigned type; + if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_dib) == FAILURE) { + WRONG_PARAM_COUNT; + } + ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, &z_dib, -1, le_freeimage_name, le_freeimage); + type = (FREE_IMAGE_COLOR_TYPE)FreeImage_GetColorType(bitmap); + RETURN_LONG(type); } /* }}} */ -/* {{{ proto int freeimage_getcolorsused(int dib) +/* {{{ proto int freeimage_getcolorsused(resource dib)Returns the number of colors used in a bitmap. */PHP_FUNCTION(freeimage_getcolorsused) { - zval **z_dib; + zval *z_dib=NULL; FIBITMAP *bitmap; unsigned colors; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &z_dib) == FAILURE) { + if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_dib) == FAILURE) { WRONG_PARAM_COUNT; } - ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, z_dib, -1, le_freeimage_name, le_freeimage); + ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, &z_dib, -1, le_freeimage_name, le_freeimage); colors = (unsigned)FreeImage_GetColorsUsed(bitmap); RETURN_LONG(colors); } @@ -1309,49 +1237,49 @@ } /* }}} */ -/* {{{ proto long freeimage_getdibsize(int dib) +/* {{{ proto long freeimage_getdibsize(resource dib)Returns the size of the DIB-element of a FIBITMAP in memory */PHP_FUNCTION(freeimage_getdibsize) { - zval **z_dib; + zval *z_dib=NULL; FIBITMAP *bitmap; - unsigned int size; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &z_dib) == FAILURE) { + unsigned size; + if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_dib) == FAILURE) { WRONG_PARAM_COUNT; } - ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, z_dib, -1, le_freeimage_name, le_freeimage); + ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, &z_dib, -1, le_freeimage_name, le_freeimage); size = (long)FreeImage_GetDIBSize(bitmap); RETURN_LONG(size); } /* }}} */ -/* {{{ proto long freeimage_getdotspermeterx(int dib) +/* {{{ proto long freeimage_getdotspermeterx(resource dib)Returns the horizontal resolution, in pixels-per-meter, of the target device for the bitmap. */PHP_FUNCTION(freeimage_getdotspermeterx) { - zval **z_dib; + zval *z_dib=NULL; FIBITMAP *bitmap; - unsigned int x; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &z_dib) == FAILURE) { + unsigned x; + if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_dib) == FAILURE) { WRONG_PARAM_COUNT; } - ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, z_dib, -1, le_freeimage_name, le_freeimage); + ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, &z_dib, -1, le_freeimage_name, le_freeimage); x = (long)FreeImage_GetDotsPerMeterX(bitmap); RETURN_LONG(x); } /* }}} */ -/* {{{ proto long freeimage_getdotspermetery(int dib) +/* {{{ proto long freeimage_getdotspermetery(resource dib)Returns the vertical resolution, in pixels-per-meter, of the target device for the bitmap. */PHP_FUNCTION(freeimage_getdotspermetery) { - zval **z_dib; + zval *z_dib=NULL; FIBITMAP *bitmap; - unsigned int y; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &z_dib) == FAILURE) { + unsigned y; + if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_dib) == FAILURE) { WRONG_PARAM_COUNT; } - ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, z_dib, -1, le_freeimage_name, le_freeimage); + ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, &z_dib, -1, le_freeimage_name, le_freeimage); y = (long)FreeImage_GetDotsPerMeterY(bitmap); RETURN_LONG(y); } @@ -1395,7 +1323,7 @@ } /* }}} */ -/* {{{ proto freeimage_getfiffromformat(string format) +/* {{{ proto int freeimage_getfiffromformat(string format)Returns a FREE_IMAGE_FORMAT identifier from the format string that was used to register the FIF. */PHP_FUNCTION(freeimage_getfiffromformat) { @@ -1424,17 +1352,16 @@returns one of the predefined FREE_IMAGE_FORMAT constants. */PHP_FUNCTION(freeimage_getfiletype) { - zval **z_file; + char *filename=NULL; + int filename_len; FREE_IMAGE_FORMAT fif; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &z_file) == FAILURE) { + if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) { WRONG_PARAM_COUNT; } - convert_to_string_ex(z_file); - - if (php_check_open_basedir(Z_STRVAL_PP(z_file) TSRMLS_CC) || (PG(safe_mode) && !php_checkuid(Z_STRVAL_PP(z_file), "wb+", CHECKUID_CHECK_MODE_PARAM))) { + if (php_check_open_basedir(filename TSRMLS_CC) || (PG(safe_mode) && !php_checkuid(filename, "wb+", CHECKUID_CHECK_MODE_PARAM))) { RETURN_FALSE; } - fif = (long)FreeImage_GetFileType(Z_STRVAL_PP(z_file), 0); + fif = (long)FreeImage_GetFileType(filename, 0); RETURN_LONG(fif); } /* }}} */ @@ -1455,75 +1382,57 @@ } /* }}} */ -/* {{{ proto long freeimage_getgreenmask(int dib) +/* {{{ proto long freeimage_getgreenmask(resource dib)Returns a bit pattern describing the green color component of a pixel in a FIBITMAP. */PHP_FUNCTION(freeimage_getgreenmask) { - zval **z_dib; + zval *z_dib=NULL; FIBITMAP *bitmap; unsigned mask; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &z_dib) == FAILURE) { + if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_dib) == FAILURE) { WRONG_PARAM_COUNT; } - ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, z_dib, -1, le_freeimage_name, le_freeimage); + ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, &z_dib, -1, le_freeimage_name, le_freeimage); mask = (unsigned)FreeImage_GetGreenMask(bitmap); RETURN_LONG(mask); } /* }}} */ -/* {{{ proto long freeimage_getheight(int dib) +/* {{{ proto long freeimage_getheight(resource dib)Returns the height of the bitmap in pixels. */PHP_FUNCTION(freeimage_getheight) { - zval **z_dib; + zval *z_dib=NULL; FIBITMAP *bitmap; - unsigned int height; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &z_dib) == FAILURE) { + unsigned height; + if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_dib) == FAILURE) { WRONG_PARAM_COUNT; } - ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, z_dib, -1, le_freeimage_name, le_freeimage); + ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, &z_dib, -1, le_freeimage_name, le_freeimage); height = (long)FreeImage_GetHeight(bitmap); RETURN_LONG(height); } /* }}} */ -/* {{{ proto freeimage_gethistogram() - */ +/* {{{ proto boolean freeimage_gethistogram(resource dib, &histo, unsigned long channel) + Computes the image histogram. For 24-bit and 32-bit images, histogram can be computed from red, + green, blue and black channels. For 8-bit images, histogram is computed from the black channel.*/ PHP_FUNCTION(freeimage_gethistogram) { - zval **z_dib=NULL,**z_histo=NULL,**z_channel=NULL; + zval *z_dib=NULL, *z_histo=NULL; FIBITMAP *bitmap; DWORD *histo = NULL; unsigned long channel = FICC_BLACK; - if (ZEND_NUM_ARGS() < 2) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz|l", &z_dib, &z_histo, &channel) == FAILURE) { WRONG_PARAM_COUNT; } - switch (ZEND_NUM_ARGS()) { - case 2: - if (zend_get_parameters_ex(2, &z_dib, &z_histo) == FAILURE) { - php_error(E_WARNING, "FreeImage_GetHistogram failed"); - RETURN_FALSE; - } - break; - case 3: - if (zend_get_parameters_ex(3, &z_dib, &z_histo, &z_channel) == FAILURE) { - php_error(E_WARNING, "FreeImage_GetHistogram failed"); - RETURN_FALSE; - } - channel = Z_LVAL_PP(z_channel); - break; - default: - WRONG_PARAM_COUNT; - break; - } - - ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, z_dib, -1, le_freeimage_name, le_freeimage); + ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, &z_dib, -1, le_freeimage_name, le_freeimage); if (FreeImage_GetHistogram(bitmap, histo, (FREE_IMAGE_COLOR_CHANNEL)channel)) { - (*z_histo)->type = IS_LONG; - (*z_histo)->value.lval = (DWORD)histo; + zval_dtor(z_histo); + ZVAL_LONG(z_histo, (DWORD)histo); RETURN_TRUE; } else { RETURN_FALSE; @@ -1539,20 +1448,19 @@ } /* }}} */ -/* {{{ proto array freeimage_getinfo(int dib) +/* {{{ proto array freeimage_getinfo(resource dib)Returns the BITMAPINFO as array in a FIBITMAP. */PHP_FUNCTION(freeimage_getinfo) { - zval **z_dib=NULL; - zval *z_header=NULL, *z_colors=NULL, *z_tmp=NULL; + zval *z_dib=NULL, *z_header=NULL, *z_colors=NULL, *z_tmp=NULL; FIBITMAP *bitmap; BITMAPINFO *info; int i; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &z_dib) == FAILURE) { + if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_dib) == FAILURE) { WRONG_PARAM_COUNT; } - ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, z_dib, -1, le_freeimage_name, le_freeimage); + ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, &z_dib, -1, le_freeimage_name, le_freeimage); info = FreeImage_GetInfo(bitmap); if (array_init(return_value)==FAILURE) { @@ -1597,18 +1505,18 @@ } /* }}} */ -/* {{{ proto array freeimage_getinfoheader(int dib) +/* {{{ proto array freeimage_getinfoheader(resource dib)Returns the BITMAPINFOHEADER as array in a FIBITMAP. */PHP_FUNCTION(freeimage_getinfoheader) { - zval **z_dib; + zval *z_dib=NULL; FIBITMAP *bitmap; BITMAPINFOHEADER *infoheader; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &z_dib) == FAILURE) { + if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_dib) == FAILURE) { WRONG_PARAM_COUNT; } - ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, z_dib, -1, le_freeimage_name, le_freeimage); + ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, &z_dib, -1, le_freeimage_name, le_freeimage); infoheader = FreeImage_GetInfoHeader(bitmap); if (array_init(return_value)==FAILURE) { @@ -1630,17 +1538,17 @@ } /* }}} */ -/* {{{ proto long freeimage_getline(int dib) +/* {{{ proto long freeimage_getline(resource dib)Returns the width of the bitmap in bytes. */PHP_FUNCTION(freeimage_getline) { - zval **z_dib; + zval *z_dib=NULL; FIBITMAP *bitmap; - unsigned int bitmap_width; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &z_dib) == FAILURE) { + unsigned bitmap_width; + if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_dib) == FAILURE) { WRONG_PARAM_COUNT; } - ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, z_dib, -1, le_freeimage_name, le_freeimage); + ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, &z_dib, -1, le_freeimage_name, le_freeimage); bitmap_width = (long)FreeImage_GetLine(bitmap); RETURN_LONG(bitmap_width); } @@ -1658,33 +1566,32 @@Returns the number of pages currently available in the multi-paged bitmap. */PHP_FUNCTION(freeimage_getpagecount) { - zval **z_bitmap; + zval *z_bitmap=NULL; FIMULTIBITMAP *multibitmap; - int pagecount; + int pagecount = 1; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &z_bitmap) == FAILURE) { + if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_bitmap) == FAILURE) { WRONG_PARAM_COUNT; } - ZEND_FETCH_RESOURCE(multibitmap, FIMULTIBITMAP *, z_bitmap, -1, le_freeimage_name, le_freeimage); + ZEND_FETCH_RESOURCE(multibitmap, FIMULTIBITMAP *, &z_bitmap, -1, le_freeimage_name, le_freeimage); pagecount = (int)FreeImage_GetPageCount(multibitmap); RETURN_LONG(pagecount); } /* }}} */ -/* {{{ proto array freeimage_getpalette(int dib) +/* {{{ proto array freeimage_getpalette(resource dib)Returns a pointer to the bitmap??s palette.*/PHP_FUNCTION(freeimage_getpalette) { - zval **z_dib; + zval *z_dib=NULL, *z_tmp=NULL; FIBITMAP *bitmap; RGBQUAD *pal; - zval *z_tmp=NULL; int i=0; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &z_dib) == FAILURE) { + if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_dib) == FAILURE) { WRONG_PARAM_COUNT; } - ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, z_dib, -1, le_freeimage_name, le_freeimage); + ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, &z_dib, -1, le_freeimage_name, le_freeimage); if(FreeImage_GetBPP(bitmap) == 8) { // Build a greyscale palette pal = FreeImage_GetPalette(bitmap); @@ -1707,68 +1614,97 @@ } /* }}} */ -/* {{{ proto long freeimage_getpitch(int dib) +/* {{{ proto long freeimage_getpitch(resource dib)Returns the width of the bitmap in bytes, rounded to the next 32-bit boundary, also known as pitch or stride or scan width.*/PHP_FUNCTION(freeimage_getpitch) { - zval **z_dib; + zval *z_dib=NULL; FIBITMAP *bitmap; - unsigned int pitch; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &z_dib) == FAILURE) { + unsigned pitch; + if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_dib) == FAILURE) { WRONG_PARAM_COUNT; } - ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, z_dib, -1, le_freeimage_name, le_freeimage); + ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, &z_dib, -1, le_freeimage_name, le_freeimage); pitch = (long)FreeImage_GetPitch(bitmap); RETURN_LONG(pitch); } /* }}} */ -/* {{{ proto int freeimage_getredmask(int dib) +/* {{{ proto int freeimage_getredmask(resource dib)Returns a bit pattern describing the red color component of a pixel in a FIBITMAP. */PHP_FUNCTION(freeimage_getredmask) { - zval **z_dib; + zval *z_dib=NULL; FIBITMAP *bitmap; unsigned mask; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &z_dib) == FAILURE) { + if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_dib) == FAILURE) { WRONG_PARAM_COUNT; } - ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, z_dib, -1, le_freeimage_name, le_freeimage); + ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, &z_dib, -1, le_freeimage_name, le_freeimage); mask = (unsigned)FreeImage_GetRedMask(bitmap); RETURN_LONG(mask); } /* }}} */ -/* {{{ proto freeimage_getscanline() - */ +/* {{{ proto string freeimage_getscanline(resource dib, int scanline) + Returns a pointer to the start of the given scanline in the bitmap??s data-bits.*/ PHP_FUNCTION(freeimage_getscanline) { - RETURN_TRUE; + zval *z_dib=NULL; + FIBITMAP *bitmap; + BYTE *ptr; + int scanline; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &z_dib, &scanline) == FAILURE) { + RETURN_FALSE; + } + ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, &z_dib, -1, le_freeimage_name, le_freeimage); + ptr = (BYTE *)FreeImage_GetScanLine(bitmap, scanline); + if (ptr) { + RETURN_STRING(ptr, 1); + } else { + php_error(E_WARNING, "FreeImage_GetScanLine failed"); + RETURN_FALSE; + } } /* }}} */ -/* {{{ proto long freeimage_gettransparencycount(int dib) +/* {{{ proto long freeimage_gettransparencycount(resource dib)Returns the number of transparent colors in a palletised bitmap. */PHP_FUNCTION(freeimage_gettransparencycount) { - zval **z_dib; + zval *z_dib=NULL; FIBITMAP *bitmap; unsigned count; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &z_dib) == FAILURE) { + if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_dib) == FAILURE) { WRONG_PARAM_COUNT; } - ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, z_dib, -1, le_freeimage_name, le_freeimage); + ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, &z_dib, -1, le_freeimage_name, le_freeimage); count = (unsigned)FreeImage_GetTransparencyCount(bitmap); RETURN_LONG(count); } /* }}} */ -/* {{{ proto freeimage_gettransparencytable() - */ +/* {{{ proto string freeimage_gettransparencytable(resource dib) + Returns a pointer to the bitmap??s transparency table. */ PHP_FUNCTION(freeimage_gettransparencytable) { - RETURN_TRUE; + zval *z_dib=NULL; + FIBITMAP *bitmap; + BYTE *ptr; + + if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_dib) == FAILURE) { + WRONG_PARAM_COUNT; + } + ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, &z_dib, -1, le_freeimage_name, le_freeimage); + ptr = (BYTE *)FreeImage_GetTransparencyTable(bitmap); + if (ptr) { + RETURN_STRING(ptr, 1); + } else { + php_error(E_WARNING, "FreeImage_GetTransparencyTable failed"); + RETURN_FALSE; + } } /* }}} */ @@ -1783,17 +1719,17 @@ } /* }}} */ -/* {{{ proto long freeimage_getwidth(int dib) +/* {{{ proto long freeimage_getwidth(resource dib)Returns the width of the bitmap in pixels. */PHP_FUNCTION(freeimage_getwidth) { - zval **z_dib; + zval *z_dib=NULL; FIBITMAP *bitmap; - unsigned int width; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &z_dib) == FAILURE) { + unsigned width; + if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_dib) == FAILURE) { WRONG_PARAM_COUNT; } - ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, z_dib, -1, le_freeimage_name, le_freeimage); + ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, &z_dib, -1, le_freeimage_name, le_freeimage); width = (long)FreeImage_GetWidth(bitmap); RETURN_LONG(width); } @@ -1807,16 +1743,16 @@ } /* }}} */ -/* {{{ proto bool freeimage_invert(int dib) +/* {{{ proto bool freeimage_invert(resource dib)Inverts each pixel data.*/PHP_FUNCTION(freeimage_invert) { - zval **z_dib; + zval *z_dib=NULL; FIBITMAP *bitmap; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &z_dib) == FAILURE) { + if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_dib) == FAILURE) { WRONG_PARAM_COUNT; } - ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, z_dib, -1, le_freeimage_name, le_freeimage); + ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, &z_dib, -1, le_freeimage_name, le_freeimage); if (FreeImage_Invert(bitmap)) { RETURN_TRUE; } else { @@ -1837,12 +1773,12 @@Returns TRUE when the plugin is enabled, FALSE when the plugin is disabled, -1 otherwise. */PHP_FUNCTION(freeimage_ispluginenabled) { - zval **z_fif; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &z_fif) == FAILURE) { + int fif; + if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &fif) == FAILURE) { WRONG_PARAM_COUNT; } - convert_to_long_ex(z_fif); - if (FreeImage_IsPluginEnabled((FREE_IMAGE_FORMAT)Z_LVAL_PP(z_fif))) { + + if (FreeImage_IsPluginEnabled((FREE_IMAGE_FORMAT)fif)) { RETURN_TRUE; } else { RETURN_FALSE; @@ -1850,16 +1786,18 @@ } /* }}} */ -/* {{{ proto bool freeimage_istransparent(int dib) +/* {{{ proto bool freeimage_istransparent(resource dib)Returns TRUE when the transparency table is enabled, FALSE otherwise. */PHP_FUNCTION(freeimage_istransparent) { - zval **z_dib; + zval *z_dib=NULL; FIBITMAP *bitmap; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &z_dib) == FAILURE) { + + if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_dib) == FAILURE) { WRONG_PARAM_COUNT; } - ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, z_dib, -1, le_freeimage_name, le_freeimage); + + ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, &z_dib, -1, le_freeimage_name, le_freeimage); if (FreeImage_IsTransparent(bitmap)) { RETURN_TRUE; } else { @@ -1872,33 +1810,16 @@Load a bitmap */PHP_FUNCTION(freeimage_load) { - zval **z_fif=NULL, **z_filename=NULL, **z_flags=NULL; FIBITMAP *bitmap; - int flags=0; + int fif, flags=0; + char *filename=NULL; + int filename_len; - switch(ZEND_NUM_ARGS()) { - case 2: - if (zend_get_parameters_ex(2, &z_fif, &z_filename) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long_ex(z_fif); - convert_to_string_ex(z_filename); - break; - case 3: - if (zend_get_parameters_ex(3, &z_fif, &z_filename, &z_flags) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long_ex(z_fif); - convert_to_string_ex(z_filename); - convert_to_long_ex(z_flags); - flags = (int)Z_LVAL_PP(z_flags); - break; - default: - WRONG_PARAM_COUNT; - break; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls|l", &fif, &filename, &filename_len, &flags) == FAILURE) { + RETURN_FALSE; } - bitmap = FreeImage_Load((FREE_IMAGE_FORMAT)Z_LVAL_PP(z_fif), (char *)Z_STRVAL_PP(z_filename), flags); + bitmap = FreeImage_Load((FREE_IMAGE_FORMAT)fif, filename, flags); if (bitmap) { ZEND_REGISTER_RESOURCE(return_value, bitmap, le_freeimage); } else { @@ -1952,22 +1873,21 @@returns TRUE if successful, FALSE otherwise. */PHP_FUNCTION(freeimage_paste) { - zval **z_dstdib, **z_srcdib, **z_left=0, **z_top=0, **z_alpha=0; + zval *z_dstdib=NULL, *z_srcdib=NULL; FIBITMAP *dst_bitmap,*src_bitmap; - int alpha; + int left=0, top=0, alpha=0; - if (ZEND_NUM_ARGS() != 5 || zend_get_parameters_ex(5, &z_dstdib, &z_srcdib, &z_left, &z_top, &z_alpha) == FAILURE) { + if (ZEND_NUM_ARGS() != 5 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrlll", &z_dstdib, &z_srcdib, &left, &top, &alpha) == FAILURE) { WRONG_PARAM_COUNT; } - ZEND_FETCH_RESOURCE(dst_bitmap, FIBITMAP *, z_dstdib, -1, le_freeimage_name, le_freeimage); - ZEND_FETCH_RESOURCE(src_bitmap, FIBITMAP *, z_srcdib, -1, le_freeimage_name, le_freeimage); - alpha = (int)Z_LVAL_PP(z_alpha); + ZEND_FETCH_RESOURCE(dst_bitmap, FIBITMAP *, &z_dstdib, -1, le_freeimage_name, le_freeimage); + ZEND_FETCH_RESOURCE(src_bitmap, FIBITMAP *, &z_srcdib, -1, le_freeimage_name, le_freeimage); if (alpha <0 || alpha > 256) { alpha = 255; } - if (FreeImage_Paste(dst_bitmap, src_bitmap, (int)Z_LVAL_PP(z_left), (int)Z_LVAL_PP(z_top), alpha)) { + if (FreeImage_Paste(dst_bitmap, src_bitmap, left, top, alpha)) { RETURN_TRUE; } else { RETURN_FALSE; @@ -1999,35 +1919,20 @@ } /* }}} */ -/* {{{ proto int freeimage_rotateclassic(int dib, double angle) +/* {{{ proto int freeimage_rotateclassic(resource dib, double angle)rotates an 8-bit greyscale, 24- or 32-bit image by means of 3 shears. */PHP_FUNCTION(freeimage_rotateclassic) { - zval **z_dib=NULL, **z_angle=0; + zval *z_dib=NULL; FIBITMAP *bitmap, *ratate; int angle = 0; - switch (ZEND_NUM_ARGS()) { - case 1: - if (zend_get_parameters_ex(1, &z_dib) == FAILURE) { - php_error(E_WARNING, "FreeImage_RatateClassic failed"); - RETURN_FALSE; - } - break; - case 2: - if (zend_get_parameters_ex(2, &z_dib, &z_angle) == FAILURE) { - php_error(E_WARNING, "FreeImage_RatateClassic failed"); - RETURN_FALSE; - } - convert_to_long_ex(z_angle); - angle = (Z_LVAL_PP(z_angle) <0 || Z_LVAL_PP(z_angle) > 360) ? 0 : Z_LVAL_PP(z_angle); - break; - default: - WRONG_PARAM_COUNT; - break; + if (ZEND_NUM_ARGS() != 2 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rd", &z_dib, &angle) == FAILURE) { + WRONG_PARAM_COUNT; } - ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, z_dib, -1, le_freeimage_name, le_freeimage); + angle = (angle <0 || angle > 360) ? 0 : angle; + ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, &z_dib, -1, le_freeimage_name, le_freeimage); ratate = FreeImage_RotateClassic(bitmap, angle); if (ratate) { ZEND_REGISTER_RESOURCE(return_value, ratate, le_freeimage); @@ -2038,91 +1943,26 @@ } /* }}} */ -/* {{{ proto freeimage_rotateex() +/* {{{ proto resource freeimage_rotateex(resource dib, double angle, double x_shift, double y_shift, double x_origin, double y_origin, BOOL use_mask) */ PHP_FUNCTION(freeimage_rotateex) { - zval **z_dib=NULL, **z_angle=0, **x_shift=0, **y_shift=0, **x_origin=0, **y_origin=0, **use_mask=NULL; + zval *z_dib=NULL; FIBITMAP *bitmap, *ratate; - double angle=0, shift_x=0, shift_y=0, origin_x=0, origin_y=0; + double angle=0, x_shift=0, y_shift=0, x_origin=0, y_origin=0; BOOL mask=FALSE; - if (ZEND_NUM_ARGS() < 1) WRONG_PARAM_COUNT; - - switch(ZEND_NUM_ARGS()) { - case 1: - if (zend_get_parameters_ex(1, &z_dib) == FAILURE) { - php_error(E_WARNING, "FreeImage_RotateEx failed"); - RETURN_FALSE; - } - break; - case 2: - if (zend_get_parameters_ex(2, &z_dib, &z_angle) == FAILURE) { - php_error(E_WARNING, "FreeImage_RotateEx failed"); - RETURN_FALSE; - } - - convert_to_long_ex(z_angle); - - angle = (Z_LVAL_PP(z_angle) <0 || Z_LVAL_PP(z_angle) > 360) ? 0 : Z_LVAL_PP(z_angle); - break; - case 3: - if (zend_get_parameters_ex(3, &z_dib, &z_angle, &x_shift) == FAILURE) { - php_error(E_WARNING, "FreeImage_RotateEx failed"); - RETURN_FALSE; - } - angle = (Z_LVAL_PP(z_angle) <0 || Z_LVAL_PP(z_angle) > 360) ? 0 : Z_LVAL_PP(z_angle); - shift_x = (Z_LVAL_PP(x_shift)<0) ? 0 : Z_LVAL_PP(x_shift); - break; - case 4: - if (zend_get_parameters_ex(4, &z_dib, &z_angle, &x_shift, &y_shift) == FAILURE) { - php_error(E_WARNING, "FreeImage_RotateEx failed"); - RETURN_FALSE; - } - angle = (Z_LVAL_PP(z_angle) <0 || Z_LVAL_PP(z_angle) > 360) ? 0 : Z_LVAL_PP(z_angle); - shift_x = (Z_LVAL_PP(x_shift)<0) ? 0 : Z_LVAL_PP(x_shift); - shift_y = (Z_LVAL_PP(y_shift)<0) ? 0 : Z_LVAL_PP(y_shift); - break; - case 5: - if (zend_get_parameters_ex(5, &z_dib, &z_angle, &x_shift, &y_shift, &x_origin) == FAILURE) { - php_error(E_WARNING, "FreeImage_RotateEx failed"); - RETURN_FALSE; - } - angle = (Z_LVAL_PP(z_angle) <0 || Z_LVAL_PP(z_angle) > 360) ? 0 : Z_LVAL_PP(z_angle); - shift_x = (Z_LVAL_PP(x_shift)<0) ? 0 : Z_LVAL_PP(x_shift); - shift_y = (Z_LVAL_PP(y_shift)<0) ? 0 : Z_LVAL_PP(y_shift); - origin_x = (Z_LVAL_PP(x_origin) < 0) ? 0 : Z_LVAL_PP(x_origin); - break; - case 6: - if (zend_get_parameters_ex(6, &z_dib, &z_angle, &x_shift, &y_shift, &x_origin, &y_origin) == FAILURE) { - php_error(E_WARNING, "FreeImage_RotateEx failed"); - RETURN_FALSE; - } - angle = (Z_LVAL_PP(z_angle) <0 || Z_LVAL_PP(z_angle) > 360) ? 0 : Z_LVAL_PP(z_angle); - shift_x = (Z_LVAL_PP(x_shift)<0) ? 0 : Z_LVAL_PP(x_shift); - shift_y = (Z_LVAL_PP(y_shift)<0) ? 0 : Z_LVAL_PP(y_shift); - origin_x = (Z_LVAL_PP(x_origin) < 0) ? 0 : Z_LVAL_PP(x_origin); - origin_y = (Z_LVAL_PP(y_origin) < 0) ? 0 : Z_LVAL_PP(y_origin); - break; - case 7: - if (zend_get_parameters_ex(7, &z_dib, &z_angle, &x_shift, &y_shift, &x_origin, &y_origin, &use_mask) == FAILURE) { - php_error(E_WARNING, "FreeImage_RotateEx failed"); - RETURN_FALSE; - } - angle = (Z_LVAL_PP(z_angle) <0 || Z_LVAL_PP(z_angle) > 360) ? 0 : Z_LVAL_PP(z_angle); - shift_x = (Z_LVAL_PP(x_shift)<0) ? 0 : Z_LVAL_PP(x_shift); - shift_y = (Z_LVAL_PP(y_shift)<0) ? 0 : Z_LVAL_PP(y_shift); - origin_x = (Z_LVAL_PP(x_origin) < 0) ? 0 : Z_LVAL_PP(x_origin); - origin_y = (Z_LVAL_PP(y_origin) < 0) ? 0 : Z_LVAL_PP(y_origin);- mask = Z_BVAL_PP(use_mask);- break; - default: - WRONG_PARAM_COUNT; - break; + if (ZEND_NUM_ARGS() != 7 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rdddddb", &z_dib, &angle, &x_shift, &y_shift, &x_origin, &y_origin, &mask) == FAILURE) { + WRONG_PARAM_COUNT; } - ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, z_dib, -1, le_freeimage_name, le_freeimage); - ratate = FreeImage_RotateEx(bitmap, angle, shift_x, shift_y, origin_x, origin_y, mask); + angle = (angle < 0 || angle > 360) ? 0 : angle; + x_shift = (x_shift < 0) ? 0 : x_shift; + y_shift = (y_shift < 0) ? 0 : y_shift; + x_origin = (x_origin < 0) ? 0 : x_origin; + y_origin = (y_origin < 0) ? 0 : y_origin; + ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, &z_dib, -1, le_freeimage_name, le_freeimage); + ratate = FreeImage_RotateEx(bitmap, angle, x_shift, y_shift, x_origin, y_origin, mask); if (ratate) { ZEND_REGISTER_RESOURCE(return_value, ratate, le_freeimage); } else { @@ -2132,21 +1972,22 @@ } /* }}} */ -/* {{{ proto bool freeimage_save(int fif, int dib, string filename, int flags) +/* {{{ proto bool freeimage_save(int fif, resource dib, string filename[, int flags])Save a previously loaded FIBITMAP to a file.*/PHP_FUNCTION(freeimage_save) { - zval **z_fif=NULL, **z_dib=NULL, **z_filename=NULL, **z_flags=NULL; + zval *z_dib=NULL; + FREE_IMAGE_FORMAT fif; + char *filename=NULL; + int filename_len, flags=0; FIBITMAP *bitmap; - if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &z_fif, &z_dib, &z_filename, &z_flags) == FAILURE) { - WRONG_PARAM_COUNT; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lrs|l", &fif, &z_dib, &filename, &filename_len, &flags) == FAILURE) { + RETURN_FALSE; } - convert_to_long_ex(z_fif); - convert_to_string_ex(z_filename); - convert_to_long_ex(z_flags); - ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, z_dib, -1, le_freeimage_name, le_freeimage); - if (FreeImage_Save((FREE_IMAGE_FORMAT)Z_LVAL_PP(z_fif), bitmap, (char *)Z_STRVAL_PP(z_filename), (int)Z_LVAL_PP(z_flags))) { + + ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, &z_dib, -1, le_freeimage_name, le_freeimage); + if (FreeImage_Save((FREE_IMAGE_FORMAT)fif, bitmap, filename, flags)) { RETURN_TRUE; } else { php_error(E_WARNING, "FreeImage_Save failed"); @@ -2163,22 +2004,22 @@ } /* }}} */ -/* {{{ proto freeimage_setchannel() - */ +/* {{{ proto freeimage_setchannel(resource dib, resource dib8, int channel) + Insert a 8-bit dib into a 24- or 32-bit image. dib8 and dib must have the same width and height. */ PHP_FUNCTION(freeimage_setchannel) { - zval **z_dib=NULL, **z_dib8=NULL, **z_channel=NULL; + zval *z_dib=NULL, *z_dib8=NULL; FIBITMAP *bitmap, *bitmap8; + int channel; - if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &z_dib, &z_dib8, &z_channel) == FAILURE) { + if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrl", &z_dib, &z_dib8, &channel) == FAILURE) { WRONG_PARAM_COUNT; } - convert_to_long_ex(z_channel); - ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, z_dib, -1, le_freeimage_name, le_freeimage); - ZEND_FETCH_RESOURCE(bitmap8, FIBITMAP *, z_dib8, -1, le_freeimage_name, le_freeimage); + ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, &z_dib, -1, le_freeimage_name, le_freeimage); + ZEND_FETCH_RESOURCE(bitmap8, FIBITMAP *, &z_dib8, -1, le_freeimage_name, le_freeimage); - if (FreeImage_SetChannel(bitmap, bitmap8, (FREE_IMAGE_COLOR_CHANNEL)Z_LVAL_PP(z_channel))) { + if (FreeImage_SetChannel(bitmap, bitmap8, (FREE_IMAGE_COLOR_CHANNEL)channel)) { RETURN_TRUE; } else { RETURN_FALSE; @@ -2199,7 +2040,15 @@or ?C1 if the plugin doesn??t exist. */PHP_FUNCTION(freeimage_setpluginenabled) { - RETURN_TRUE; + int fif, ret; + boolean enable; + + if (ZEND_NUM_ARGS() != 2 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lb", &fif, &enable) == FAILURE) { + WRONG_PARAM_COUNT; + } + + ret = (int)FreeImage_SetPluginEnabled(fif, enable); + RETURN_LONG(ret); } /* }}} */ @@ -2211,11 +2060,19 @@ } /* }}} */ -/* {{{ proto freeimage_settransparent() - */ +/* {{{ proto void freeimage_settransparent(resource dib, boolean enabled) + Tells FreeImage if it should make use of the transparency table that may accompany a bitmap. */ PHP_FUNCTION(freeimage_settransparent) { - RETURN_TRUE; + zval *z_dib=NULL; + FIBITMAP *bitmap; + boolean enabled; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rb", &z_dib, &enabled) == FAILURE) { + WRONG_PARAM_COUNT; + } + ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, &z_dib, -1, le_freeimage_name, le_freeimage); + FreeImage_SetTransparent(bitmap, enabled); } /* }}} */ @@ -2227,18 +2084,18 @@ } /* }}} */ -/* {{{ proto void freeimage_unload(int dib) +/* {{{ proto void freeimage_unload(resource dib)Deletes a previously loaded FIBITMAP from memory. */PHP_FUNCTION(freeimage_unload) { - zval **z_dib=NULL; + zval *z_dib=NULL; FIBITMAP *bitmap; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &z_dib) == FAILURE) { + if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_dib) == FAILURE) { WRONG_PARAM_COUNT; } - ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, z_dib, -1, le_freeimage_name, le_freeimage); - zend_list_delete(Z_RESVAL_PP(z_dib)); + ZEND_FETCH_RESOURCE(bitmap, FIBITMAP *, &z_dib, -1, le_freeimage_name, le_freeimage); + zend_list_delete(Z_RESVAL_P(z_dib)); RETURN_TRUE; } /* }}} */