Debian Codegraph @

test/frei0r-run.c

raw symbols SCIP
1 /* This file is part of frei0r (https://frei0r.dyne.org)
2 *
3 * Copyright (C) 2024-2025 Dyne.org foundation
4 * designed, written and maintained by Denis Roio <[email protected]>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, either version 3 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 *
19 */
20
21 #include <unistd.h>
22 #include <libgen.h>
23 #include <dlfcn.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <math.h>
28
29 #include <frei0r.h>cxx . . $ `<file>/include/frei0r.h`/
30 #include "test-pattern.h"cxx . . $ `<file>/test/test-pattern.h`/
31
32 #if defined(__unix__cxx . . $ `<built-in>:397:9`!) && defined(GUI)
33 #pragma message "Compiling GUI test"
34 #include <X11/Xlib.h>
35 #include <X11/Xutil.h>
36 #endif
37
38 // frei0r function prototypes
39 typedef int (*f0r_init_fcxx . . $ f0r_init_f#)(void);
40 typedef void (*f0r_deinit_fcxx . . $ f0r_deinit_f#)(void);
41 typedef void (*f0r_get_plugin_info_fcxx . . $ f0r_get_plugin_info_f#)(f0r_plugin_info_tcxx . . $ f0r_plugin_info_t# *info);
42 typedef void (*f0r_get_param_info_fcxx . . $ f0r_get_param_info_f#)(f0r_param_info_tcxx . . $ f0r_param_info_t# *info, int param_index);
43 typedef f0r_instance_tcxx . . $ f0r_instance_t# (*f0r_construct_fcxx . . $ f0r_construct_f#)(unsigned int width, unsigned int height);
44 typedef void (*f0r_update_fcxx . . $ f0r_update_f#)(f0r_instance_tcxx . . $ f0r_instance_t# instance,
45 double time, const uint32_tcxx . . $ uint32_t#* inframe, uint32_tcxx . . $ uint32_t#* outframe);
46 typedef void (*f0r_update2_fcxx . . $ f0r_update2_f#)(f0r_instance_tcxx . . $ f0r_instance_t# instance, double time,
47 const uint32_tcxx . . $ uint32_t#* inframe1, const uint32_tcxx . . $ uint32_t#* inframe2,
48 const uint32_tcxx . . $ uint32_t#* inframe3, uint32_tcxx . . $ uint32_t#* outframe);
49 typedef void (*f0r_destruct_fcxx . . $ f0r_destruct_f#)(f0r_instance_tcxx . . $ f0r_instance_t# instance);
50 typedef void (*f0r_set_param_value_fcxx . . $ f0r_set_param_value_f#)(f0r_instance_tcxx . . $ f0r_instance_t# instance, f0r_param_tcxx . . $ f0r_param_t# param, int param_index);
51 typedef void (*f0r_get_param_value_fcxx . . $ f0r_get_param_value_f#)(f0r_instance_tcxx . . $ f0r_instance_t# instance, f0r_param_tcxx . . $ f0r_param_t# param, int param_index);
52
53
54 // Generate a simple color bar test pattern
55 void generate_test_patterncxx . . $ generate_test_pattern(d33c5f1e16ab2e16).(uint32_tcxx . . $ uint32_t#* frame, int width, int height, int color_model, int pattern_variant) {
56 // Create color bars: red, green, blue, white, black, cyan, magenta, yellow
57 int bar_width = width / 8;
58
59 for (int y = 0; y < height; y++) {
60 for (int x = 0; x < width; x++) {
61 int bar_index = x / bar_width;
62 if (bar_index >= 8) bar_index = 7;
63
64 // Rotate pattern based on variant
65 if (pattern_variant == 1) {
66 // Vertical bars instead
67 bar_index = y / (height / 8);
68 if (bar_index >= 8) bar_index = 7;
69 } else if (pattern_variant == 2) {
70 // Checkerboard
71 bar_index = ((x / bar_width) + (y / (height / 8))) % 8;
72 }
73
74 uint8_tcxx . . $ uint8_t# r, g, b, a = 255;
75
76 switch (bar_index) {
77 case 0: // Red
78 r = 255; g = 0; b = 0;
79 break;
80 case 1: // Green
81 r = 0; g = 255; b = 0;
82 break;
83 case 2: // Blue
84 r = 0; g = 0; b = 255;
85 break;
86 case 3: // White
87 r = 255; g = 255; b = 255;
88 break;
89 case 4: // Black
90 r = 0; g = 0; b = 0;
91 break;
92 case 5: // Cyan
93 r = 0; g = 255; b = 255;
94 break;
95 case 6: // Magenta
96 r = 255; g = 0; b = 255;
97 break;
98 case 7: // Yellow
99 r = 255; g = 255; b = 0;
100 break;
101 default:
102 r = 128; g = 128; b = 128;
103 break;
104 }
105
106 // Add some vertical variation for visual interest
107 if (y < height / 4) {
108 // Top quarter: keep original colors
109 } else if (y < height / 2) {
110 // Second quarter: darker
111 r = r * 0.7;
112 g = g * 0.7;
113 b = b * 0.7;
114 } else if (y < 3 * height / 4) {
115 // Third quarter: even darker
116 r = r * 0.4;
117 g = g * 0.4;
118 b = b * 0.4;
119 } else {
120 // Bottom quarter: much darker
121 r = r * 0.2;
122 g = g * 0.2;
123 b = b * 0.2;
124 }
125
126 if (color_model == F0R_COLOR_MODEL_BGRA8888cxx . . $ `include/frei0r.h:299:9`!) {
127 frame[y * width + x] = (a << 24) | (r << 16) | (g << 8) | b;
128 } else {
129 frame[y * width + x] = (a << 24) | (b << 16) | (g << 8) | r;
130 }
131 }
132 }
133 }
134
135 // Test parameters by cycling through different values
136 void test_parameterscxx . . $ test_parameters(c7814f50d6620840).(f0r_instance_tcxx . . $ f0r_instance_t# instance, f0r_set_param_value_fcxx . . $ f0r_set_param_value_f# f0r_set_param_value,
137 f0r_get_param_info_fcxx . . $ f0r_get_param_info_f# f0r_get_param_info, int num_params, int frame_count) {
138 f0r_param_info_tcxx . . $ f0r_param_info_t# param_info;
139 double double_val;
140 f0r_param_color_tcxx . . $ f0r_param_color_t# color_val;
141 f0r_param_position_tcxx . . $ f0r_param_position_t# position_val;
142
143 for (int i = 0; i < num_params; i++) {
144 f0r_get_param_info(&param_info, i);
145
146 switch (param_info.typecxx . . $ f0r_param_info#type.) {
147 case F0R_PARAM_BOOLcxx . . $ `include/frei0r.h:377:9`!:
148 // Alternate between 0.0 and 1.0 every 30 frames
149 double_val = (frame_count / 30) % 2;
150 f0r_set_param_value(instance, (f0r_param_tcxx . . $ f0r_param_t#)&double_val, i);
151 break;
152
153 case F0R_PARAM_DOUBLEcxx . . $ `include/frei0r.h:383:9`!:
154 // Cycle through values 0.0 to 1.0 over 60 frames
155 double_val = (frame_count % 60) / 60.0;
156 f0r_set_param_value(instance, (f0r_param_tcxx . . $ f0r_param_t#)&double_val, i);
157 break;
158
159 case F0R_PARAM_COLORcxx . . $ `include/frei0r.h:389:9`!:
160 // Cycle through different colors
161 switch ((frame_count / 20) % 4) {
162 case 0: // Red
163 color_val.rcxx . . $ f0r_param_color#r. = 1.0; color_val.gcxx . . $ f0r_param_color#g. = 0.0; color_val.bcxx . . $ f0r_param_color#b. = 0.0;
164 break;
165 case 1: // Green
166 color_val.rcxx . . $ f0r_param_color#r. = 0.0; color_val.gcxx . . $ f0r_param_color#g. = 1.0; color_val.bcxx . . $ f0r_param_color#b. = 0.0;
167 break;
168 case 2: // Blue
169 color_val.rcxx . . $ f0r_param_color#r. = 0.0; color_val.gcxx . . $ f0r_param_color#g. = 0.0; color_val.bcxx . . $ f0r_param_color#b. = 1.0;
170 break;
171 case 3: // White
172 color_val.rcxx . . $ f0r_param_color#r. = 1.0; color_val.gcxx . . $ f0r_param_color#g. = 1.0; color_val.bcxx . . $ f0r_param_color#b. = 1.0;
173 break;
174 }
175 f0r_set_param_value(instance, (f0r_param_tcxx . . $ f0r_param_t#)&color_val, i);
176 break;
177
178 case F0R_PARAM_POSITIONcxx . . $ `include/frei0r.h:394:9`!:
179 // Move position in a circular pattern
180 position_val.xcxx . . $ f0r_param_position#x. = 0.5 + 0.4 * sincxx . . $ sin(447c67c6676f75c3).(frame_count * 0.1);
181 position_val.ycxx . . $ f0r_param_position#y. = 0.5 + 0.4 * coscxx . . $ cos(447c67c6676f75c3).(frame_count * 0.1);
182 f0r_set_param_value(instance, (f0r_param_tcxx . . $ f0r_param_t#)&position_val, i);
183 break;
184
185 case F0R_PARAM_STRINGcxx . . $ `include/frei0r.h:400:9`!:
186 {
187 // For string parameters, use "0" as default
188 char *string_val = "0";
189 f0r_set_param_value(instance, (f0r_param_tcxx . . $ f0r_param_t#)&string_val, i);
190 break;
191 }
192
193 default:
194 // For unknown parameter types, set to middle value
195 double_val = 0.5;
196 f0r_set_param_value(instance, (f0r_param_tcxx . . $ f0r_param_t#)&double_val, i);
197 break;
198 }
199 }
200 }
201
202 int maincxx . . $ main(afcd3168fc1188a4).(int argc, char* argv[]) {
203 // instance frei0r pointers
204 static void *dl_handle;
205 static f0r_init_fcxx . . $ f0r_init_f# f0r_init;
206 static f0r_deinit_fcxx . . $ f0r_deinit_f# f0r_deinit;
207 static f0r_plugin_info_tcxx . . $ f0r_plugin_info_t# pi;
208 static f0r_get_plugin_info_fcxx . . $ f0r_get_plugin_info_f# f0r_get_plugin_info;
209 static f0r_get_param_info_fcxx . . $ f0r_get_param_info_f# f0r_get_param_info;
210 static f0r_param_info_tcxx . . $ f0r_param_info_t# param;
211 static f0r_instance_tcxx . . $ f0r_instance_t# instance;
212 static f0r_construct_fcxx . . $ f0r_construct_f# f0r_construct;
213 static f0r_update_fcxx . . $ f0r_update_f# f0r_update;
214 static f0r_destruct_fcxx . . $ f0r_destruct_f# f0r_destruct;
215 static f0r_set_param_value_fcxx . . $ f0r_set_param_value_f# f0r_set_param_value;
216 static f0r_get_param_value_fcxx . . $ f0r_get_param_value_f# f0r_get_param_value;
217
218 const char *usage = "Usage: frei0r-run [-tdg] [-f frames] -p <frei0r_plugin_file>\n"
219 " -d debug mode\n"
220 " -g graphical display mode (Linux/WSL)\n"
221 " -f frames number of frames to process (default: 100)\n"
222 " -p plugin path to frei0r plugin file";
223 if (argc < 2) {
224 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!,"%s\n",usage);
225 return -1;
226 }
227
228 int opt;
229 int graphical = 0;
230 int debug = 0;
231 int frames = 100; // Number of frames to test
232 char plugin_file[512];
233 plugin_file[0] = '\0';
234 while((opt = getoptcxx . . $ getopt(2483c31ff9bab884).(argc, argv, "tdgf:p:")) != -1) {
235 switch(opt) {
236 case 'd':
237 debug = 1;
238 break;
239 case 'g':
240 graphical = 1;
241 break;
242 case 'f':
243 frames = atoicxx . . $ atoi(5c4306d8553b3696).(optargcxx . . $ optarg.);
244 break;
245 case 'p':
246 snprintfcxx . . $ snprintf(ea502d73e74c754c).(plugin_file, 511, "%s", optargcxx . . $ optarg.);
247 break;
248 }
249 }
250
251 if (plugin_file[0] == '\0') {
252 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Error: plugin file required (-p option)\n%s\n", usage);
253 return -1;
254 }
255
256 // Set fixed video properties for test pattern
257 int frame_width = 640;
258 int frame_height = 480;
259 int fps = 30;
260
261 const char *file = basenamecxx . . $ `<external>/6296865783241590524/libgen.h:35:9`!(plugin_file);
262 const char *dir = dirnamecxx . . $ dirname(7a9722d75b371431).(plugin_file);
263 char path[256];;
264 snprintfcxx . . $ snprintf(ea502d73e74c754c).(path, 255,"%s/%s",dir,file);
265 // fprintf(stderr,"%s %s\n",argv[0], file);
266 // load shared library
267 dl_handle = dlopencxx . . $ dlopen(fb9ec0bb113f3da8).(path, RTLD_NOWcxx . . $ `<external>/10632388298615623587/dlfcn.h:25:9`!|RTLD_LOCALcxx . . $ `<external>/10632388298615623587/dlfcn.h:38:9`!);
268 if(!dl_handle) {
269 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!,"error: %s\n",dlerrorcxx . . $ dlerror(41208ce6ca65dd58).());
270 exitcxx . . $ exit(3ca292c338df9bb3).(1);
271 }
272 // get plugin function calls
273 f0r_init = (f0r_init_fcxx . . $ f0r_init_f#) dlsymcxx . . $ dlsym(5c3a2d84d269ab4b).(dl_handle,"f0r_init");
274 f0r_deinit = (f0r_deinit_fcxx . . $ f0r_deinit_f#) dlsymcxx . . $ dlsym(5c3a2d84d269ab4b).(dl_handle,"f0r_deinit");
275 f0r_get_plugin_info = (f0r_get_plugin_info_fcxx . . $ f0r_get_plugin_info_f#) dlsymcxx . . $ dlsym(5c3a2d84d269ab4b).(dl_handle,"f0r_get_plugin_info");
276 f0r_get_param_info = (f0r_get_param_info_fcxx . . $ f0r_get_param_info_f#) dlsymcxx . . $ dlsym(5c3a2d84d269ab4b).(dl_handle,"f0r_get_param_info");
277 f0r_construct = (f0r_construct_fcxx . . $ f0r_construct_f#) dlsymcxx . . $ dlsym(5c3a2d84d269ab4b).(dl_handle,"f0r_construct");
278 f0r_update = (f0r_update_fcxx . . $ f0r_update_f#) dlsymcxx . . $ dlsym(5c3a2d84d269ab4b).(dl_handle,"f0r_update");
279 f0r_destruct = (f0r_destruct_fcxx . . $ f0r_destruct_f#) dlsymcxx . . $ dlsym(5c3a2d84d269ab4b).(dl_handle,"f0r_destruct");
280 f0r_set_param_value = (f0r_set_param_value_fcxx . . $ f0r_set_param_value_f#) dlsymcxx . . $ dlsym(5c3a2d84d269ab4b).(dl_handle,"f0r_set_param_value");
281 f0r_get_param_value = (f0r_get_param_value_fcxx . . $ f0r_get_param_value_f#) dlsymcxx . . $ dlsym(5c3a2d84d269ab4b).(dl_handle,"f0r_get_param_value");
282
283 // always initialize plugin first
284 f0r_init();
285 // get info about plugin
286 f0r_get_plugin_info(&pi);
287 const char *frei0r_color_model = (pi.color_modelcxx . . $ f0r_plugin_info#color_model. == F0R_COLOR_MODEL_BGRA8888cxx . . $ `include/frei0r.h:299:9`! ? "bgra8888" :
288 pi.color_modelcxx . . $ f0r_plugin_info#color_model. == F0R_COLOR_MODEL_RGBA8888cxx . . $ `include/frei0r.h:308:9`! ? "rgba8888" :
289 pi.color_modelcxx . . $ f0r_plugin_info#color_model. == F0R_COLOR_MODEL_PACKED32cxx . . $ `include/frei0r.h:322:9`! ? "packed32" : "unknown");
290
291 if(debug) {
292 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!,"{\n \"name\":\"%s\",\n \"type\":\"%s\",\n \"color_model\":\"%s\",\n \"num_params\":\"%d\"\n}",
293 pi.namecxx . . $ f0r_plugin_info#name.,
294 pi.plugin_typecxx . . $ f0r_plugin_info#plugin_type. == F0R_PLUGIN_TYPE_FILTERcxx . . $ `include/frei0r.h:247:9`! ? "filter" :
295 pi.plugin_typecxx . . $ f0r_plugin_info#plugin_type. == F0R_PLUGIN_TYPE_SOURCEcxx . . $ `include/frei0r.h:249:9`! ? "source" :
296 pi.plugin_typecxx . . $ f0r_plugin_info#plugin_type. == F0R_PLUGIN_TYPE_MIXER2cxx . . $ `include/frei0r.h:251:9`! ? "mixer2" :
297 pi.plugin_typecxx . . $ f0r_plugin_info#plugin_type. == F0R_PLUGIN_TYPE_MIXER3cxx . . $ `include/frei0r.h:253:9`! ? "mixer3" : "unknown",
298 frei0r_color_model,
299 pi.num_paramscxx . . $ f0r_plugin_info#num_params.);
300 // Print parameter information
301 if (pi.num_paramscxx . . $ f0r_plugin_info#num_params. > 0) {
302 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!,",\n \"parameters\":[\n");
303 for (int i = 0; i < pi.num_paramscxx . . $ f0r_plugin_info#num_params.; i++) {
304 f0r_get_param_info(&param, i);
305 const char* param_type =
306 param.typecxx . . $ f0r_param_info#type. == F0R_PARAM_BOOLcxx . . $ `include/frei0r.h:377:9`! ? "bool" :
307 param.typecxx . . $ f0r_param_info#type. == F0R_PARAM_DOUBLEcxx . . $ `include/frei0r.h:383:9`! ? "double" :
308 param.typecxx . . $ f0r_param_info#type. == F0R_PARAM_COLORcxx . . $ `include/frei0r.h:389:9`! ? "color" :
309 param.typecxx . . $ f0r_param_info#type. == F0R_PARAM_POSITIONcxx . . $ `include/frei0r.h:394:9`! ? "position" :
310 param.typecxx . . $ f0r_param_info#type. == F0R_PARAM_STRINGcxx . . $ `include/frei0r.h:400:9`! ? "string" : "unknown";
311 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!," {\"name\":\"%s\",\"type\":\"%s\",\"explanation\":\"%s\"}",
312 param.namecxx . . $ f0r_param_info#name., param_type, param.explanationcxx . . $ f0r_param_info#explanation.);
313 if (i < pi.num_paramscxx . . $ f0r_plugin_info#num_params. - 1) fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!,",\n");
314 }
315 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!,"\n ]\n");
316 }
317 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!,"}\n");
318 }
319
320 instance = f0r_construct(frame_width, frame_height);
321
322 uint32_tcxx . . $ uint32_t# *input_buffer = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
323 uint32_tcxx . . $ uint32_t# *input_buffer2 = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
324 uint32_tcxx . . $ uint32_t# *input_buffer3 = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
325 uint32_tcxx . . $ uint32_t# *output_buffer;
326
327 // Allocate buffers based on plugin type
328 if (pi.plugin_typecxx . . $ f0r_plugin_info#plugin_type. == F0R_PLUGIN_TYPE_FILTERcxx . . $ `include/frei0r.h:247:9`!) {
329 input_buffer = (uint32_tcxx . . $ uint32_t#*)calloccxx . . $ calloc(63a7bf2941bfcd7a).(4, frame_width * frame_height);
330 } else if (pi.plugin_typecxx . . $ f0r_plugin_info#plugin_type. == F0R_PLUGIN_TYPE_MIXER2cxx . . $ `include/frei0r.h:251:9`!) {
331 input_buffer = (uint32_tcxx . . $ uint32_t#*)calloccxx . . $ calloc(63a7bf2941bfcd7a).(4, frame_width * frame_height);
332 input_buffer2 = (uint32_tcxx . . $ uint32_t#*)calloccxx . . $ calloc(63a7bf2941bfcd7a).(4, frame_width * frame_height);
333 } else if (pi.plugin_typecxx . . $ f0r_plugin_info#plugin_type. == F0R_PLUGIN_TYPE_MIXER3cxx . . $ `include/frei0r.h:253:9`!) {
334 input_buffer = (uint32_tcxx . . $ uint32_t#*)calloccxx . . $ calloc(63a7bf2941bfcd7a).(4, frame_width * frame_height);
335 input_buffer2 = (uint32_tcxx . . $ uint32_t#*)calloccxx . . $ calloc(63a7bf2941bfcd7a).(4, frame_width * frame_height);
336 input_buffer3 = (uint32_tcxx . . $ uint32_t#*)calloccxx . . $ calloc(63a7bf2941bfcd7a).(4, frame_width * frame_height);
337 }
338 // SOURCE type needs no input buffer
339
340 output_buffer = (uint32_tcxx . . $ uint32_t#*)calloccxx . . $ calloc(63a7bf2941bfcd7a).(4, frame_width * frame_height);
341
342 #if defined(GUI)
343 // Generate initial test patterns
344 if (input_buffer)
345 generate_animated_test_pattern(input_buffer, frame_width, frame_height, 0, pi.color_model);
346 if (input_buffer2)
347 generate_animated_test_pattern(input_buffer2, frame_width, frame_height, 0, pi.color_model);
348 if (input_buffer3)
349 generate_animated_test_pattern(input_buffer3, frame_width, frame_height, 0, pi.color_model);
350 #else
351 if (input_buffer)
352 generate_test_patterncxx . . $ generate_test_pattern(d33c5f1e16ab2e16).(input_buffer, frame_width, frame_height, pi.color_modelcxx . . $ f0r_plugin_info#color_model., 0);
353 if (input_buffer2)
354 generate_test_patterncxx . . $ generate_test_pattern(d33c5f1e16ab2e16).(input_buffer2, frame_width, frame_height, pi.color_modelcxx . . $ f0r_plugin_info#color_model., 1);
355 if (input_buffer3)
356 generate_test_patterncxx . . $ generate_test_pattern(d33c5f1e16ab2e16).(input_buffer3, frame_width, frame_height, pi.color_modelcxx . . $ f0r_plugin_info#color_model., 2);
357 #endif
358
359 #if defined(__unix__cxx . . $ `<built-in>:397:9`!) && defined(GUI)
360 Display *display = NULL;
361 Window window;
362 GC gc;
363 XImage *ximage = NULL;
364
365 if (graphical) {
366 display = XOpenDisplay(NULL);
367 if (!display) {
368 fprintf(stderr, "Warning: Cannot open X display, falling back to headless mode\n");
369 graphical = 0;
370 } else {
371 int screen = DefaultScreen(display);
372 window = XCreateSimpleWindow(display, RootWindow(display, screen),
373 0, 0, frame_width, frame_height, 1,
374 BlackPixel(display, screen),
375 WhitePixel(display, screen));
376
377 XStoreName(display, window, pi.name);
378 XSelectInput(display, window, ExposureMask | KeyPressMask);
379 XMapWindow(display, window);
380 gc = XCreateGC(display, window, 0, NULL);
381
382 Visual *visual = DefaultVisual(display, screen);
383 ximage = XCreateImage(display, visual, 24, ZPixmap, 0,
384 (char*)output_buffer, frame_width, frame_height, 32, 0);
385
386 XFlush(display);
387 }
388 }
389 #endif
390
391 // Load f0r_update2 for mixers
392 f0r_update2_fcxx . . $ f0r_update2_f# f0r_update2 = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
393 if (pi.plugin_typecxx . . $ f0r_plugin_info#plugin_type. == F0R_PLUGIN_TYPE_MIXER2cxx . . $ `include/frei0r.h:251:9`! || pi.plugin_typecxx . . $ f0r_plugin_info#plugin_type. == F0R_PLUGIN_TYPE_MIXER3cxx . . $ `include/frei0r.h:253:9`!) {
394 f0r_update2 = (f0r_update2_fcxx . . $ f0r_update2_f#)dlsymcxx . . $ dlsym(5c3a2d84d269ab4b).(dl_handle, "f0r_update2");
395 if (!f0r_update2) {
396 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Error: Cannot load f0r_update2 for mixer plugin\n");
397 if (input_buffer) freecxx . . $ free(5d22bdacc48458e8).(input_buffer);
398 if (input_buffer2) freecxx . . $ free(5d22bdacc48458e8).(input_buffer2);
399 if (input_buffer3) freecxx . . $ free(5d22bdacc48458e8).(input_buffer3);
400 freecxx . . $ free(5d22bdacc48458e8).(output_buffer);
401 f0r_destruct(instance);
402 f0r_deinit();
403 dlclosecxx . . $ dlclose(dedf1e9b1c614a07).(dl_handle);
404 return 1;
405 }
406 }
407
408 // Test the plugin with different parameter values
409 for (int frame = 0; frame < frames; frame++) {
410 #if defined(GUI)
411 // Generate animated test patterns for this frame
412 if (input_buffer)
413 generate_animated_test_pattern(input_buffer, frame_width, frame_height, frame, pi.color_model);
414 if (input_buffer2)
415 generate_animated_test_pattern(input_buffer2, frame_width, frame_height, frame + 10, pi.color_model);
416 if (input_buffer3)
417 generate_animated_test_pattern(input_buffer3, frame_width, frame_height, frame + 20, pi.color_model);
418 #else
419 if (input_buffer)
420 generate_test_patterncxx . . $ generate_test_pattern(d33c5f1e16ab2e16).(input_buffer, frame_width, frame_height, pi.color_modelcxx . . $ f0r_plugin_info#color_model., 0);
421 if (input_buffer2)
422 generate_test_patterncxx . . $ generate_test_pattern(d33c5f1e16ab2e16).(input_buffer2, frame_width, frame_height, pi.color_modelcxx . . $ f0r_plugin_info#color_model., 1);
423 if (input_buffer3)
424 generate_test_patterncxx . . $ generate_test_pattern(d33c5f1e16ab2e16).(input_buffer3, frame_width, frame_height, pi.color_modelcxx . . $ f0r_plugin_info#color_model., 2);
425 #endif
426
427 // Update parameters if the plugin has any
428 if (pi.num_paramscxx . . $ f0r_plugin_info#num_params. > 0 && f0r_set_param_value) {
429 test_parameterscxx . . $ test_parameters(c7814f50d6620840).(instance, f0r_set_param_value, f0r_get_param_info, pi.num_paramscxx . . $ f0r_plugin_info#num_params., frame);
430 }
431
432 // Apply plugin based on type
433 double time = (double)frame / (double)fps;
434
435 switch (pi.plugin_typecxx . . $ f0r_plugin_info#plugin_type.) {
436 case F0R_PLUGIN_TYPE_SOURCEcxx . . $ `include/frei0r.h:249:9`!:
437 f0r_update(instance, time, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, output_buffer);
438 break;
439 case F0R_PLUGIN_TYPE_FILTERcxx . . $ `include/frei0r.h:247:9`!:
440 f0r_update(instance, time, (const uint32_tcxx . . $ uint32_t#*)input_buffer, output_buffer);
441 break;
442 case F0R_PLUGIN_TYPE_MIXER2cxx . . $ `include/frei0r.h:251:9`!:
443 f0r_update2(instance, time, (const uint32_tcxx . . $ uint32_t#*)input_buffer,
444 (const uint32_tcxx . . $ uint32_t#*)input_buffer2, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, output_buffer);
445 break;
446 case F0R_PLUGIN_TYPE_MIXER3cxx . . $ `include/frei0r.h:253:9`!:
447 f0r_update2(instance, time, (const uint32_tcxx . . $ uint32_t#*)input_buffer,
448 (const uint32_tcxx . . $ uint32_t#*)input_buffer2, (const uint32_tcxx . . $ uint32_t#*)input_buffer3,
449 output_buffer);
450 break;
451 default:
452 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Unknown plugin type: %d\n", pi.plugin_typecxx . . $ f0r_plugin_info#plugin_type.);
453 break;
454 }
455
456 #if defined(__unix__cxx . . $ `<built-in>:397:9`!) && defined(GUI)
457 if (graphical && display) {
458 ximage->data = (char*)output_buffer;
459 XPutImage(display, window, gc, ximage, 0, 0, 0, 0, frame_width, frame_height);
460 XFlush(display);
461
462 // Check for key press to exit early
463 while (XPending(display)) {
464 XEvent event;
465 XNextEvent(display, &event);
466 if (event.type == KeyPress) {
467 fprintf(stderr, "\nInterrupted by user at frame %d\n", frame);
468 frame = frames; // Exit loop
469 break;
470 }
471 }
472
473 usleep(1000000 / fps); // Frame delay
474 }
475 #endif
476
477 if (!graphical && frame % 10 == 0 && debug) {
478 printfcxx . . $ printf(581fddd72a8db8fc).("Frame %d processed\n", frame);
479 }
480 }
481
482 #if defined(__unix__cxx . . $ `<built-in>:397:9`!) && defined(GUI)
483 if (graphical && display) {
484 ximage->data = NULL; // Prevent XDestroyImage from freeing our buffer
485 XDestroyImage(ximage);
486 XFreeGC(display, gc);
487 XDestroyWindow(display, window);
488 XCloseDisplay(display);
489 }
490 #endif
491
492 if(debug) {
493 const char *plugin_type_name = "unknown";
494 switch (pi.plugin_typecxx . . $ f0r_plugin_info#plugin_type.) {
495 case F0R_PLUGIN_TYPE_SOURCEcxx . . $ `include/frei0r.h:249:9`!: plugin_type_name = "source"; break;
496 case F0R_PLUGIN_TYPE_FILTERcxx . . $ `include/frei0r.h:247:9`!: plugin_type_name = "filter"; break;
497 case F0R_PLUGIN_TYPE_MIXER2cxx . . $ `include/frei0r.h:251:9`!: plugin_type_name = "mixer2"; break;
498 case F0R_PLUGIN_TYPE_MIXER3cxx . . $ `include/frei0r.h:253:9`!: plugin_type_name = "mixer3"; break;
499 }
500 printfcxx . . $ printf(581fddd72a8db8fc).("Test completed successfully. Plugin: %s (type: %s)\n", pi.namecxx . . $ f0r_plugin_info#name., plugin_type_name);
501 printfcxx . . $ printf(581fddd72a8db8fc).("Tested %d frames with %d parameters\n", frames, pi.num_paramscxx . . $ f0r_plugin_info#num_params.);
502 if (pi.plugin_typecxx . . $ f0r_plugin_info#plugin_type. != F0R_PLUGIN_TYPE_SOURCEcxx . . $ `include/frei0r.h:249:9`!) {
503 printfcxx . . $ printf(581fddd72a8db8fc).("Input: %dx%d test pattern(s)\n", frame_width, frame_height);
504 }
505 printfcxx . . $ printf(581fddd72a8db8fc).("Output: %dx%d processed frames\n", frame_width, frame_height);
506 }
507
508 if (input_buffer) freecxx . . $ free(5d22bdacc48458e8).(input_buffer);
509 if (input_buffer2) freecxx . . $ free(5d22bdacc48458e8).(input_buffer2);
510 if (input_buffer3) freecxx . . $ free(5d22bdacc48458e8).(input_buffer3);
511 freecxx . . $ free(5d22bdacc48458e8).(output_buffer);
512
513 f0r_destruct(instance);
514 f0r_deinit();
515
516 dlclosecxx . . $ dlclose(dedf1e9b1c614a07).(dl_handle);
517
518 return 0;
519 }