update internationalization data
[goodguy/history.git] / cinelerra-5.0 / plugins / despike / despike.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  * 
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (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 General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  * 
20  */
21
22 #include "clip.h"
23 #include "confirmsave.h"
24 #include "bchash.h"
25 #include "errorbox.h"
26 #include "filexml.h"
27 #include "language.h"
28 #include "despike.h"
29 #include "despikewindow.h"
30 #include "samples.h"
31
32 #include "vframe.h"
33
34 #include <string.h>
35
36
37
38 REGISTER_PLUGIN(Despike)
39
40
41
42 Despike::Despike(PluginServer *server)
43  : PluginAClient(server)
44 {
45         
46         last_sample = 0;
47 }
48
49 Despike::~Despike()
50 {
51         
52 }
53
54 const char* Despike::plugin_title() { return _("Despike"); }
55 int Despike::is_realtime() { return 1; }
56
57 NEW_WINDOW_MACRO(Despike, DespikeWindow)
58
59 LOAD_CONFIGURATION_MACRO(Despike, DespikeConfig)
60
61
62 int Despike::process_realtime(int64_t size, Samples *input_ptr, Samples *output_ptr)
63 {
64         load_configuration();
65
66         double threshold = db.fromdb(config.level);
67         double change = db.fromdb(config.slope);
68
69 //printf("Despike::process_realtime 1\n");
70         double *output_samples = output_ptr->get_data();
71         double *input_samples = input_ptr->get_data();
72         for(int64_t i = 0; i < size; i++)
73         {
74                 if(fabs(input_samples[i]) > threshold || 
75                         fabs(input_samples[i]) - fabs(last_sample) > change) 
76                 {
77                         output_samples[i] = last_sample;
78                 }
79                 else
80                 {
81                         output_samples[i] = input_samples[i];
82                         last_sample = input_samples[i];
83                 }
84         }
85 //printf("Despike::process_realtime 2\n");
86
87         return 0;
88 }
89
90
91
92 void Despike::save_data(KeyFrame *keyframe)
93 {
94         FileXML output;
95
96 // cause xml file to store data directly in text
97         output.set_shared_output(keyframe->get_data(), MESSAGESIZE);
98
99         output.tag.set_title("DESPIKE");
100         output.tag.set_property("LEVEL", config.level);
101         output.tag.set_property("SLOPE", config.slope);
102         output.append_tag();
103         output.append_newline();
104         output.terminate_string();
105 }
106
107 void Despike::read_data(KeyFrame *keyframe)
108 {
109         FileXML input;
110 // cause xml file to read directly from text
111         input.set_shared_input(keyframe->get_data(), strlen(keyframe->get_data()));
112         int result = 0;
113
114         result = input.read_tag();
115
116         if(!result)
117         {
118                 if(input.tag.title_is("DESPIKE"))
119                 {
120                         config.level = input.tag.get_property("LEVEL", config.level);
121                         config.slope = input.tag.get_property("SLOPE", config.slope);
122                 }
123         }
124 }
125
126 void Despike::update_gui()
127 {
128         if(thread)
129         {
130                 load_configuration();
131                 ((DespikeWindow*)thread->window)->lock_window();
132                 ((DespikeWindow*)thread->window)->level->update(config.level);
133                 ((DespikeWindow*)thread->window)->slope->update(config.slope);
134                 ((DespikeWindow*)thread->window)->unlock_window();
135         }
136 }
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153 DespikeConfig::DespikeConfig()
154 {
155         level = 0;
156         slope = 0;
157 }
158
159 int DespikeConfig::equivalent(DespikeConfig &that)
160 {
161         return EQUIV(level, that.level) && 
162                 EQUIV(slope, that.slope);
163 }
164
165 void DespikeConfig::copy_from(DespikeConfig &that)
166 {
167         level = that.level;
168         slope = that.slope;
169 }
170
171 void DespikeConfig::interpolate(DespikeConfig &prev, 
172                 DespikeConfig &next, 
173                 int64_t prev_frame, 
174                 int64_t next_frame, 
175                 int64_t current_frame)
176 {
177         double next_scale = (double)(current_frame - prev_frame) / (next_frame - prev_frame);
178         double prev_scale = (double)(next_frame - current_frame) / (next_frame - prev_frame);
179
180         this->level = prev.level * prev_scale + next.level * next_scale;
181         this->slope = prev.slope * prev_scale + next.slope * next_scale;
182 }
183
184
185
186
187
188