Last commit for filters/php_bumpmap.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"

/* aliases for the exported symbols */

#define php_filter_init			php_bumpmap_LTX_php_filter_init
#define php_filter_deinit		php_bumpmap_LTX_php_filter_deinit
#define php_filter_exec			php_bumpmap_LTX_php_filter_exec
#define php_filter_getfiltercount	php_bumpmap_LTX_php_filter_getfiltercount
#define php_filter_getfilternames	php_bumpmap_LTX_php_filter_getfilternames
#define php_filter_getextinfo		php_bumpmap_LTX_php_filter_getextinfo
#define php_filter_getparams		php_bumpmap_LTX_php_filter_getparams


static char* _php_bumpmap_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_bumpmap_exec(char* filter, HashTable* params,int index)
{
	char *allpnames[][10]={
		{"map","angle","elevation","depth","red","green","blue","ambient",0},
		{"map","x","y","z","depth","red","green","blue","ambient",0}
	    };
	int allptypes[][10]={
		{'I','i','i','i','i','i','i','i'},
		{'I','i','i','i','i','i','i','i','i'}
	    };
	char **paramnames;
	int *paramtypes;
	char *script;
	Imlib_Image im=NULL;
	ulong num_index;
	zend_string *str_index;
	imlib_zval *data;

	paramnames=allpnames[index];
	paramtypes=allptypes[index];

	script=estrdup(filter);
	script=_php_bumpmap_stradd(script,"(");

	ZEND_HASH_FOREACH_KEY_VAL(params, num_index, str_index, data)
        {
		if (str_index)
		{
			int match=0;
			int index=0;
			while (paramnames[index])
			{
				if (strcmp(STR_VAL(str_index),paramnames[index])==0)
				{
					char val[32];

					switch(paramtypes[index])
					{
					    case 'I':
						    im=(Imlib_Image)_php_imlib_get_image(Z_RES_P(data)); /* Why is cast to Imlib_Image needed? */
						    script=_php_bumpmap_stradd(script,"map=[]");
						    break;
					    case 'i':
						    convert_to_long_ex(data);
						    sprintf(val,"%d",(int)Z_LVAL_PP(data));
				    		    script=_php_bumpmap_stradd(script,STR_VAL(str_index));
						    script=_php_bumpmap_stradd(script,"=");
						    script=_php_bumpmap_stradd(script,val);
						    break;
					}
					script=_php_bumpmap_stradd(script,",");
					match=1;
					break;
				}
				index++;
			}
			if (!match)
			{
				php_error(E_NOTICE,"Unknown argument %s ignored",str_index);
			}
		}
	} ZEND_HASH_FOREACH_END();

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

int
php_filter_init()
{
   return SUCCESS;
}

void
php_filter_deinit()
{
	return;
}

int
_php_bumpmap_getfilterindex(char*);

int
php_filter_exec(Imlib_Image im, char *filter, HashTable *params)
{
	int index=_php_bumpmap_getfilterindex(filter);
	if (index!=-1)
	{
		int rv;
		imlib_context_set_image(im);
		rv=_php_bumpmap_exec(filter,params,index);
		return rv;
	}
	return FAILURE;
}

int
php_filter_getfiltercount()
{
	return 2;
}

void
php_filter_getfilternames(char** filternames)
{
	filternames[0]="bump_map";
	filternames[1]="bump_map_point";
}

int
_php_bumpmap_getfilterindex(char* filtername)
{
    char** filternames;
    int i;

    filternames=(char**)emalloc(php_filter_getfiltercount()*sizeof(char*));
    php_filter_getfilternames(filternames);
    for (i=0;i<php_filter_getfiltercount();i++)
    {
	if (strcmp(filtername,filternames[i])==0) return i;
    }
    return -1;
}

void
php_filter_getextinfo(char** info)
{
	info[0]="Bump Mapping";
	info[1]="Provides PHP interface to Willem Monsuwe's bump mapping filter.";
	info[2]="Piotr Pawlow (pp@siedziba.pl)";
}

char*
php_filter_getparams(char* filter)
{
	char* filterparams[]={
	    NULL,
	    "Image map, int angle=0, int elevation=30, int depth=0x200, int red=0x200, int green=0x200, int blue=0x200, int ambient=0",
	    "Image map, int x=0, int y=0, int z=30, int depth=0x200, int red=0x200, int green=0x200, int blue=0x200, int ambient=0"
	};
	return filterparams[_php_bumpmap_getfilterindex(filter)+1];
}
ViewGit