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 == 1);
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)
448 DenoiseMJPEG::~DenoiseMJPEG()
452 thread->window->set_done(0);
453 thread->completion.lock();
460 if(accumulation) delete [] accumulation;
463 int DenoiseMJPEG::process_realtime(VFrame *input, VFrame *output)
465 load_configuration();
469 int DenoiseMJPEG::is_realtime()
474 char* DenoiseMJPEG::plugin_title()
476 return _("Denoise video2");
479 VFrame* DenoiseMJPEG::new_picon()
481 return new VFrame(picon_png);
484 SHOW_GUI_MACRO(DenoiseMJPEG, DenoiseMJPEGThread)
486 RAISE_WINDOW_MACRO(DenoiseMJPEG)
488 void DenoiseMJPEG::update_gui()
492 load_configuration();
493 thread->window->lock_window();
494 thread->window->delay->update(config.delay);
495 thread->window->threshold1->update(config.threshold);
496 thread->window->unlock_window();
502 SET_STRING_MACRO(DenoiseMJPEG);
504 LOAD_CONFIGURATION_MACRO(DenoiseMJPEG, DenoiseMJPEGConfig)
506 int DenoiseMJPEG::load_defaults()
508 char directory[BCTEXTLEN];
509 // set the default directory
510 sprintf(directory, "%sdenoisevideo.rc", BCASTDIR);
513 defaults = new Defaults(directory);
516 config.radius = defaults->get("RADIUS", config.radius);
517 config.threshold = defaults->get("THRESHOLD", config.threshold);
518 config.threshold2 = defaults->get("THRESHOLD2", config.threshold2);
519 config.sharpness = defaults->get("SHARPNESS", config.sharpness);
520 config.lcontrast = defaults->get("LCONTRAST", config.lcontrast);
521 config.ccontrast = defaults->get("CCONTRAST", config.ccontrast);
522 config.deinterlace = defaults->get("DEINTERLACE", config.deinterlace);
523 config.mode = defaults->get("MODE", config.mode);
524 config.delay = defaults->get("DELAY", config.delay);
528 int DenoiseMJPEG::save_defaults()
530 defaults->update("RADIUS", config.radius);
531 defaults->update("THRESHOLD", config.threshold);
532 defaults->update("THRESHOLD2", config.threshold2);
533 defaults->update("SHARPNESS", config.sharpness);
534 defaults->update("LCONTRAST", config.lcontrast);
535 defaults->update("CCONTRAST", config.ccontrast);
536 defaults->update("DEINTERLACE", config.deinterlace);
537 defaults->update("MODE", config.mode);
538 defaults->update("DELAY", config.delay);
543 void DenoiseMJPEG::save_data(KeyFrame *keyframe)
547 // cause data to be stored directly in text
548 output.set_shared_string(keyframe->data, MESSAGESIZE);
549 output.tag.set_title("DENOISE_VIDEO2");
550 output.tag.set_property("RADIUS", config.radius);
551 output.tag.set_property("THRESHOLD", config.threshold);
552 output.tag.set_property("THRESHOLD2", config.threshold2);
553 output.tag.set_property("SHARPNESS", config.sharpness);
554 output.tag.set_property("LCONTRAST", config.lcontrast);
555 output.tag.set_property("CCONTRAST", config.ccontrast);
556 output.tag.set_property("DEINTERLACE", config.deinterlace);
557 output.tag.set_property("MODE", config.mode);
558 output.tag.set_property("DELAY", config.delay);
560 output.terminate_string();
563 void DenoiseMJPEG::read_data(KeyFrame *keyframe)
567 input.set_shared_string(keyframe->data, strlen(keyframe->data));
571 while(!input.read_tag())
573 if(input.tag.title_is("DENOISE_VIDEO2"))
575 config.radius = input.tag.get_property("RADIUS", config.radius);
576 config.threshold = input.tag.get_property("THRESHOLD", config.threshold);
577 config.threshold2 = input.tag.get_property("THRESHOLD2", config.threshold2);
578 config.sharpness = input.tag.get_property("SHARPNESS", config.sharpness);
579 config.lcontrast = input.tag.get_property("LCONTRAST", config.lcontrast);
580 config.ccontrast = input.tag.get_property("CCONTRAST", config.ccontrast);
581 config.deinterlace = input.tag.get_property("DEINTERLACE", config.deinterlace);
582 config.mode = input.tag.get_property("MODE", config.mode);
583 config.delay = input.tag.get_property("DELAY", config.delay);