Debian Codegraph @

src/mixer2/sleid0r/sleid0r_wipe-rect.c

raw symbols SCIP
1 /*
2 Copyright (C) 2013 Vadim Druzhin <[email protected]>
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include <stdlib.h>
19 #include <stdint.h>
20 #include <string.h>
21 #include <frei0r.h>
22
23 typedef struct instance_s
24 {
25 int w;
26 int h;
27 double pos;
28 int bw;
29 int bw_scale;
30 int *bwk;
31 } instance_t;
32
33 int f0r_init(void)
34 {
35 return 1;
36 }
37
38 void f0r_deinit(void) {}
39
40 void f0r_get_plugin_info(f0r_plugin_info_t *info)
41 {
42 info->name = "wipe-rect";
43 info->author = "Vadim Druzhin";
44 info->plugin_type = F0R_PLUGIN_TYPE_MIXER2;
45 info->color_model = F0R_COLOR_MODEL_RGBA8888;
46 info->frei0r_version = FREI0R_MAJOR_VERSION;
47 info->major_version = 0;
48 info->minor_version = 1;
49 info->num_params = 1;
50 info->explanation = "Rectangular wipe";
51 }
52
53 void f0r_get_param_info(f0r_param_info_t *info, int index)
54 {
55 if(0 == index)
56 {
57 info->name = "position";
58 info->type = F0R_PARAM_DOUBLE;
59 info->explanation = "Rectangle size";
60 }
61 }
62
63 f0r_instance_t f0r_construct(unsigned width, unsigned height)
64 {
65 instance_t *inst;
66 unsigned bw;
67 unsigned i;
68
69 if(height < width)
70 bw = height / 16;
71 else
72 bw = width / 16;
73
74 inst = malloc(sizeof(*inst) + bw * sizeof(*inst->bwk));
75 if(NULL == inst)
76 return NULL;
77
78 inst->w = width;
79 inst->h = height;
80 inst->pos = 0.0;
81 inst->bw = bw;
82 inst->bw_scale = bw * bw;
83 inst->bwk = (int *)(inst + 1);
84
85 for(i = 0; i < bw; ++i)
86 {
87 if(i < bw / 2)
88 inst->bwk[i] = i * i * 2;
89 else
90 inst->bwk[i] = inst->bw_scale - (bw - i) * (bw - i) * 2;
91 }
92
93 return inst;
94 }
95
96 void f0r_destruct(f0r_instance_t inst)
97 {
98 free(inst);
99 }
100
101 void f0r_set_param_value(f0r_instance_t instance, f0r_param_t param, int param_index)
102 {
103 instance_t *inst = instance;
104
105 if(0 == param_index)
106 inst->pos = *(f0r_param_double *)param;
107 }
108
109 void f0r_get_param_value(f0r_instance_t instance, f0r_param_t param, int param_index)
110 {
111 instance_t *inst = instance;
112
113 if(0 == param_index)
114 *(f0r_param_double *)param = inst->pos;
115 }
116
117 void f0r_update2(
118 f0r_instance_t instance,
119 double time,
120 const uint32_t* inframe1,
121 const uint32_t* inframe2,
122 const uint32_t* inframe3,
123 uint32_t* outframe
124 )
125 {
126 instance_t *inst = instance;
127 int y, x;
128 int off_h, off_v;
129 uint8_t *c1, *c2, *co;
130 int b, k;
131 int x0, x1;
132 int y0, y1;
133
134 (void)time; /* Unused */
135 (void)inframe3; /* Unused */
136
137 off_v = (int)((inst->w / 2 + inst->bw) * inst->pos + 0.5) - inst->bw;
138
139 off_h = (int)((inst->h / 2 + inst->bw) * inst->pos + 0.5) - inst->bw;
140
141 if(inst->h / 2 > off_h + inst->bw)
142 {
143 memcpy(outframe, inframe1,
144 inst->w * (inst->h / 2 - off_h - inst->bw) * sizeof(*outframe));
145
146 memcpy(outframe + inst->w * (inst->h / 2 + off_h + inst->bw),
147 inframe1 + inst->w * (inst->h / 2 + off_h + inst->bw),
148 inst->w * (inst->h / 2 - off_h - inst->bw) * sizeof(*outframe));
149 }
150
151 if(inst->w / 2 > off_v + inst->bw)
152 {
153 for(y = inst->h / 2 - off_h - inst->bw; y < inst->h / 2 + off_h + inst->bw; ++y)
154 {
155 if(y < 0 || y >= inst->h)
156 continue;
157
158 memcpy(outframe + inst->w * y, inframe1 + inst->w * y,
159 (inst->w / 2 - off_v - inst->bw) * sizeof(*outframe));
160
161 memcpy(outframe + inst->w * y + inst->w / 2 + off_v + inst->bw,
162 inframe1 + inst->w * y + inst->w / 2 + off_v + inst->bw,
163 (inst->w / 2 - off_v - inst->bw) * sizeof(*outframe));
164 }
165 }
166
167 if(off_v > 0)
168 {
169 for(y = inst->h / 2 - off_h; y < inst->h / 2 + off_h; ++y)
170 memcpy(
171 outframe + inst->w * y + inst->w / 2 - off_v,
172 inframe2 + inst->w * y + inst->w / 2 - off_v,
173 off_v * 2 * sizeof(*outframe)
174 );
175 }
176
177 for(b = 0; b < inst->bw; ++b)
178 {
179 k = inst->bwk[b];
180
181 y = inst->h / 2 - off_h - inst->bw + b;
182 if(y < 0)
183 continue;
184
185 x0 = inst->w / 2 - off_v - inst->bw + b;
186 if(x0 < 0)
187 x0 = 0;
188
189 x1 = inst->w / 2 + off_v + inst->bw - b;
190 if(x1 > inst->w)
191 x1 = inst->w;
192
193 c1 = (uint8_t *)(inframe1 + inst->w * y + x0);
194 c2 = (uint8_t *)(inframe2 + inst->w * y + x0);
195 co = (uint8_t *)(outframe + inst->w * y + x0);
196
197 for(x = 0; x < (x1 - x0) * 4; ++x)
198 {
199 *co = (*c1 * (inst->bw_scale - k) + *c2 * k + inst->bw_scale / 2) / inst->bw_scale;
200 ++c1;
201 ++c2;
202 ++co;
203 }
204 }
205
206 for(b = 0; b < inst->bw; ++b)
207 {
208 k = inst->bwk[b];
209
210 y = inst->h / 2 + off_h + b;
211 if(y >= inst->h)
212 continue;
213
214 x0 = inst->w / 2 - off_v - b;
215 if(x0 < 0)
216 x0 = 0;
217
218 x1 = inst->w / 2 + off_v + b + 1;
219 if(x1 > inst->w)
220 x1 = inst->w;
221
222 c1 = (uint8_t *)(inframe1 + inst->w * y + x0);
223 c2 = (uint8_t *)(inframe2 + inst->w * y + x0);
224 co = (uint8_t *)(outframe + inst->w * y + x0);
225
226 for(x = 0; x < (x1 - x0) * 4; ++x)
227 {
228 *co = (*c1 * k + *c2 * (inst->bw_scale - k) + inst->bw_scale / 2) / inst->bw_scale;
229 ++c1;
230 ++c2;
231 ++co;
232 }
233 }
234
235 for(b = 0; b < inst->bw * 4; ++b)
236 {
237 k = inst->bwk[b / 4];
238
239 x0 = inst->w / 2 - off_v - inst->bw;
240 if(x0 + b / 4 < 0)
241 continue;
242
243 y0 = inst->h / 2 - off_h - inst->bw + b / 4;
244 if(y0 < 0)
245 y0 = 0;
246
247 y1 = inst->h / 2 + off_h + inst->bw - b / 4;
248 if(y1 > inst->h)
249 y1 = inst->h;
250
251 c1 = (uint8_t *)(inframe1 + inst->w * y0 + x0) + b;
252 c2 = (uint8_t *)(inframe2 + inst->w * y0 + x0) + b;
253 co = (uint8_t *)(outframe + inst->w * y0 + x0) + b;
254
255 for(y = 0; y < y1 - y0; ++y)
256 {
257 *co = (*c1 * (inst->bw_scale - k) + *c2 * k + inst->bw_scale / 2) / inst->bw_scale;
258 c1 += inst->w * 4;
259 c2 += inst->w * 4;
260 co += inst->w * 4;
261 }
262 }
263
264 for(b = 0; b < inst->bw * 4; ++b)
265 {
266 k = inst->bwk[b / 4];
267
268 x0 = inst->w / 2 + off_v;
269 if(x0 + b / 4 >= inst->w)
270 continue;
271
272 y0 = inst->h / 2 - off_h - b / 4;
273 if(y0 < 0)
274 y0 = 0;
275
276 y1 = inst->h / 2 + off_h + b / 4 + 1;
277 if(y1 > inst->h)
278 y1 = inst->h;
279
280 c1 = (uint8_t *)(inframe1 + inst->w * y0 + x0) + b;
281 c2 = (uint8_t *)(inframe2 + inst->w * y0 + x0) + b;
282 co = (uint8_t *)(outframe + inst->w * y0 + x0) + b;
283
284 for(y = 0; y < y1 - y0; ++y)
285 {
286 *co = (*c1 * k + *c2 * (inst->bw_scale - k) + inst->bw_scale / 2) / inst->bw_scale;
287 c1 += inst->w * 4;
288 c2 += inst->w * 4;
289 co += inst->w * 4;
290 }
291 }
292 }
293
294
295