Debian Codegraph @

src/mixer2/sleid0r/sleid0r_wipe-down.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-down";
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 = "Wipe from top to bottom";
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 = "Edge position";
60 }
61 }
62
63 f0r_instance_t f0r_construct(unsigned width, unsigned height)
64 {
65 instance_t *inst;
66 unsigned bw = height / 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, x;
123 int off;
124 unsigned bw, dbw;
125 uint8_t *c1, *c2, *co;
126
127 (void)time; /* Unused */
128 (void)inframe3; /* Unused */
129
130 off = (int)((inst->h + inst->bw) * inst->pos + 0.5) - inst->bw;
131 bw = inst->bw;
132 dbw = 0;
133
134 if(off < 0)
135 {
136 bw += off;
137 off = 0;
138 dbw = inst->bw - bw;
139 }
140 else if(inst->h < off + bw)
141 bw = inst->h - off;
142
143 memcpy(outframe, inframe2, inst->w * off * sizeof(*outframe));
144
145 memcpy(outframe + inst->w * (off + bw), inframe1 + inst->w * (off + bw),
146 inst->w * (inst->h - off - bw) * sizeof(*outframe));
147
148 c1 = (uint8_t *)(inframe1 + inst->w * off);
149 c2 = (uint8_t *)(inframe2 + inst->w * off);
150 co = (uint8_t *)(outframe + inst->w * off);
151 for(y = 0; y < bw; ++y)
152 {
153 unsigned k = inst->bwk[y + dbw];
154
155 for(x = 0; x < inst->w * 4; ++x)
156 {
157 *co = (*c1 * k + *c2 * (inst->bw_scale - k) + inst->bw_scale / 2) / inst->bw_scale;
158 ++c1;
159 ++c2;
160 ++co;
161 }
162
163 }
164 }
165
166
167