Debian Codegraph @

src/filter/gateweave/gateweave.c

raw symbols SCIP
1 #cxx . . $ `<file>/src/filter/gateweave/gateweave.c`/include <stdlib.h>
2 #include <math.h>
3 #include "frei0r.h"cxx . . $ `<file>/include/frei0r.h`/
4 #include "frei0r/math.h"cxx . . $ `<file>/include/frei0r/math.h`/
5
6
7 // let's try to walk through everything because i'm a moron
8 // this is the struct for the effect instance
9 typedef struct gateweave_instancecxx . . $ gateweave_instance#
10 {
11 // image dimensions
12 unsigned int widthcxx . . $ gateweave_instance#width.;
13 unsigned int heightcxx . . $ gateweave_instance#height.;
14
15 // parameters
16 double intervalcxx . . $ gateweave_instance#interval.;
17 double max_move_xcxx . . $ gateweave_instance#max_move_x.;
18 double max_move_ycxx . . $ gateweave_instance#max_move_y.;
19
20 // other variables that the effect uses to keep track of things
21 double next_key_xcxx . . $ gateweave_instance#next_key_x.;
22 double next_key_ycxx . . $ gateweave_instance#next_key_y.;
23 double prev_key_xcxx . . $ gateweave_instance#prev_key_x.;
24 double prev_key_ycxx . . $ gateweave_instance#prev_key_y.;
25
26 } gateweave_instance_tcxx . . $ gateweave_instance_t#;
27
28
29 // these functions are for the effect
30 static double gateweave_random_rangecxx . . $ gateweave_random_range(d8e7e0733fa41c87).(double range, double last)
31 {
32 if(range <= 0)
33 {
34 return 0;
35 }
36
37 // the maximum shift is 10 pixels
38 // since range includes fractional values, we want to multiply it by 100
39 // this will generate an integer between -100 and 100 for the shift
40 // and then we divide by 100 to receive a decimal answer between -10.00 and 10.00
41 range *= 10;
42 int int_range = range * 100;
43 int_range = (randcxx . . $ rand(b126dc7c1de90089).() % (int_range * 2)) - int_range;
44 double ret = int_range / 100.0;
45
46 // we don't want to generate a value similar to one we already generated twice in a row
47 ret = CLAMPcxx . . $ `include/frei0r/math.h:48:9`!(ret, -range, range);
48 if((ret > 0 && ret >= last - 0.12) || (ret < 0 && ret <= last + 0.12))
49 {
50 ret *= -1;
51 }
52 return ret;
53 }
54
55 static inline double gateweave_lerpcxx . . $ gateweave_lerp(7678bba071383ab).(double v0, double v1, double t)
56 {
57 return v0 + t * (v1 - v0);
58 }
59
60
61 // this function mixes the colors of two pixels
62 // a is the original pixel that will be changed
63 // b is the second pixel that will not be changed
64 // the amount is how much of the second pixel will be mixed
65 // an amount of 1 means pixel a will be equal to pixel b
66 // an amount of 0 means pixel a will be equal to pixel a (no change)
67 // an amount of 0.5 means pixel a will be equal to 0.5 * pixel a + 0.5 * pixel b
68 static uint32_tcxx . . $ uint32_t# gateweave_blend_colorcxx . . $ gateweave_blend_color(354cee07270d3fc8).(uint32_tcxx . . $ uint32_t# a, uint32_tcxx . . $ uint32_t# b, double amount)
69 {
70 uint8_tcxx . . $ uint8_t# c_a;
71 uint8_tcxx . . $ uint8_t# c_b;
72 uint8_tcxx . . $ uint8_t# c_g;
73 uint8_tcxx . . $ uint8_t# c_r;
74 uint32_tcxx . . $ uint32_t# output;
75
76 // RRGGBBAA
77 // 0xFFFFFFFF
78 c_a = CLAMP0255cxx . . $ CLAMP0255(bc0fba5608a0bfe7).(((a & 0xFF000000) >> 24) * (1 - amount) + ((b & 0xFF000000) >> 24) * (amount));
79 c_b = CLAMP0255cxx . . $ CLAMP0255(bc0fba5608a0bfe7).(((a & 0x00FF0000) >> 16) * (1 - amount) + ((b & 0x00FF0000) >> 16) * (amount));
80 c_g = CLAMP0255cxx . . $ CLAMP0255(bc0fba5608a0bfe7).(((a & 0x0000FF00) >> 8) * (1 - amount) + ((b & 0x0000FF00) >> 8) * (amount));
81 c_r = CLAMP0255cxx . . $ CLAMP0255(bc0fba5608a0bfe7).(((a & 0x000000FF)) * (1 - amount) + ((b & 0x000000FF)) * (amount));
82
83 output = (output & 0xFFFFFF00) | (uint32_tcxx . . $ uint32_t#)c_r;
84 output = (output & 0xFFFF00FF) | ((uint32_tcxx . . $ uint32_t#)c_g << 8);
85 output = (output & 0xFF00FFFF) | ((uint32_tcxx . . $ uint32_t#)c_b << 16);
86 output = (output & 0x00FFFFFF) | ((uint32_tcxx . . $ uint32_t#)c_a << 24);
87
88 return output;
89 }
90
91 // this function is the one that ultimately manipulates the image
92 // it shifts the image and can do so to a value less than one pixel
93 static inline void gateweave_shift_picturecxx . . $ gateweave_shift_picture(1970dedbc8e6d445).(const uint32_tcxx . . $ uint32_t#* in, uint32_tcxx . . $ uint32_t#* out, double shift_x, double shift_y, int w, int h)
94 {
95 uint32_tcxx . . $ uint32_t#* buf = (uint32_tcxx . . $ uint32_t#*)calloccxx . . $ calloc(63a7bf2941bfcd7a).(w * h, sizeof(uint32_tcxx . . $ uint32_t#));
96
97 // first we shift to the nearest whole pixel
98 int int_shift_x = shift_x;
99 int int_shift_y = shift_y;
100 int pixel_shift = int_shift_x + (int_shift_y * w);
101 for(unsigned int i = 0; i < w * h; i++)
102 {
103 if(i + pixel_shift < 0 || i + pixel_shift >= w * h)
104 {
105 *(buf + i) = 0;
106 }
107 else
108 {
109 *(buf + i) = *(in + i + pixel_shift);
110 }
111 }
112
113 // then we shift the fractional component
114 // let's think about how this works
115 // let's suppose we shift left 1.5 pixels and shift down 1.25 pixels
116 // after shifting 1 pixel left and 1 pixel down, we still have the 0.5 and 0.25 shifts left to do
117 // to do this we want each pixel to equal 50% the current pixel and 50% the pixel to its left
118 // we also want each pixel to equal 75% the current pixel and 25% the pixel below it
119 // but this isn't actually possible to do
120 shift_x -= int_shift_x;
121 shift_y -= int_shift_y;
122
123 int shift_component_x;
124 int shift_component_y;
125
126 char larger_x_comp = 0;
127 if(fabs(shift_x) > fabs(shift_y))
128 {
129 larger_x_comp = 1;
130 }
131
132 if(shift_x < 0)
133 {
134 shift_component_x = -1;
135 }
136 else
137 {
138 shift_component_x = 1;
139 }
140 if(shift_y < 0)
141 {
142 shift_component_y = -w;
143 }
144 else
145 {
146 shift_component_y = w;
147 }
148
149 uint32_tcxx . . $ uint32_t# v = 0;
150 for(unsigned int i = 0; i < w * h; i++)
151 {
152 if(i + shift_component_x >= 0 && i + shift_component_x < w * h &&
153 i + shift_component_y >= 0 && i + shift_component_y < w * h &&
154 i + shift_component_x + shift_component_y >= 0 && i + shift_component_x + shift_component_y < w * h)
155 {
156 if(larger_x_comp)
157 {
158 v = gateweave_blend_colorcxx . . $ gateweave_blend_color(354cee07270d3fc8).(*(buf + i + shift_component_x), *(buf + i + shift_component_x + shift_component_y), shift_y);
159 *(out + i) = gateweave_blend_colorcxx . . $ gateweave_blend_color(354cee07270d3fc8).(*(buf + i), v, shift_x);
160 }
161 else
162 {
163 v = gateweave_blend_colorcxx . . $ gateweave_blend_color(354cee07270d3fc8).(*(buf + i + shift_component_y), *(buf + i + shift_component_x + shift_component_y), shift_x);
164 *(out + i) = gateweave_blend_colorcxx . . $ gateweave_blend_color(354cee07270d3fc8).(*(buf + i), v, shift_y);
165 }
166 }
167 }
168 freecxx . . $ free(5d22bdacc48458e8).(buf);
169 }
170
171
172 // these functions are for frei0r
173 // mostly copy/paste/slightly modified from the other frei0r effects
174 int f0r_initcxx . . $ f0r_init(b126dc7c1de90089).()
175 {
176 return 1;
177 }
178
179 void f0r_deinitcxx . . $ f0r_deinit(49f6e7a06ebc5aa8).()
180 {}
181
182 void f0r_get_plugin_infocxx . . $ f0r_get_plugin_info(35d753456c0ea59c).(f0r_plugin_info_tcxx . . $ f0r_plugin_info_t#* info)
183 {
184 info->namecxx . . $ f0r_plugin_info#name. = "Gate Weave";
185 info->authorcxx . . $ f0r_plugin_info#author. = "esmane";
186 info->explanationcxx . . $ f0r_plugin_info#explanation. = "Randomly moves frame around to simulate film gate weave.";
187 info->plugin_typecxx . . $ f0r_plugin_info#plugin_type. = F0R_PLUGIN_TYPE_FILTERcxx . . $ `include/frei0r.h:247:9`!;
188 info->color_modelcxx . . $ f0r_plugin_info#color_model. = F0R_COLOR_MODEL_RGBA8888cxx . . $ `include/frei0r.h:308:9`!;
189 info->frei0r_versioncxx . . $ f0r_plugin_info#frei0r_version. = FREI0R_MAJOR_VERSIONcxx . . $ `include/frei0r.h:217:9`!;
190 info->major_versioncxx . . $ f0r_plugin_info#major_version. = 0;
191 info->minor_versioncxx . . $ f0r_plugin_info#minor_version. = 2;
192 info->num_paramscxx . . $ f0r_plugin_info#num_params. = 3;
193 }
194
195 void f0r_get_param_infocxx . . $ f0r_get_param_info(a9f9aa7954cc4a37).(f0r_param_info_tcxx . . $ f0r_param_info_t#* info, int param_index)
196 {
197 switch(param_index)
198 {
199 case 0:
200 info->namecxx . . $ f0r_param_info#name. = "Interval";
201 info->explanationcxx . . $ f0r_param_info#explanation. = "The amount of time before the position is randomized again. The larger the number the slower the picture will move.";
202 info->typecxx . . $ f0r_param_info#type. = F0R_PARAM_DOUBLEcxx . . $ `include/frei0r.h:383:9`!;
203 break;
204
205 case 1:
206 info->namecxx . . $ f0r_param_info#name. = "Maximum Horizontal Movement";
207 info->explanationcxx . . $ f0r_param_info#explanation. = "The maximum distance the picture could move left or right. The larger the number the more the picture moves and the less subtle the effect.";
208 info->typecxx . . $ f0r_param_info#type. = F0R_PARAM_DOUBLEcxx . . $ `include/frei0r.h:383:9`!;
209 break;
210
211 case 2:
212 info->namecxx . . $ f0r_param_info#name. = "Maximum Vertical Movement";
213 info->explanationcxx . . $ f0r_param_info#explanation. = "The maximum distance the picture could move up or down. The larger the number the more the picture moves and the less subtle the effect.";
214 info->typecxx . . $ f0r_param_info#type. = F0R_PARAM_DOUBLEcxx . . $ `include/frei0r.h:383:9`!;
215 break;
216 }
217 }
218
219 f0r_instance_tcxx . . $ f0r_instance_t# f0r_constructcxx . . $ f0r_construct(da3f471cd007a696).(unsigned int width, unsigned int height)
220 {
221 gateweave_instance_tcxx . . $ gateweave_instance_t#* inst = (gateweave_instance_tcxx . . $ gateweave_instance_t#*)calloccxx . . $ calloc(63a7bf2941bfcd7a).(1, sizeof(*inst));
222
223 inst->widthcxx . . $ gateweave_instance#width. = width;
224 inst->heightcxx . . $ gateweave_instance#height. = height;
225 inst->intervalcxx . . $ gateweave_instance#interval. = 0.6;
226 inst->max_move_xcxx . . $ gateweave_instance#max_move_x. = 0.2;
227 inst->max_move_ycxx . . $ gateweave_instance#max_move_y. = 0.2;
228
229 // other variables that the effect uses to keep track of things
230 inst->next_key_xcxx . . $ gateweave_instance#next_key_x. = gateweave_random_rangecxx . . $ gateweave_random_range(d8e7e0733fa41c87).(inst->max_move_xcxx . . $ gateweave_instance#max_move_x., 0);
231 inst->next_key_ycxx . . $ gateweave_instance#next_key_y. = gateweave_random_rangecxx . . $ gateweave_random_range(d8e7e0733fa41c87).(inst->max_move_ycxx . . $ gateweave_instance#max_move_y., 0);
232 inst->prev_key_xcxx . . $ gateweave_instance#prev_key_x. = 0;
233 inst->prev_key_ycxx . . $ gateweave_instance#prev_key_y. = 0;
234
235 return (f0r_instance_tcxx . . $ f0r_instance_t#)inst;
236 }
237
238 void f0r_destructcxx . . $ f0r_destruct(5d22bdacc48458e8).(f0r_instance_tcxx . . $ f0r_instance_t# instance)
239 {
240 gateweave_instance_tcxx . . $ gateweave_instance_t#* inst = (gateweave_instance_tcxx . . $ gateweave_instance_t#*)instance;
241 freecxx . . $ free(5d22bdacc48458e8).(instance);
242 }
243
244 void f0r_set_param_valuecxx . . $ f0r_set_param_value(5be095a8278d2bf5).(f0r_instance_tcxx . . $ f0r_instance_t# instance, f0r_param_tcxx . . $ f0r_param_t# param, int param_index)
245 {
246 gateweave_instance_tcxx . . $ gateweave_instance_t#* inst = (gateweave_instance_tcxx . . $ gateweave_instance_t#*)instance;
247 switch(param_index)
248 {
249 case 0:
250 inst->intervalcxx . . $ gateweave_instance#interval. = *((double*)param);
251 break;
252 case 1:
253 inst->max_move_xcxx . . $ gateweave_instance#max_move_x. = *((double*)param);
254 break;
255 case 2:
256 inst->max_move_ycxx . . $ gateweave_instance#max_move_y. = *((double*)param);
257 break;
258 }
259 }
260
261 void f0r_get_param_valuecxx . . $ f0r_get_param_value(5be095a8278d2bf5).(f0r_instance_tcxx . . $ f0r_instance_t# instance, f0r_param_tcxx . . $ f0r_param_t# param, int param_index)
262 {
263 gateweave_instance_tcxx . . $ gateweave_instance_t#* inst = (gateweave_instance_tcxx . . $ gateweave_instance_t#*)instance;
264 switch(param_index)
265 {
266 case 0:
267 *((double*)param) = inst->intervalcxx . . $ gateweave_instance#interval.;
268 break;
269 case 1:
270 *((double*)param) = inst->max_move_xcxx . . $ gateweave_instance#max_move_x.;
271 break;
272 case 2:
273 *((double*)param) = inst->max_move_ycxx . . $ gateweave_instance#max_move_y.;
274 break;
275 }
276 }
277
278 void f0r_updatecxx . . $ f0r_update(96cd7b27f2fca8a7).(f0r_instance_tcxx . . $ f0r_instance_t# instance, double time, const uint32_tcxx . . $ uint32_t#* inframe, uint32_tcxx . . $ uint32_t#* outframe)
279 {
280 gateweave_instance_tcxx . . $ gateweave_instance_t#* inst = (gateweave_instance_tcxx . . $ gateweave_instance_t#*)instance;
281 inst->next_key_xcxx . . $ gateweave_instance#next_key_x. = gateweave_random_rangecxx . . $ gateweave_random_range(d8e7e0733fa41c87).(inst->max_move_xcxx . . $ gateweave_instance#max_move_x., inst->next_key_xcxx . . $ gateweave_instance#next_key_x.);
282 inst->next_key_ycxx . . $ gateweave_instance#next_key_y. = gateweave_random_rangecxx . . $ gateweave_random_range(d8e7e0733fa41c87).(inst->max_move_ycxx . . $ gateweave_instance#max_move_y., inst->next_key_ycxx . . $ gateweave_instance#next_key_y.);
283
284 inst->prev_key_xcxx . . $ gateweave_instance#prev_key_x. = gateweave_lerpcxx . . $ gateweave_lerp(7678bba071383ab).(inst->next_key_xcxx . . $ gateweave_instance#next_key_x., inst->prev_key_xcxx . . $ gateweave_instance#prev_key_x., inst->intervalcxx . . $ gateweave_instance#interval.);
285 inst->prev_key_ycxx . . $ gateweave_instance#prev_key_y. = gateweave_lerpcxx . . $ gateweave_lerp(7678bba071383ab).(inst->next_key_ycxx . . $ gateweave_instance#next_key_y., inst->prev_key_ycxx . . $ gateweave_instance#prev_key_y., inst->intervalcxx . . $ gateweave_instance#interval.);
286
287 gateweave_shift_picturecxx . . $ gateweave_shift_picture(1970dedbc8e6d445).(inframe, outframe, inst->prev_key_xcxx . . $ gateweave_instance#prev_key_x., inst->prev_key_ycxx . . $ gateweave_instance#prev_key_y., inst->widthcxx . . $ gateweave_instance#width., inst->heightcxx . . $ gateweave_instance#height.);
288 }