Debian Codegraph @

src/filter/flippo/flippo.c

raw symbols SCIP
1 /* flippo.c */
2
3 /*
4 * 02/03/2004 j.s.s. optimized the whole process
5 * 07/11/2004 c.e. prelz
6 *
7 * My first frei0r effect - simple flipping
8 */
9
10 #include "frei0r.h"
11
12 #include <assert.h>
13 #include <stdlib.h>
14 #include <string.h>
15
16 typedef struct flippo_instance
17 {
18 unsigned int width, height;
19 char flippox, flippoy;
20 } flippo_instance_t;
21
22 int f0r_init()
23 {
24 return 1;
25 }
26
27 void f0r_deinit()
28 {
29 }
30
31 void f0r_get_plugin_info(f0r_plugin_info_t* flippoInfo)
32 {
33 flippoInfo->name = "Flippo";
34 flippoInfo->author = "Carlo Emilio, Jean-Sebastien Senecal";
35 flippoInfo->plugin_type = F0R_PLUGIN_TYPE_FILTER;
36 flippoInfo->color_model = F0R_COLOR_MODEL_PACKED32;
37 flippoInfo->frei0r_version = FREI0R_MAJOR_VERSION;
38 flippoInfo->major_version = 0;
39 flippoInfo->minor_version = 1;
40 flippoInfo->num_params = 2;
41 flippoInfo->explanation = "Flipping in x and y axis";
42 }
43
44 void f0r_get_param_info(f0r_param_info_t* info, int param_index)
45 {
46 switch(param_index)
47 {
48 case 0:
49 info->name="X axis";
50 info->type=F0R_PARAM_BOOL;
51 info->explanation="Flipping on the horizontal axis";
52 break;
53 case 1:
54 info->name="Y axis";
55 info->type=F0R_PARAM_BOOL;
56 info->explanation = "Flipping on the vertical axis";
57 break;
58 }
59 }
60
61 f0r_instance_t f0r_construct(unsigned int width,unsigned int height)
62 {
63 flippo_instance_t *inst=(flippo_instance_t*)calloc(1, sizeof(*inst));
64
65 inst->width=width;
66 inst->height=height;
67
68 return (f0r_instance_t)inst;
69 }
70
71 void f0r_destruct(f0r_instance_t instance)
72 {
73 flippo_instance_t* inst = (flippo_instance_t*)instance;
74
75 free(inst);
76 }
77
78 void f0r_set_param_value(f0r_instance_t instance,
79 f0r_param_t param,int param_index)
80 {
81 assert(instance);
82 flippo_instance_t *inst=(flippo_instance_t*)instance;
83
84 switch(param_index)
85 {
86 case 0:
87 inst->flippox=( *((double*)param) >= 0.5 );
88 break;
89 case 1:
90 inst->flippoy=( *((double*)param) >= 0.5 );
91 break;
92 }
93 }
94
95 void f0r_get_param_value(f0r_instance_t instance,
96 f0r_param_t param,int param_index)
97 {
98 assert(instance);
99
100 flippo_instance_t *inst=(flippo_instance_t*)instance;
101
102 switch(param_index)
103 {
104 case 0:
105 *((double*)param)=(inst->flippox ? 1.0 : 0.0);
106 break;
107 case 1:
108 *((double*)param)=(inst->flippoy ? 1.0 : 0.0);
109 break;
110 }
111 }
112
113 void f0r_update(f0r_instance_t instance,double time,
114 const uint32_t *inframe, uint32_t *outframe)
115 {
116 assert(instance);
117
118 flippo_instance_t* inst=(flippo_instance_t*)instance;
119 unsigned int w=inst->width;
120 unsigned int h=inst->height;
121 unsigned int len=w*h;
122 unsigned int twice_w = 2*w;
123 unsigned int rowsize = w*sizeof(uint32_t);
124 unsigned int i;
125
126 if (inst->flippox)
127 {
128 if (inst->flippoy)
129 {
130 // flip and flop
131 inframe += len-1; // point to the end
132 while (len--)
133 *outframe++ = *inframe--;
134 }
135 else
136 {
137 // flip only
138 inframe += w-1; // point to the end of current row
139 while (h--)
140 {
141 i=w;
142 while (i--)
143 *outframe++ = *inframe--;
144 inframe += twice_w;
145 }
146 }
147 }
148 else
149 {
150 if (inst->flippoy)
151 {
152 // flop only
153 inframe += len - w - 1; // point to start of last row
154 while (h--)
155 {
156 memcpy(outframe, inframe, rowsize);
157 outframe += w;
158 inframe -= w;
159 }
160 }
161 else
162 {
163 // no flip, no flop
164 memcpy(outframe, inframe, len*sizeof(uint32_t));
165 }
166 }
167
168 }
169