2 #include "confirmsave.h"
8 #include "despikewindow.h"
15 #define _(String) gettext(String)
16 #define gettext_noop(String) String
17 #define N_(String) gettext_noop (String)
20 REGISTER_PLUGIN(Despike)
24 Despike::Despike(PluginServer *server)
25 : PluginAClient(server)
27 PLUGIN_CONSTRUCTOR_MACRO
33 PLUGIN_DESTRUCTOR_MACRO
36 char* Despike::plugin_title() { return _("Despike"); }
37 int Despike::is_realtime() { return 1; }
39 NEW_PICON_MACRO(Despike)
42 SHOW_GUI_MACRO(Despike, DespikeThread)
43 SET_STRING_MACRO(Despike)
44 RAISE_WINDOW_MACRO(Despike)
46 LOAD_CONFIGURATION_MACRO(Despike, DespikeConfig)
49 int Despike::process_realtime(int64_t size, double *input_ptr, double *output_ptr)
53 double threshold = db.fromdb(config.level);
54 double change = db.fromdb(config.slope);
56 //printf("Despike::process_realtime 1\n");
57 for(int64_t i = 0; i < size; i++)
59 if(fabs(input_ptr[i]) > threshold ||
60 fabs(input_ptr[i]) - fabs(last_sample) > change)
62 output_ptr[i] = last_sample;
66 output_ptr[i] = input_ptr[i];
67 last_sample = input_ptr[i];
70 //printf("Despike::process_realtime 2\n");
76 int Despike::load_defaults()
80 // set the default directory
81 sprintf(directory, "%sdespike.rc", get_defaultdir());
85 defaults = new Defaults(directory);
89 config.level = defaults->get("LEVEL", (double)0);
90 config.slope = defaults->get("SLOPE", (double)0);
95 int Despike::save_defaults()
97 defaults->update("LEVEL", config.level);
98 defaults->update("SLOPE", config.slope);
104 void Despike::save_data(KeyFrame *keyframe)
108 // cause xml file to store data directly in text
109 output.set_shared_string(keyframe->data, MESSAGESIZE);
111 output.tag.set_title("DESPIKE");
112 output.tag.set_property("LEVEL", config.level);
113 output.tag.set_property("SLOPE", config.slope);
115 output.append_newline();
116 output.terminate_string();
119 void Despike::read_data(KeyFrame *keyframe)
122 // cause xml file to read directly from text
123 input.set_shared_string(keyframe->data, strlen(keyframe->data));
126 result = input.read_tag();
130 if(input.tag.title_is("DESPIKE"))
132 config.level = input.tag.get_property("LEVEL", config.level);
133 config.slope = input.tag.get_property("SLOPE", config.slope);
138 void Despike::update_gui()
142 load_configuration();
143 thread->window->lock_window();
144 thread->window->level->update(config.level);
145 thread->window->slope->update(config.slope);
146 thread->window->unlock_window();
165 DespikeConfig::DespikeConfig()
171 int DespikeConfig::equivalent(DespikeConfig &that)
173 return EQUIV(level, that.level) &&
174 EQUIV(slope, that.slope);
177 void DespikeConfig::copy_from(DespikeConfig &that)
183 void DespikeConfig::interpolate(DespikeConfig &prev,
187 int64_t current_frame)
189 double next_scale = (double)(current_frame - prev_frame) / (next_frame - prev_frame);
190 double prev_scale = (double)(next_frame - current_frame) / (next_frame - prev_frame);
192 this->level = prev.level * prev_scale + next.level * next_scale;
193 this->slope = prev.slope * prev_scale + next.slope * next_scale;