Implemented the gdScatter filter I wrote almost 10 years ago · php/php-src@bcd11a1

@@ -112,7 +112,8 @@ int overflow2(int a, int b);

112112

#define IMAGE_FILTER_MEAN_REMOVAL 9

113113

#define IMAGE_FILTER_SMOOTH 10

114114

#define IMAGE_FILTER_PIXELATE 11

115-

#define IMAGE_FILTER_MAX 11

115+

#define IMAGE_FILTER_SCATTER 12

116+

#define IMAGE_FILTER_MAX 12

116117

#define IMAGE_FILTER_MAX_ARGS 6

117118

static void php_image_filter_negate(INTERNAL_FUNCTION_PARAMETERS);

118119

static void php_image_filter_grayscale(INTERNAL_FUNCTION_PARAMETERS);

@@ -126,6 +127,7 @@ static void php_image_filter_selective_blur(INTERNAL_FUNCTION_PARAMETERS);

126127

static void php_image_filter_mean_removal(INTERNAL_FUNCTION_PARAMETERS);

127128

static void php_image_filter_smooth(INTERNAL_FUNCTION_PARAMETERS);

128129

static void php_image_filter_pixelate(INTERNAL_FUNCTION_PARAMETERS);

130+

static void php_image_filter_scatter(INTERNAL_FUNCTION_PARAMETERS);

129131130132

/* End Section filters declarations */

131133

static gdImagePtr _php_image_create_from_string (zval *Data, char *tn, gdImagePtr (*ioctx_func_p)());

@@ -1191,6 +1193,7 @@ PHP_MINIT_FUNCTION(gd)

11911193

REGISTER_LONG_CONSTANT("IMG_FILTER_MEAN_REMOVAL", IMAGE_FILTER_MEAN_REMOVAL, CONST_CS | CONST_PERSISTENT);

11921194

REGISTER_LONG_CONSTANT("IMG_FILTER_SMOOTH", IMAGE_FILTER_SMOOTH, CONST_CS | CONST_PERSISTENT);

11931195

REGISTER_LONG_CONSTANT("IMG_FILTER_PIXELATE", IMAGE_FILTER_PIXELATE, CONST_CS | CONST_PERSISTENT);

1196+

REGISTER_LONG_CONSTANT("IMG_FILTER_SCATTER", IMAGE_FILTER_SCATTER, CONST_CS | CONST_PERSISTENT);

11941197

/* End Section Filters */

1195119811961199

#ifdef GD_VERSION_STRING

@@ -4455,6 +4458,50 @@ static void php_image_filter_pixelate(INTERNAL_FUNCTION_PARAMETERS)

44554458

RETURN_FALSE;

44564459

}

445744604461+

static void php_image_filter_scatter(INTERNAL_FUNCTION_PARAMETERS)

4462+

{

4463+

zval *IM;

4464+

zval *hash_colors = NULL;

4465+

gdImagePtr im;

4466+

zend_long tmp;

4467+

zend_long scatter_sub, scatter_plus;

4468+4469+

if (zend_parse_parameters(ZEND_NUM_ARGS(), "rlll|a", &IM, &tmp, &scatter_sub, &scatter_plus, &hash_colors) == FAILURE) {

4470+

RETURN_FALSE;

4471+

}

4472+4473+

if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) {

4474+

RETURN_FALSE;

4475+

}

4476+4477+

if (hash_colors) {

4478+

uint32_t i = 0;

4479+

uint32_t num_colors = zend_hash_num_elements(Z_ARRVAL_P(hash_colors));

4480+

zval *color;

4481+

int *colors;

4482+4483+

if (num_colors == 0) {

4484+

RETURN_BOOL(gdImageScatter(im, (int)scatter_sub, (int)scatter_plus));

4485+

}

4486+4487+

colors = emalloc(num_colors * sizeof(int));

4488+4489+

zend_hash_internal_pointer_reset(Z_ARRVAL_P(hash_colors));

4490+4491+

while ((color = zend_hash_get_current_data(Z_ARRVAL_P(hash_colors))) != NULL) {

4492+

zend_hash_move_forward(Z_ARRVAL_P(hash_colors));

4493+4494+

*(colors + i++) = (int) zval_get_long(color);

4495+

}

4496+4497+

RETVAL_BOOL(gdImageScatterColor(im, (int)scatter_sub, (int)scatter_plus, colors, num_colors));

4498+4499+

efree(colors);

4500+

} else {

4501+

RETURN_BOOL(gdImageScatter(im, (int) scatter_sub, (int) scatter_plus))

4502+

}

4503+

}

4504+44584505

/* {{{ proto bool imagefilter(resource src_im, int filtertype[, int arg1 [, int arg2 [, int arg3 [, int arg4 ]]]] )

44594506

Applies Filter an image using a custom angle */

44604507

PHP_FUNCTION(imagefilter)

@@ -4476,7 +4523,8 @@ PHP_FUNCTION(imagefilter)

44764523

php_image_filter_selective_blur,

44774524

php_image_filter_mean_removal,

44784525

php_image_filter_smooth,

4479-

php_image_filter_pixelate

4526+

php_image_filter_pixelate,

4527+

php_image_filter_scatter

44804528

};

4481452944824530

if (ZEND_NUM_ARGS() < 2 || ZEND_NUM_ARGS() > IMAGE_FILTER_MAX_ARGS) {