summaryrefslogtreecommitdiffhomepage
path: root/filters/php_testfilter.c
blob: ccc2268cb482b89e24eef0df8276a0850726ea44 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#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;
      ulong num_index;
      zend_string *str_index;
      zval *data;

      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_FOREACH_KEY_VAL(params, num_index, str_index, data)
      {
        if (str_index)
        {
          convert_to_long_ex(data);
          if (!strcmp(str_index->val,"red")) r=Z_LVAL_P(data);
          if (!strcmp(str_index->val,"blue")) b=Z_LVAL_P(data);
          if (!strcmp(str_index->val,"green")) g=Z_LVAL_P(data);
          if (!strcmp(str_index->val,"x")) x=Z_LVAL_P(data);
          if (!strcmp(str_index->val,"y")) y=Z_LVAL_P(data);
          if (!strcmp(str_index->val,"w")) w=Z_LVAL_P(data);
          if (!strcmp(str_index->val,"h")) h=Z_LVAL_P(data);
          if (!strcmp(str_index->val,"alpha")) a=Z_LVAL_P(data);
        }
      } ZEND_HASH_FOREACH_END();
/*
      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;
}