Last commit for filters/php_colormod.c: a2f603174ce34359dde60b6227d138b5bf330503

Revert "Quick and dirty PHP7 port."

Piotr Pawłow [2016-09-14 15:21:01]
Revert "Quick and dirty PHP7 port."

This reverts commit 87380c76cb1eb3644da7291d842281caaae63f2d.
There are much more differences between PHP5 and 7 than I anticipated.
The code doesn't work right.
#include "php.h"
#include "php_imlib.h"

#define php_filter_init			php_colormod_LTX_php_filter_init
#define php_filter_deinit		php_colormod_LTX_php_filter_deinit
#define php_filter_exec			php_colormod_LTX_php_filter_exec
#define php_filter_getfiltercount	php_colormod_LTX_php_filter_getfiltercount
#define php_filter_getfilternames	php_colormod_LTX_php_filter_getfilternames
#define php_filter_getextinfo		php_colormod_LTX_php_filter_getextinfo
#define php_filter_getparams		php_colormod_LTX_php_filter_getparams

static char* _php_colormod_stradd(char* str1,char* str2)
{
	char* retval;
	if ((str1)&&(str2))
	{
		retval=emalloc((strlen(str1)+strlen(str2)+1)*sizeof(char));
		if (retval)
		{
			strcpy(retval,str1);
			strcat(retval,str2);
			efree(str1);
			return retval;
		}
	}
	return str1;
}

static int
_php_colormod_exec(HashTable* params)
{
	char *paramnames[]={"x","y","w","h","brightness","contrast","gamma","brightness_r","contrast_r","gamma_r","brightness_g","contrast_g","gamma_g","brightness_b","contrast_b","gamma_b","brightness_a","contrast_a","gamma_a","tint","tint_r","tint_g","tint_b","tint_a",0};
	int paramtypes[]=  {'i','i','i','i','d',         'd',       'd',    'd',           'd',         'd',      'd',           'd',         'd',      'd',           'd',         'd',      'd',           'd',         'd',      'd',   'd',     'd',     'd',     'd'       };
	char *script;

	HashPosition pos;
	script=estrdup("colormod(");

	zend_hash_internal_pointer_reset_ex(params,&pos);
	while (pos)
	{
		char *str_index;
		ulong num_index;
		int retval;

		retval=zend_hash_get_current_key_ex(params,&str_index,NULL,&num_index,0,&pos);
		if (retval==HASH_KEY_IS_STRING)
		{
			int match=0;
			int index=0;
			while (paramnames[index])
			{
				if (strcmp(str_index,paramnames[index])==0)
				{
					char val[32];
					zval **data;
					zend_hash_get_current_data_ex(params,&data,&pos);

					switch(paramtypes[index])
					{
					    case 'i':
						    convert_to_long_ex(data);
						    sprintf(val,"%d",(int)Z_LVAL_PP(data));
				    		    script=_php_colormod_stradd(script,str_index);
						    script=_php_colormod_stradd(script,"=");
						    script=_php_colormod_stradd(script,val);
						    break;
					    case 'd':
						    convert_to_double_ex(data);
						    sprintf(val,"%f",(double)Z_DVAL_PP(data));
				    		    script=_php_colormod_stradd(script,str_index);
						    script=_php_colormod_stradd(script,"=");
						    script=_php_colormod_stradd(script,val);
						    break;
					}
					script=_php_colormod_stradd(script,",");
					match=1;
					break;
				}
				index++;
			}
			if (!match)
    		    	{
				php_error(E_NOTICE,"Unknown argument %s ignored",str_index);
			}
		}
		zend_hash_move_forward_ex(params,&pos);
	}

	if (script[strlen(script)-1]==',') script[strlen(script)-1]='\0';
	script=_php_colormod_stradd(script,");");
	if (!script) return FAILURE;
/* zend_printf("Script: %s<br>",script); */
	imlib_apply_filter(script);
	efree(script);
	return SUCCESS;
}

int
php_filter_init()
{
   return SUCCESS;
}

void
php_filter_deinit()
{
	return;
}

int
php_filter_exec(Imlib_Image im, char *filter, HashTable *params)
{
	if (!strcmp(filter, "colormod"))
	{
		imlib_context_set_image(im);
		return _php_colormod_exec(params);
	}
	return FAILURE;
}

int
php_filter_getfiltercount()
{
	return 1;
}

void
php_filter_getfilternames(char** filternames)
{
	filternames[0]="colormod";
}

void
php_filter_getextinfo(char** info)
{
	info[0]="Tinting";
	info[1]="Provides PHP interface to Willem Monsuwe's color modification filters.";
	info[2]="Piotr Pawlow (pp@siedziba.pl)";
}

char*
php_filter_getparams(char* filter)
{
	if (!strcmp(filter, "colormod")) return "int x=0, int y=0, int w=image_width, int h=image_height, double brightness[_r|_g|_b|_a]=0, double contrast[_r|_g|_b|_a]=1, double gamma[_r|_g|_b|_a]=1, double tint[_r|_g|_b|_a]=1";
	return NULL;
}
ViewGit