00001 #include "clip.h"
00002 #include "confirmsave.h"
00003 #include "bchash.h"
00004 #include "errorbox.h"
00005 #include "filexml.h"
00006 #include "picon_png.h"
00007 #include "despike.h"
00008 #include "despikewindow.h"
00009
00010 #include "vframe.h"
00011
00012 #include <string.h>
00013
00014 #include <libintl.h>
00015 #define _(String) gettext(String)
00016 #define gettext_noop(String) String
00017 #define N_(String) gettext_noop (String)
00018
00019
00020 REGISTER_PLUGIN(Despike)
00021
00022
00023
00024 Despike::Despike(PluginServer *server)
00025 : PluginAClient(server)
00026 {
00027 PLUGIN_CONSTRUCTOR_MACRO
00028 last_sample = 0;
00029 }
00030
00031 Despike::~Despike()
00032 {
00033 PLUGIN_DESTRUCTOR_MACRO
00034 }
00035
00036 char* Despike::plugin_title() { return N_("Despike"); }
00037 int Despike::is_realtime() { return 1; }
00038
00039 NEW_PICON_MACRO(Despike)
00040
00041
00042 SHOW_GUI_MACRO(Despike, DespikeThread)
00043 SET_STRING_MACRO(Despike)
00044 RAISE_WINDOW_MACRO(Despike)
00045
00046 LOAD_CONFIGURATION_MACRO(Despike, DespikeConfig)
00047
00048
00049 int Despike::process_realtime(int64_t size, double *input_ptr, double *output_ptr)
00050 {
00051 load_configuration();
00052
00053 double threshold = db.fromdb(config.level);
00054 double change = db.fromdb(config.slope);
00055
00056
00057 for(int64_t i = 0; i < size; i++)
00058 {
00059 if(fabs(input_ptr[i]) > threshold ||
00060 fabs(input_ptr[i]) - fabs(last_sample) > change)
00061 {
00062 output_ptr[i] = last_sample;
00063 }
00064 else
00065 {
00066 output_ptr[i] = input_ptr[i];
00067 last_sample = input_ptr[i];
00068 }
00069 }
00070
00071
00072 return 0;
00073 }
00074
00075
00076 int Despike::load_defaults()
00077 {
00078 char directory[1024];
00079
00080
00081 sprintf(directory, "%sdespike.rc", get_defaultdir());
00082
00083
00084
00085 defaults = new BC_Hash(directory);
00086
00087 defaults->load();
00088
00089 config.level = defaults->get("LEVEL", (double)0);
00090 config.slope = defaults->get("SLOPE", (double)0);
00091
00092 return 0;
00093 }
00094
00095 int Despike::save_defaults()
00096 {
00097 defaults->update("LEVEL", config.level);
00098 defaults->update("SLOPE", config.slope);
00099 defaults->save();
00100 return 0;
00101 }
00102
00103
00104 void Despike::save_data(KeyFrame *keyframe)
00105 {
00106 FileXML output;
00107
00108
00109 output.set_shared_string(keyframe->data, MESSAGESIZE);
00110
00111 output.tag.set_title("DESPIKE");
00112 output.tag.set_property("LEVEL", config.level);
00113 output.tag.set_property("SLOPE", config.slope);
00114 output.append_tag();
00115 output.tag.set_title("/DESPIKE");
00116 output.append_tag();
00117 output.append_newline();
00118 output.terminate_string();
00119 }
00120
00121 void Despike::read_data(KeyFrame *keyframe)
00122 {
00123 FileXML input;
00124
00125 input.set_shared_string(keyframe->data, strlen(keyframe->data));
00126 int result = 0;
00127
00128 result = input.read_tag();
00129
00130 if(!result)
00131 {
00132 if(input.tag.title_is("DESPIKE"))
00133 {
00134 config.level = input.tag.get_property("LEVEL", config.level);
00135 config.slope = input.tag.get_property("SLOPE", config.slope);
00136 }
00137 }
00138 }
00139
00140 void Despike::update_gui()
00141 {
00142 if(thread)
00143 {
00144 load_configuration();
00145 thread->window->lock_window();
00146 thread->window->level->update(config.level);
00147 thread->window->slope->update(config.slope);
00148 thread->window->unlock_window();
00149 }
00150 }
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167 DespikeConfig::DespikeConfig()
00168 {
00169 level = 0;
00170 slope = 0;
00171 }
00172
00173 int DespikeConfig::equivalent(DespikeConfig &that)
00174 {
00175 return EQUIV(level, that.level) &&
00176 EQUIV(slope, that.slope);
00177 }
00178
00179 void DespikeConfig::copy_from(DespikeConfig &that)
00180 {
00181 level = that.level;
00182 slope = that.slope;
00183 }
00184
00185 void DespikeConfig::interpolate(DespikeConfig &prev,
00186 DespikeConfig &next,
00187 int64_t prev_frame,
00188 int64_t next_frame,
00189 int64_t current_frame)
00190 {
00191 double next_scale = (double)(current_frame - prev_frame) / (next_frame - prev_frame);
00192 double prev_scale = (double)(next_frame - current_frame) / (next_frame - prev_frame);
00193
00194 this->level = prev.level * prev_scale + next.level * next_scale;
00195 this->slope = prev.slope * prev_scale + next.slope * next_scale;
00196 }
00197
00198
00199
00200
00201
00202