3 #include "denoisemjpeg.h"
12 #define _(String) gettext(String)
13 #define gettext_noop(String) String
14 #define N_(String) gettext_noop (String)
24 REGISTER_PLUGIN(DenoiseMJPEG)
31 DenoiseMJPEGConfig::DenoiseMJPEGConfig()
44 int DenoiseMJPEGConfig::equivalent(DenoiseMJPEGConfig &that)
47 that.radius == radius &&
48 that.threshold == threshold &&
49 that.threshold2 == threshold2 &&
50 that.sharpness == sharpness &&
51 that.lcontrast == lcontrast &&
52 that.ccontrast == ccontrast &&
53 that.deinterlace == deinterlace &&
58 void DenoiseMJPEGConfig::copy_from(DenoiseMJPEGConfig &that)
61 threshold = that.threshold;
62 threshold2 = that.threshold2;
63 sharpness = that.sharpness;
64 lcontrast = that.lcontrast;
65 ccontrast = that.ccontrast;
66 deinterlace = that.deinterlace;
71 void DenoiseMJPEGConfig::interpolate(DenoiseMJPEGConfig &prev,
72 DenoiseMJPEGConfig &next,
77 double next_scale = (double)(current_frame - prev_frame) / (next_frame - prev_frame);
78 double prev_scale = (double)(next_frame - current_frame) / (next_frame - prev_frame);
80 this->radius = (int)(prev.radius * prev_scale + next.radius * next_scale);
81 this->threshold = (int)(prev.threshold * prev_scale + next.threshold * next_scale);
82 this->threshold2 = (int)(prev.threshold2 * prev_scale + next.threshold2 * next_scale);
83 this->sharpness = (int)(prev.sharpness * prev_scale + next.sharpness * next_scale);
84 this->lcontrast = (int)(prev.lcontrast * prev_scale + next.lcontrast * next_scale);
85 this->ccontrast = (int)(prev.ccontrast * prev_scale + next.ccontrast * next_scale);
86 this->deinterlace = prev.deinterlace;
87 this->mode = prev.mode;
88 this->delay = (int)(prev.delay * prev_scale + next.delay * next_scale);
96 DenoiseMJPEGRadius::DenoiseMJPEGRadius(DenoiseMJPEG *plugin, int x, int y)
99 plugin->config.radius,
103 this->plugin = plugin;
106 int DenoiseMJPEGRadius::handle_event()
108 int result = get_value();
109 plugin->config.radius = result;
110 plugin->send_configure_change();
119 DenoiseMJPEGThresh::DenoiseMJPEGThresh(DenoiseMJPEG *plugin, int x, int y)
122 plugin->config.threshold,
126 this->plugin = plugin;
129 int DenoiseMJPEGThresh::handle_event()
131 int result = get_value();
132 plugin->config.threshold = result;
133 plugin->send_configure_change();
142 DenoiseMJPEGThresh2::DenoiseMJPEGThresh2(DenoiseMJPEG *plugin, int x, int y)
145 plugin->config.threshold2,
149 this->plugin = plugin;
152 int DenoiseMJPEGThresh2::handle_event()
154 int result = get_value();
155 plugin->config.threshold2 = result;
156 plugin->send_configure_change();
165 DenoiseMJPEGSharp::DenoiseMJPEGSharp(DenoiseMJPEG *plugin, int x, int y)
168 plugin->config.sharpness,
172 this->plugin = plugin;
175 int DenoiseMJPEGSharp::handle_event()
177 int result = get_value();
178 plugin->config.sharpness = result;
179 plugin->send_configure_change();
188 DenoiseMJPEGLContrast::DenoiseMJPEGLContrast(DenoiseMJPEG *plugin, int x, int y)
191 plugin->config.lcontrast,
195 this->plugin = plugin;
198 int DenoiseMJPEGLContrast::handle_event()
200 int result = get_value();
201 plugin->config.lcontrast = result;
202 plugin->send_configure_change();
211 DenoiseMJPEGCContrast::DenoiseMJPEGCContrast(DenoiseMJPEG *plugin, int x, int y)
214 plugin->config.ccontrast,
218 this->plugin = plugin;
221 int DenoiseMJPEGCContrast::handle_event()
223 int result = get_value();
224 plugin->config.ccontrast = result;
225 plugin->send_configure_change();
234 DenoiseMJPEGDeinterlace::DenoiseMJPEGDeinterlace(DenoiseMJPEG *plugin, int x, int y)
237 plugin->config.deinterlace,
240 this->plugin = plugin;
243 int DenoiseMJPEGDeinterlace::handle_event()
245 int result = get_value();
246 plugin->config.deinterlace = result;
247 plugin->send_configure_change();
256 DenoiseMJPEGModeProgressive::DenoiseMJPEGModeProgressive(DenoiseMJPEG *plugin, DenoiseMJPEGWindow *gui, int x, int y)
259 plugin->config.mode == 0,
262 this->plugin = plugin;
266 int DenoiseMJPEGModeProgressive::handle_event()
268 int result = get_value();
269 if(result) gui->update_mode(0);
270 plugin->send_configure_change();
275 DenoiseMJPEGModeInterlaced::DenoiseMJPEGModeInterlaced(DenoiseMJPEG *plugin, DenoiseMJPEGWindow *gui, int x, int y)
278 plugin->config.mode == 1,
281 this->plugin = plugin;
285 int DenoiseMJPEGModeInterlaced::handle_event()
287 int result = get_value();
288 if(result) gui->update_mode(1);
289 plugin->send_configure_change();
294 DenoiseMJPEGModeFast::DenoiseMJPEGModeFast(DenoiseMJPEG *plugin, DenoiseMJPEGWindow *gui, int x, int y)
297 plugin->config.mode == 2,
300 this->plugin = plugin;
304 int DenoiseMJPEGModeFast::handle_event()
306 int result = get_value();
307 if(result) gui->update_mode(2);
308 plugin->send_configure_change();
317 DenoiseMJPEGDelay::DenoiseMJPEGDelay(DenoiseMJPEG *plugin, int x, int y)
320 plugin->config.delay,
324 this->plugin = plugin;
327 int DenoiseMJPEGDelay::handle_event()
329 int result = get_value();
330 plugin->config.delay = result;
331 plugin->send_configure_change();
345 DenoiseMJPEGWindow::DenoiseMJPEGWindow(DenoiseMJPEG *plugin, int x, int y)
346 : BC_Window(plugin->gui_string,
357 this->plugin = plugin;
361 void DenoiseMJPEGWindow::create_objects()
363 int x1 = 10, y1 = 20, x2 = 140, x3 = 180, y2 = 10, margin = 30, margin2 = 25;
364 add_subwindow(new BC_Title(x1, y1, _("Search radius:")));
365 add_subwindow(radius = new DenoiseMJPEGRadius(plugin, x2, y2));
368 add_subwindow(new BC_Title(x1, y1, _("Pass 1 threshold:")));
369 add_subwindow(threshold1 = new DenoiseMJPEGThresh(plugin, x3, y2));
372 add_subwindow(new BC_Title(x1, y1, _("Pass 2 threshold:")));
373 add_subwindow(threshold2 = new DenoiseMJPEGThresh2(plugin, x2, y2));
376 add_subwindow(new BC_Title(x1, y1, _("Sharpness:")));
377 add_subwindow(sharpness = new DenoiseMJPEGSharp(plugin, x3, y2));
380 add_subwindow(new BC_Title(x1, y1, _("Luma contrast:")));
381 add_subwindow(lcontrast = new DenoiseMJPEGLContrast(plugin, x2, y2));
384 add_subwindow(new BC_Title(x1, y1, _("Chroma contrast:")));
385 add_subwindow(ccontrast = new DenoiseMJPEGCContrast(plugin, x3, y2));
388 add_subwindow(new BC_Title(x1, y1, _("Delay frames:")));
389 add_subwindow(delay = new DenoiseMJPEGDelay(plugin, x2, y2));
392 add_subwindow(new BC_Title(x1, y1, _("Mode:")));
393 add_subwindow(interlaced = new DenoiseMJPEGModeInterlaced(plugin, this, x2, y1));
396 add_subwindow(progressive = new DenoiseMJPEGModeProgressive(plugin, this, x2, y1));
399 add_subwindow(fast = new DenoiseMJPEGModeFast(plugin, this, x2, y1));
402 add_subwindow(deinterlace = new DenoiseMJPEGDeinterlace(plugin, x1, y1));
408 void DenoiseMJPEGWindow::update_mode(int value)
410 plugin->config.mode = value;
411 progressive->update(value == 0);
412 interlaced->update(value == 1);
413 fast->update(value == 2);
416 int DenoiseMJPEGWindow::close_event()
427 PLUGIN_THREAD_OBJECT(DenoiseMJPEG, DenoiseMJPEGThread, DenoiseMJPEGWindow)
439 DenoiseMJPEG::DenoiseMJPEG(PluginServer *server)
440 : PluginVClient(server)
442 PLUGIN_CONSTRUCTOR_MACRO
447 DenoiseMJPEG::~DenoiseMJPEG()
449 PLUGIN_DESTRUCTOR_MACRO
451 if(accumulation) delete [] accumulation;
454 int DenoiseMJPEG::process_realtime(VFrame *input, VFrame *output)
456 load_configuration();
460 char* DenoiseMJPEG::plugin_title() { return N_("Denoise video2"); }
461 int DenoiseMJPEG::is_realtime() { return 1; }
463 VFrame* DenoiseMJPEG::new_picon()
465 return new VFrame(picon_png);
468 SHOW_GUI_MACRO(DenoiseMJPEG, DenoiseMJPEGThread)
470 RAISE_WINDOW_MACRO(DenoiseMJPEG)
472 void DenoiseMJPEG::update_gui()
476 load_configuration();
477 thread->window->lock_window();
478 thread->window->delay->update(config.delay);
479 thread->window->threshold1->update(config.threshold);
480 thread->window->unlock_window();
486 SET_STRING_MACRO(DenoiseMJPEG);
488 LOAD_CONFIGURATION_MACRO(DenoiseMJPEG, DenoiseMJPEGConfig)
490 int DenoiseMJPEG::load_defaults()
492 char directory[BCTEXTLEN];
493 // set the default directory
494 sprintf(directory, "%sdenoisevideo.rc", BCASTDIR);
497 defaults = new BC_Hash(directory);
500 config.radius = defaults->get("RADIUS", config.radius);
501 config.threshold = defaults->get("THRESHOLD", config.threshold);
502 config.threshold2 = defaults->get("THRESHOLD2", config.threshold2);
503 config.sharpness = defaults->get("SHARPNESS", config.sharpness);
504 config.lcontrast = defaults->get("LCONTRAST", config.lcontrast);
505 config.ccontrast = defaults->get("CCONTRAST", config.ccontrast);
506 config.deinterlace = defaults->get("DEINTERLACE", config.deinterlace);
507 config.mode = defaults->get("MODE", config.mode);
508 config.delay = defaults->get("DELAY", config.delay);
512 int DenoiseMJPEG::save_defaults()
514 defaults->update("RADIUS", config.radius);
515 defaults->update("THRESHOLD", config.threshold);
516 defaults->update("THRESHOLD2", config.threshold2);
517 defaults->update("SHARPNESS", config.sharpness);
518 defaults->update("LCONTRAST", config.lcontrast);
519 defaults->update("CCONTRAST", config.ccontrast);
520 defaults->update("DEINTERLACE", config.deinterlace);
521 defaults->update("MODE", config.mode);
522 defaults->update("DELAY", config.delay);
527 void DenoiseMJPEG::save_data(KeyFrame *keyframe)
531 // cause data to be stored directly in text
532 output.set_shared_string(keyframe->data, MESSAGESIZE);
533 output.tag.set_title("DENOISE_VIDEO2");
534 output.tag.set_property("RADIUS", config.radius);
535 output.tag.set_property("THRESHOLD", config.threshold);
536 output.tag.set_property("THRESHOLD2", config.threshold2);
537 output.tag.set_property("SHARPNESS", config.sharpness);
538 output.tag.set_property("LCONTRAST", config.lcontrast);
539 output.tag.set_property("CCONTRAST", config.ccontrast);
540 output.tag.set_property("DEINTERLACE", config.deinterlace);
541 output.tag.set_property("MODE", config.mode);
542 output.tag.set_property("DELAY", config.delay);
544 output.tag.set_title("/DENOISE_VIDEO2");
546 output.terminate_string();
549 void DenoiseMJPEG::read_data(KeyFrame *keyframe)
553 input.set_shared_string(keyframe->data, strlen(keyframe->data));
557 while(!input.read_tag())
559 if(input.tag.title_is("DENOISE_VIDEO2"))
561 config.radius = input.tag.get_property("RADIUS", config.radius);
562 config.threshold = input.tag.get_property("THRESHOLD", config.threshold);
563 config.threshold2 = input.tag.get_property("THRESHOLD2", config.threshold2);
564 config.sharpness = input.tag.get_property("SHARPNESS", config.sharpness);
565 config.lcontrast = input.tag.get_property("LCONTRAST", config.lcontrast);
566 config.ccontrast = input.tag.get_property("CCONTRAST", config.ccontrast);
567 config.deinterlace = input.tag.get_property("DEINTERLACE", config.deinterlace);
568 config.mode = input.tag.get_property("MODE", config.mode);
569 config.delay = input.tag.get_property("DELAY", config.delay);