Debian Codegraph @

src/mixer2/euclid_eraser/euclid_eraser.cpp

raw symbols SCIP
1 // SPDX-License-Identifier: GPL-2.0-or-latercxx . . $ `<file>/src/mixer2/euclid_eraser/euclid_eraser.cpp`/
2 // Copyright (C) 2024 Erik H. Beck, [email protected]
3 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
4
5 /* This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA
19 *
20 * Also see:
21 *
22 * https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
23 *
24 */
25
26 /** This is the source file for the euclid eraser two-input mixer for
27 frei0r. It uses euclidean distance to remove a static background
28 from a video. See file ./euclid_eraser.md for more info
29 */
30
31 #include <math.h>
32 #include "frei0r.hpp"cxx . . $ `<file>/include/frei0r.hpp`/
33 #include "frei0r/math.h"cxx . . $ `<file>/include/frei0r/math.h`/
34
35 #define NBYTEScxx . . $ `src/mixer2/euclid_eraser/euclid_eraser.cpp:35:9`! 4
36 #define CHANNELScxx . . $ `src/mixer2/euclid_eraser/euclid_eraser.cpp:36:9`! 3 // Actually 4; 0-3
37
38 double euclidDistancecxx . . $ euclidDistance(d636cd1c3b63cbdc).(uint8_t x_r, uint8_t x_g, uint8_t x_b,
39 uint8_t y_r, uint8_t y_g, uint8_t y_b)
40 {
41 //calculating color channel differences for next steps
42 double red_d = x_r - y_r;
43 double green_d = x_g - y_g;
44 double blue_d = x_b - y_b;
45
46 double sq_sum, dist;
47
48 //calculating Euclidean distance
49 sq_sum = powcxx . . $ pow(1b569819b62499ac).(red_d, 2) + powcxx . . $ pow(1b569819b62499ac).(green_d, 2) + powcxx . . $ pow(1b569819b62499ac). (blue_d, 2);
50 dist = sqrtcxx . . $ sqrt(447c67c6676f75c3).(sq_sum);
51
52 return dist;
53 }
54
55
56 class euclid_erasercxx . . $ euclid_eraser# : public frei0rcxx . . $ frei0r/::mixer2cxx . . $ frei0r/mixer2#
57 {
58
59 public:
60 euclid_erasercxx . . $ euclid_eraser#euclid_eraser(b4d55b1286ff73e8).(unsigned int width, unsigned int height)
61 {
62 thresholdcxx . . $ euclid_eraser#threshold. = 5.6; // Default distance threshold value
63 register_paramcxx . . $ frei0r/fx#register_param(acfd1d4411be0164).(thresholdcxx . . $ euclid_eraser#threshold., "threshold"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., "Matching Threshold"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
64 }
65
66 void updatecxx . . $ euclid_eraser#update(aea6c563decfb03a).(double time,
67 uint32_t* out,
68 const uint32_t* in1,
69 const uint32_t* in2)
70 {
71
72 const uint8_t *src1 = reinterpret_cast<const uint8_t*>(in1); //frst track (0)
73 const uint8_t *src2 = reinterpret_cast<const uint8_t*>(in2); //second trk (1)
74 uint8_t *dst = reinterpret_cast<uint8_t*>(out);
75
76 double e_dist;
77
78 uint32_t sizeCounter = sizecxx . . $ frei0r/fx#size.;
79 uint32_t b;
80
81 while (sizeCounter--)
82 {
83
84 // Loop over rgb
85 // Copy pixels from src2 to destination
86
87 for (b=0; b<3; b++)
88 {
89 dst[b]=src2[b];
90 }
91 e_dist=euclidDistancecxx . . $ euclidDistance(d636cd1c3b63cbdc).(src1[0],src1[1],src1[2],
92 src2[0],src2[1],src2[2]);
93
94 if (e_dist <= euclid_erasercxx . . $ euclid_eraser#::thresholdcxx . . $ euclid_eraser#threshold.) {
95 // Make alpha channel for pixel fully transparent
96 dst[3]=0;
97 }
98 else {
99 // Make alpha channel for the pixel fully opaque
100 dst[3]=255;
101 }
102
103 src1 += NBYTEScxx . . $ `src/mixer2/euclid_eraser/euclid_eraser.cpp:35:9`!;
104 src2 += NBYTEScxx . . $ `src/mixer2/euclid_eraser/euclid_eraser.cpp:35:9`!;
105 dst += NBYTEScxx . . $ `src/mixer2/euclid_eraser/euclid_eraser.cpp:35:9`!;
106 }
107
108 }
109 private:
110 double thresholdcxx . . $ euclid_eraser#threshold.;
111
112 };
113
114 frei0rcxx . . $ frei0r/::constructcxx . . $ frei0r/construct#<euclid_erasercxx . . $ euclid_eraser#> plugincxx . . $ plugin.("euclid_eraser"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).,
115 "Erasing backgrounds with euclidean distance"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).,
116 "Erik H. Beck"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).,
117 0,1,
118 F0R_COLOR_MODEL_RGBA8888cxx . . $ `include/frei0r.h:308:9`!);
119