#include "php.h" #include "php_imlib.h" #define php_filter_init php_testfilter_LTX_php_filter_init #define php_filter_deinit php_testfilter_LTX_php_filter_deinit #define php_filter_exec php_testfilter_LTX_php_filter_exec #define php_filter_getfiltercount php_testfilter_LTX_php_filter_getfiltercount #define php_filter_getfilternames php_testfilter_LTX_php_filter_getfilternames #define php_filter_getextinfo php_testfilter_LTX_php_filter_getextinfo #define php_filter_getparams php_testfilter_LTX_php_filter_getparams static int _php_testfilter_tint(Imlib_Image im, HashTable* params) { Imlib_Image imge = im; Imlib_Image anoim; HashPosition pos; Imlib_Color_Modifier cm; DATA8 atab[256]; int x = 0, y = 0, w = 0, h = 0; DATA8 r = 255, b = 255, g = 255, a = 255; /* printf( "php_testfilter.c: tint called\n" ); */ /* Set friendly defaults */ imlib_context_set_image( imge ); w = imlib_image_get_width(); h = imlib_image_get_height(); 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) { zval **data; zend_hash_get_current_data_ex(params,&data,&pos); convert_to_long_ex(data); if (!strcmp(str_index,"red")) r=Z_LVAL_PP(data); if (!strcmp(str_index,"blue")) b=Z_LVAL_PP(data); if (!strcmp(str_index,"green")) g=Z_LVAL_PP(data); if (!strcmp(str_index,"x")) x=Z_LVAL_PP(data); if (!strcmp(str_index,"y")) y=Z_LVAL_PP(data); if (!strcmp(str_index,"w")) w=Z_LVAL_PP(data); if (!strcmp(str_index,"h")) h=Z_LVAL_PP(data); if (!strcmp(str_index,"alpha")) a=Z_LVAL_PP(data); } zend_hash_move_forward_ex(params,&pos); } /* zend_printf( "Using values red=%d,blue=%d,green=%d,x=%d,y=%d,height=%d,width=%d,alpha=%d\n", r,b,g,x,y,w,h,a ); */ anoim = imlib_create_image( w, h ); cm = imlib_create_color_modifier(); imlib_context_set_color_modifier(cm); imlib_context_set_image(anoim); imlib_context_set_color(r, g, b, 255); imlib_image_fill_rectangle(0, 0, w, h); imlib_context_set_blend(1); imlib_image_set_has_alpha(1); memset(atab, a, sizeof(atab)); imlib_set_color_modifier_tables(NULL, NULL, NULL, atab); imlib_apply_color_modifier_to_rectangle(0, 0, w, h); imlib_context_set_image( imge ); imlib_blend_image_onto_image( anoim, 0, 0, 0, w, h, x, y, w, h); imlib_free_color_modifier(); imlib_context_set_image(anoim); imlib_free_image_and_decache(); imlib_context_set_image(imge); 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, "tint")) { return _php_testfilter_tint(im,params); } return FAILURE; } int php_filter_getfiltercount() { return 1; } void php_filter_getfilternames(char** filternames) { filternames[0]="tint"; } void php_filter_getextinfo(char** info) { info[0]="Test Filter"; info[1]="Just a simple native php_imlib filter, based on Chriss Ross' test filter from imlib2 package."; info[2]="Piotr Pawlow (pp@siedziba.pl)"; } char* php_filter_getparams(char* filter) { if (!strcmp(filter, "tint")) return "int x=0, int y=0, int w=image_width, int h=image_height, int red=255, int green=255, int blue=255, int alpha=255"; return NULL; }