1 #include "bcdisplayinfo.h"
6 #include "loadbalance.h"
8 #include "plugincolors.h"
9 #include "pluginvclient.h"
16 #define _(String) gettext(String)
17 #define gettext_noop(String) String
18 #define N_(String) gettext_noop (String)
24 #define MINSATURATION -100
25 #define MAXSATURATION 100
39 void copy_from(HueConfig &src);
40 int equivalent(HueConfig &src);
41 void interpolate(HueConfig &prev,
46 float hue, saturation, value;
49 class HueSlider : public BC_FSlider
52 HueSlider(HueEffect *plugin, int x, int y, int w);
57 class SaturationSlider : public BC_FSlider
60 SaturationSlider(HueEffect *plugin, int x, int y, int w);
65 class ValueSlider : public BC_FSlider
68 ValueSlider(HueEffect *plugin, int x, int y, int w);
73 class HueWindow : public BC_Window
76 HueWindow(HueEffect *plugin, int x, int y);
77 void create_objects();
81 SaturationSlider *saturation;
85 PLUGIN_THREAD_HEADER(HueEffect, HueThread, HueWindow)
87 class HueEngine : public LoadServer
90 HueEngine(HueEffect *plugin, int cpus);
92 LoadClient* new_client();
93 LoadPackage* new_package();
97 class HuePackage : public LoadPackage
104 class HueUnit : public LoadClient
107 HueUnit(HueEffect *plugin, HueEngine *server);
108 void process_package(LoadPackage *package);
113 class HueEffect : public PluginVClient
116 HueEffect(PluginServer *server);
119 int process_realtime(VFrame *input, VFrame *output);
121 char* plugin_title();
123 int load_configuration();
126 void save_data(KeyFrame *keyframe);
127 void read_data(KeyFrame *keyframe);
134 VFrame *input, *output;
159 HueConfig::HueConfig()
161 hue = saturation = value = 0;
164 void HueConfig::copy_from(HueConfig &src)
167 saturation = src.saturation;
170 int HueConfig::equivalent(HueConfig &src)
172 return EQUIV(hue, src.hue) &&
173 EQUIV(saturation, src.saturation) &&
174 EQUIV(value, src.value);
176 void HueConfig::interpolate(HueConfig &prev,
182 double next_scale = (double)(current_frame - prev_frame) / (next_frame - prev_frame);
183 double prev_scale = (double)(next_frame - current_frame) / (next_frame - prev_frame);
185 this->hue = prev.hue * prev_scale + next.hue * next_scale;
186 this->saturation = prev.saturation * prev_scale + next.saturation * next_scale;
187 this->value = prev.value * prev_scale + next.value * next_scale;
197 HueSlider::HueSlider(HueEffect *plugin, int x, int y, int w)
207 this->plugin = plugin;
209 int HueSlider::handle_event()
211 plugin->config.hue = get_value();
212 plugin->send_configure_change();
222 SaturationSlider::SaturationSlider(HueEffect *plugin, int x, int y, int w)
228 (float)MINSATURATION,
229 (float)MAXSATURATION,
230 plugin->config.saturation)
232 this->plugin = plugin;
234 int SaturationSlider::handle_event()
236 plugin->config.saturation = get_value();
237 plugin->send_configure_change();
247 ValueSlider::ValueSlider(HueEffect *plugin, int x, int y, int w)
255 plugin->config.value)
257 this->plugin = plugin;
259 int ValueSlider::handle_event()
261 plugin->config.value = get_value();
262 plugin->send_configure_change();
273 HueWindow::HueWindow(HueEffect *plugin, int x, int y)
274 : BC_Window(plugin->gui_string,
285 this->plugin = plugin;
287 void HueWindow::create_objects()
289 int x = 10, y = 10, x1 = 100;
290 add_subwindow(new BC_Title(x, y, _("Hue:")));
291 add_subwindow(hue = new HueSlider(plugin, x1, y, 200));
293 add_subwindow(new BC_Title(x, y, _("Saturation:")));
294 add_subwindow(saturation = new SaturationSlider(plugin, x1, y, 200));
296 add_subwindow(new BC_Title(x, y, _("Value:")));
297 add_subwindow(value = new ValueSlider(plugin, x1, y, 200));
303 int HueWindow::close_event()
312 PLUGIN_THREAD_OBJECT(HueEffect, HueThread, HueWindow)
314 HueEngine::HueEngine(HueEffect *plugin, int cpus)
315 : LoadServer(cpus, cpus)
317 this->plugin = plugin;
319 void HueEngine::init_packages()
321 int increment = plugin->input->get_h() / LoadServer::total_packages + 1;
323 for(int i = 0; i < LoadServer::total_packages; i++)
325 HuePackage *pkg = (HuePackage*)packages[i];
327 pkg->row2 = y + increment;
329 if(pkg->row2 > plugin->input->get_h())
331 y = pkg->row2 = plugin->input->get_h();
335 LoadClient* HueEngine::new_client()
337 return new HueUnit(plugin, this);
339 LoadPackage* HueEngine::new_package()
341 return new HuePackage;
351 HuePackage::HuePackage()
356 HueUnit::HueUnit(HueEffect *plugin, HueEngine *server)
359 this->plugin = plugin;
368 #define HUESATURATION(type, max, components, use_yuv) \
370 float h_offset = plugin->config.hue; \
371 float s_offset = ((float)plugin->config.saturation + -MINSATURATION) / MAXSATURATION; \
372 float v_offset = ((float)plugin->config.value + -MINVALUE) / MAXVALUE; \
373 for(int i = pkg->row1; i < pkg->row2; i++) \
375 type* in_row = (type*)plugin->input->get_rows()[i]; \
376 type* out_row = (type*)plugin->output->get_rows()[i]; \
378 for(int j = 0; j < w; j++) \
391 yuv.yuv_to_rgb_16(r_i, g_i, b_i, y, u, v); \
393 yuv.yuv_to_rgb_8(r_i, g_i, b_i, y, u, v); \
394 HSV::rgb_to_hsv((float)r_i / max, \
403 r = (float)in_row[0] / max; \
404 g = (float)in_row[1] / max; \
405 b = (float)in_row[2] / max; \
406 HSV::rgb_to_hsv(r, g, b, h, s, va); \
414 if(h >= 360) h -= 360; \
417 if(h < 0) h += 360; \
423 HSV::hsv_to_yuv(y, u, v, h, s, va, max); \
430 HSV::hsv_to_rgb(r, g, b, h, s, va); \
434 out_row[0] = (int)CLIP(r, 0, max); \
435 out_row[1] = (int)CLIP(g, 0, max); \
436 out_row[2] = (int)CLIP(b, 0, max); \
440 if(components == 4) \
441 out_row[3] = in_row[3]; \
442 in_row += components; \
443 out_row += components; \
449 void HueUnit::process_package(LoadPackage *package)
451 HuePackage *pkg = (HuePackage*)package;
452 int w = plugin->input->get_w();
454 switch(plugin->input->get_color_model())
457 HUESATURATION(unsigned char, 0xff, 3, 0)
461 HUESATURATION(unsigned char, 0xff, 3, 1)
465 HUESATURATION(uint16_t, 0xffff, 3, 0)
469 HUESATURATION(uint16_t, 0xffff, 3, 1)
473 HUESATURATION(unsigned char, 0xff, 4, 0)
477 HUESATURATION(unsigned char, 0xff, 4, 1)
480 case BC_RGBA16161616:
481 HUESATURATION(uint16_t, 0xffff, 4, 0)
484 case BC_YUVA16161616:
485 HUESATURATION(uint16_t, 0xffff, 4, 1)
494 REGISTER_PLUGIN(HueEffect)
497 HueEffect::HueEffect(PluginServer *server)
498 : PluginVClient(server)
501 PLUGIN_CONSTRUCTOR_MACRO
503 HueEffect::~HueEffect()
505 PLUGIN_DESTRUCTOR_MACRO
506 if(engine) delete engine;
509 int HueEffect::process_realtime(VFrame *input, VFrame *output)
511 load_configuration();
513 this->output = output;
514 if(EQUIV(config.hue, 0) && EQUIV(config.saturation, 0) && EQUIV(config.value, 0))
516 if(input->get_rows()[0] != output->get_rows()[0])
517 output->copy_from(input);
521 if(!engine) engine = new HueEngine(this, PluginClient::smp + 1);
523 engine->process_packages();
527 int HueEffect::is_realtime()
531 char* HueEffect::plugin_title()
533 return _("Hue saturation");
536 NEW_PICON_MACRO(HueEffect)
537 SHOW_GUI_MACRO(HueEffect, HueThread)
538 SET_STRING_MACRO(HueEffect)
539 RAISE_WINDOW_MACRO(HueEffect)
540 LOAD_CONFIGURATION_MACRO(HueEffect, HueConfig)
542 int HueEffect::load_defaults()
544 char directory[BCTEXTLEN];
545 sprintf(directory, "%shuesaturation.rc", BCASTDIR);
546 defaults = new Defaults(directory);
548 config.hue = defaults->get("HUE", config.hue);
549 config.saturation = defaults->get("SATURATION", config.saturation);
550 config.value = defaults->get("VALUE", config.value);
553 int HueEffect::save_defaults()
555 defaults->update("HUE", config.hue);
556 defaults->update("SATURATION", config.saturation);
557 defaults->update("VALUE", config.value);
561 void HueEffect::save_data(KeyFrame *keyframe)
564 output.set_shared_string(keyframe->data, MESSAGESIZE);
565 output.tag.set_title("HUESATURATION");
566 output.tag.set_property("HUE", config.hue);
567 output.tag.set_property("SATURATION", config.saturation);
568 output.tag.set_property("VALUE", config.value);
570 output.terminate_string();
572 void HueEffect::read_data(KeyFrame *keyframe)
575 input.set_shared_string(keyframe->data, strlen(keyframe->data));
576 while(!input.read_tag())
578 if(input.tag.title_is("HUESATURATION"))
580 config.hue = input.tag.get_property("HUE", config.hue);
581 config.saturation = input.tag.get_property("SATURATION", config.saturation);
582 config.value = input.tag.get_property("VALUE", config.value);
586 void HueEffect::update_gui()
590 thread->window->lock_window();
591 load_configuration();
592 thread->window->hue->update(config.hue);
593 thread->window->saturation->update(config.saturation);
594 thread->window->value->update(config.value);
595 thread->window->unlock_window();