Debian Codegraph @

src/mixer2/sleid0r/sleid0r_slide-up.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 } instance_t;
29
30 int f0r_init(void)
31 {
32 return 1;
33 }
34
35 void f0r_deinit(void) {}
36
37 void f0r_get_plugin_info(f0r_plugin_info_t *info)
38 {
39 info->name = "slide-up";
40 info->author = "Vadim Druzhin";
41 info->plugin_type = F0R_PLUGIN_TYPE_MIXER2;
42 info->color_model = F0R_COLOR_MODEL_RGBA8888;
43 info->frei0r_version = FREI0R_MAJOR_VERSION;
44 info->major_version = 0;
45 info->minor_version = 1;
46 info->num_params = 1;
47 info->explanation = "Slide from bottom to top";
48 }
49
50 void f0r_get_param_info(f0r_param_info_t *info, int index)
51 {
52 if(0 == index)
53 {
54 info->name = "position";
55 info->type = F0R_PARAM_DOUBLE;
56 info->explanation = "Slide position";
57 }
58 }
59
60 f0r_instance_t f0r_construct(unsigned width, unsigned height)
61 {
62 instance_t *inst;
63
64 inst = calloc(1, sizeof(*inst));
65 if(NULL == inst)
66 return NULL;
67
68 inst->w = width;
69 inst->h = height;
70 inst->pos = 0.0;
71
72 return inst;
73 }
74
75 void f0r_destruct(f0r_instance_t inst)
76 {
77 free(inst);
78 }
79
80 void f0r_set_param_value(f0r_instance_t instance, f0r_param_t param, int param_index)
81 {
82 instance_t *inst = instance;
83
84 if(0 == param_index)
85 inst->pos = *(f0r_param_double *)param;
86 }
87
88 void f0r_get_param_value(f0r_instance_t instance, f0r_param_t param, int param_index)
89 {
90 instance_t *inst = instance;
91
92 if(0 == param_index)
93 *(f0r_param_double *)param = inst->pos;
94 }
95
96 void f0r_update2(
97 f0r_instance_t instance,
98 double time,
99 const uint32_t* inframe1,
100 const uint32_t* inframe2,
101 const uint32_t* inframe3,
102 uint32_t* outframe
103 )
104 {
105 instance_t *inst = instance;
106 double t;
107 int off;
108 unsigned bw;
109 unsigned xy;
110 uint32_t px;
111
112 (void)time; /* Unused */
113 (void)inframe3; /* Unused */
114
115 if(inst->pos < 0.5)
116 {
117 t = inst->pos;
118 t = t * t * 2.0;
119 }
120 else
121 {
122 t = 1.0 - inst->pos;
123 t = 1.0 - t * t * 2.0;
124 }
125
126 bw = inst->h / 64;
127
128 off = (int)((inst->h + bw) * t + 0.5) - bw;
129
130 if(off < 0)
131 {
132 bw += off;
133 off = 0;
134 }
135 else if(inst->h < off + bw)
136 bw = inst->h - off;
137
138 memcpy(outframe, inframe1,
139 (inst->h - off - bw) * inst->w * sizeof(*outframe));
140
141 for(xy = (inst->h - off - bw) * inst->w; xy < (inst->h - off) * inst->w; ++xy)
142 {
143 px = (inframe1[xy] >> 2) & 0x3F3F3F3F;
144 ((uint8_t *)(&px))[3] = ((uint8_t *)(inframe1 + xy))[3];
145 outframe[xy] = px;
146 }
147
148 memcpy(outframe + (inst->h - off) * inst->w, inframe2,
149 off * inst->w * sizeof(*outframe));
150 }
151
152
153