Debian Codegraph @

src/mixer2/sleid0r/sleid0r_wipe-barn-door-v.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 unsigned w;
26 unsigned h;
27 double pos;
28 unsigned bw;
29 unsigned bw_scale;
30 unsigned *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-barn-door-v";
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 = "Vertical barn door 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 = "Edges position";
60 }
61 }
62
63 f0r_instance_t f0r_construct(unsigned width, unsigned height)
64 {
65 instance_t *inst;
66 unsigned bw = width / 16;
67 unsigned i;
68
69 inst = malloc(sizeof(*inst) + bw * sizeof(*inst->bwk));
70 if(NULL == inst)
71 return NULL;
72
73 inst->w = width;
74 inst->h = height;
75 inst->pos = 0.0;
76 inst->bw = bw;
77 inst->bw_scale = bw * bw;
78 inst->bwk = (unsigned *)(inst + 1);
79
80 for(i = 0; i < bw; ++i)
81 {
82 if(i < bw / 2)
83 inst->bwk[i] = i * i * 2;
84 else
85 inst->bwk[i] = inst->bw_scale - (bw - i) * (bw - i) * 2;
86 }
87
88 return inst;
89 }
90
91 void f0r_destruct(f0r_instance_t inst)
92 {
93 free(inst);
94 }
95
96 void f0r_set_param_value(f0r_instance_t instance, f0r_param_t param, int param_index)
97 {
98 instance_t *inst = instance;
99
100 if(0 == param_index)
101 inst->pos = *(f0r_param_double *)param;
102 }
103
104 void f0r_get_param_value(f0r_instance_t instance, f0r_param_t param, int param_index)
105 {
106 instance_t *inst = instance;
107
108 if(0 == param_index)
109 *(f0r_param_double *)param = inst->pos;
110 }
111
112 void f0r_update2(
113 f0r_instance_t instance,
114 double time,
115 const uint32_t* inframe1,
116 const uint32_t* inframe2,
117 const uint32_t* inframe3,
118 uint32_t* outframe
119 )
120 {
121 instance_t *inst = instance;
122 unsigned y;
123 int off;
124 unsigned bw, i, dbw1, dbw2;
125 uint8_t *c1, *c2, *co;
126
127 (void)time; /* Unused */
128 (void)inframe3; /* Unused */
129
130 off = (int)((inst->w / 2 + inst->bw) * inst->pos + 0.5) - inst->bw;
131 bw = inst->bw;
132 dbw1 = 0;
133 dbw2 = 0;
134
135 if(off < 0)
136 {
137 bw += off;
138 off = 0;
139 dbw1 = inst->bw - bw;
140 }
141 else if(inst->w / 2 < off + bw)
142 {
143 bw = inst->w / 2 - off;
144 dbw2 = inst->bw - bw;
145 }
146
147 for(y = 0; y < inst->h; ++y)
148 {
149 memcpy(outframe + inst->w * y, inframe1 + inst->w * y,
150 (inst->w / 2 - off - bw) * sizeof(*outframe));
151
152 memcpy(outframe + inst->w * y + inst->w / 2 + off + bw,
153 inframe1 + inst->w * y+ inst->w / 2 + off + bw,
154 (inst->w / 2 - off - bw) * sizeof(*outframe));
155
156 memcpy(outframe + inst->w * y + inst->w / 2 - off,
157 inframe2 + inst->w * y + inst->w / 2 - off,
158 off * 2 * sizeof(*outframe));
159
160 c1 = (uint8_t *)(inframe1 + inst->w * y + inst->w / 2 - off - bw);
161 c2 = (uint8_t *)(inframe2 + inst->w * y + inst->w / 2 - off - bw);
162 co = (uint8_t *)(outframe + inst->w * y + inst->w / 2 - off - bw);
163 for(i = 0; i < bw * 4; ++i)
164 {
165 unsigned k = inst->bwk[i / 4 + dbw2];
166
167 *co = (*c1 * (inst->bw_scale - k) + *c2 * k + inst->bw_scale / 2) / inst->bw_scale;
168 ++c1;
169 ++c2;
170 ++co;
171 }
172
173 c1 = (uint8_t *)(inframe1 + inst->w * y + inst->w / 2 + off);
174 c2 = (uint8_t *)(inframe2 + inst->w * y + inst->w / 2 + off);
175 co = (uint8_t *)(outframe + inst->w * y + inst->w / 2 + off);
176 for(i = 0; i < bw * 4; ++i)
177 {
178 unsigned k = inst->bwk[i / 4 + dbw1];
179
180 *co = (*c1 * k + *c2 * (inst->bw_scale - k) + inst->bw_scale / 2) / inst->bw_scale;
181 ++c1;
182 ++c2;
183 ++co;
184 }
185 }
186 }
187
188
189