1 #include "bcdisplayinfo.h"
7 #include "loadbalance.h"
9 #include "plugincolors.h"
10 #include "pluginvclient.h"
21 #define MINSATURATION -100
22 #define MAXSATURATION 100
36 void copy_from(HueConfig &src);
37 int equivalent(HueConfig &src);
38 void interpolate(HueConfig &prev,
43 float hue, saturation, value;
46 class HueSlider : public BC_FSlider
49 HueSlider(HueEffect *plugin, int x, int y, int w);
54 class SaturationSlider : public BC_FSlider
57 SaturationSlider(HueEffect *plugin, int x, int y, int w);
62 class ValueSlider : public BC_FSlider
65 ValueSlider(HueEffect *plugin, int x, int y, int w);
70 class HueWindow : public BC_Window
73 HueWindow(HueEffect *plugin, int x, int y);
74 void create_objects();
78 SaturationSlider *saturation;
82 PLUGIN_THREAD_HEADER(HueEffect, HueThread, HueWindow)
84 class HueEngine : public LoadServer
87 HueEngine(HueEffect *plugin, int cpus);
89 LoadClient* new_client();
90 LoadPackage* new_package();
94 class HuePackage : public LoadPackage
101 class HueUnit : public LoadClient
104 HueUnit(HueEffect *plugin, HueEngine *server);
105 void process_package(LoadPackage *package);
110 class HueEffect : public PluginVClient
113 HueEffect(PluginServer *server);
116 int process_realtime(VFrame *input, VFrame *output);
118 char* plugin_title();
120 int load_configuration();
123 void save_data(KeyFrame *keyframe);
124 void read_data(KeyFrame *keyframe);
131 VFrame *input, *output;
156 HueConfig::HueConfig()
158 hue = saturation = value = 0;
161 void HueConfig::copy_from(HueConfig &src)
164 saturation = src.saturation;
167 int HueConfig::equivalent(HueConfig &src)
169 return EQUIV(hue, src.hue) &&
170 EQUIV(saturation, src.saturation) &&
171 EQUIV(value, src.value);
173 void HueConfig::interpolate(HueConfig &prev,
179 double next_scale = (double)(current_frame - prev_frame) / (next_frame - prev_frame);
180 double prev_scale = (double)(next_frame - current_frame) / (next_frame - prev_frame);
182 this->hue = prev.hue * prev_scale + next.hue * next_scale;
183 this->saturation = prev.saturation * prev_scale + next.saturation * next_scale;
184 this->value = prev.value * prev_scale + next.value * next_scale;
194 HueSlider::HueSlider(HueEffect *plugin, int x, int y, int w)
204 this->plugin = plugin;
206 int HueSlider::handle_event()
208 plugin->config.hue = get_value();
209 plugin->send_configure_change();
219 SaturationSlider::SaturationSlider(HueEffect *plugin, int x, int y, int w)
225 (float)MINSATURATION,
226 (float)MAXSATURATION,
227 plugin->config.saturation)
229 this->plugin = plugin;
231 int SaturationSlider::handle_event()
233 plugin->config.saturation = get_value();
234 plugin->send_configure_change();
244 ValueSlider::ValueSlider(HueEffect *plugin, int x, int y, int w)
252 plugin->config.value)
254 this->plugin = plugin;
256 int ValueSlider::handle_event()
258 plugin->config.value = get_value();
259 plugin->send_configure_change();
270 HueWindow::HueWindow(HueEffect *plugin, int x, int y)
271 : BC_Window(plugin->gui_string,
282 this->plugin = plugin;
284 void HueWindow::create_objects()
286 int x = 10, y = 10, x1 = 100;
287 add_subwindow(new BC_Title(x, y, _("Hue:")));
288 add_subwindow(hue = new HueSlider(plugin, x1, y, 200));
290 add_subwindow(new BC_Title(x, y, _("Saturation:")));
291 add_subwindow(saturation = new SaturationSlider(plugin, x1, y, 200));
293 add_subwindow(new BC_Title(x, y, _("Value:")));
294 add_subwindow(value = new ValueSlider(plugin, x1, y, 200));
300 WINDOW_CLOSE_EVENT(HueWindow)
309 PLUGIN_THREAD_OBJECT(HueEffect, HueThread, HueWindow)
311 HueEngine::HueEngine(HueEffect *plugin, int cpus)
312 : LoadServer(cpus, cpus)
314 this->plugin = plugin;
316 void HueEngine::init_packages()
318 int increment = plugin->input->get_h() / LoadServer::total_packages + 1;
320 for(int i = 0; i < LoadServer::total_packages; i++)
322 HuePackage *pkg = (HuePackage*)packages[i];
324 pkg->row2 = y + increment;
326 if(pkg->row2 > plugin->input->get_h())
328 y = pkg->row2 = plugin->input->get_h();
332 LoadClient* HueEngine::new_client()
334 return new HueUnit(plugin, this);
336 LoadPackage* HueEngine::new_package()
338 return new HuePackage;
348 HuePackage::HuePackage()
353 HueUnit::HueUnit(HueEffect *plugin, HueEngine *server)
356 this->plugin = plugin;
365 #define HUESATURATION(type, max, components, use_yuv) \
367 float h_offset = plugin->config.hue; \
368 float s_offset = ((float)plugin->config.saturation - MINSATURATION) / MAXSATURATION; \
369 float v_offset = ((float)plugin->config.value - MINVALUE) / MAXVALUE; \
370 for(int i = pkg->row1; i < pkg->row2; i++) \
372 type* in_row = (type*)plugin->input->get_rows()[i]; \
373 type* out_row = (type*)plugin->output->get_rows()[i]; \
375 for(int j = 0; j < w; j++) \
384 y = (int)in_row[0]; \
385 u = (int)in_row[1]; \
386 v = (int)in_row[2]; \
388 yuv.yuv_to_rgb_16(r_i, g_i, b_i, y, u, v); \
390 yuv.yuv_to_rgb_8(r_i, g_i, b_i, y, u, v); \
391 HSV::rgb_to_hsv((float)r_i / max, \
400 r = (float)in_row[0] / max; \
401 g = (float)in_row[1] / max; \
402 b = (float)in_row[2] / max; \
403 HSV::rgb_to_hsv(r, g, b, h, s, va); \
411 if(h >= 360) h -= 360; \
412 if(h < 0) h += 360; \
413 if(sizeof(type) < 4) \
423 HSV::hsv_to_yuv(y, u, v, h, s, va, max); \
430 HSV::hsv_to_rgb(r, g, b, h, s, va); \
431 if(sizeof(type) < 4) \
436 out_row[0] = (type)CLIP(r, 0, max); \
437 out_row[1] = (type)CLIP(g, 0, max); \
438 out_row[2] = (type)CLIP(b, 0, max); \
442 out_row[0] = (type)r; \
443 out_row[1] = (type)g; \
444 out_row[2] = (type)b; \
448 in_row += components; \
449 out_row += components; \
455 void HueUnit::process_package(LoadPackage *package)
457 HuePackage *pkg = (HuePackage*)package;
458 int w = plugin->input->get_w();
460 switch(plugin->input->get_color_model())
463 HUESATURATION(unsigned char, 0xff, 3, 0)
467 HUESATURATION(float, 1, 3, 0)
471 HUESATURATION(unsigned char, 0xff, 3, 1)
475 HUESATURATION(uint16_t, 0xffff, 3, 0)
479 HUESATURATION(uint16_t, 0xffff, 3, 1)
483 HUESATURATION(float, 1, 4, 0)
487 HUESATURATION(unsigned char, 0xff, 4, 0)
491 HUESATURATION(unsigned char, 0xff, 4, 1)
494 case BC_RGBA16161616:
495 HUESATURATION(uint16_t, 0xffff, 4, 0)
498 case BC_YUVA16161616:
499 HUESATURATION(uint16_t, 0xffff, 4, 1)
508 REGISTER_PLUGIN(HueEffect)
511 HueEffect::HueEffect(PluginServer *server)
512 : PluginVClient(server)
515 PLUGIN_CONSTRUCTOR_MACRO
517 HueEffect::~HueEffect()
519 PLUGIN_DESTRUCTOR_MACRO
520 if(engine) delete engine;
523 int HueEffect::process_realtime(VFrame *input, VFrame *output)
525 load_configuration();
527 this->output = output;
528 if(EQUIV(config.hue, 0) && EQUIV(config.saturation, 0) && EQUIV(config.value, 0))
530 if(input->get_rows()[0] != output->get_rows()[0])
531 output->copy_from(input);
535 if(!engine) engine = new HueEngine(this, PluginClient::smp + 1);
537 engine->process_packages();
542 char* HueEffect::plugin_title() { return N_("Hue saturation"); }
543 int HueEffect::is_realtime() { return 1; }
545 NEW_PICON_MACRO(HueEffect)
546 SHOW_GUI_MACRO(HueEffect, HueThread)
547 SET_STRING_MACRO(HueEffect)
548 RAISE_WINDOW_MACRO(HueEffect)
549 LOAD_CONFIGURATION_MACRO(HueEffect, HueConfig)
551 int HueEffect::load_defaults()
553 char directory[BCTEXTLEN];
554 sprintf(directory, "%shuesaturation.rc", BCASTDIR);
555 defaults = new Defaults(directory);
557 config.hue = defaults->get("HUE", config.hue);
558 config.saturation = defaults->get("SATURATION", config.saturation);
559 config.value = defaults->get("VALUE", config.value);
562 int HueEffect::save_defaults()
564 defaults->update("HUE", config.hue);
565 defaults->update("SATURATION", config.saturation);
566 defaults->update("VALUE", config.value);
570 void HueEffect::save_data(KeyFrame *keyframe)
573 output.set_shared_string(keyframe->data, MESSAGESIZE);
574 output.tag.set_title("HUESATURATION");
575 output.tag.set_property("HUE", config.hue);
576 output.tag.set_property("SATURATION", config.saturation);
577 output.tag.set_property("VALUE", config.value);
579 output.terminate_string();
581 void HueEffect::read_data(KeyFrame *keyframe)
584 input.set_shared_string(keyframe->data, strlen(keyframe->data));
585 while(!input.read_tag())
587 if(input.tag.title_is("HUESATURATION"))
589 config.hue = input.tag.get_property("HUE", config.hue);
590 config.saturation = input.tag.get_property("SATURATION", config.saturation);
591 config.value = input.tag.get_property("VALUE", config.value);
595 void HueEffect::update_gui()
599 thread->window->lock_window();
600 load_configuration();
601 thread->window->hue->update(config.hue);
602 thread->window->saturation->update(config.saturation);
603 thread->window->value->update(config.value);
604 thread->window->unlock_window();