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 for(int i = 0; i < LoadServer::get_total_packages(); i++)
320 HuePackage *pkg = (HuePackage*)get_package(i);
321 pkg->row1 = plugin->input->get_h() * i / LoadServer::get_total_packages();
322 pkg->row2 = plugin->input->get_h() * (i + 1) / LoadServer::get_total_packages();
325 LoadClient* HueEngine::new_client()
327 return new HueUnit(plugin, this);
329 LoadPackage* HueEngine::new_package()
331 return new HuePackage;
341 HuePackage::HuePackage()
346 HueUnit::HueUnit(HueEffect *plugin, HueEngine *server)
349 this->plugin = plugin;
358 #define HUESATURATION(type, max, components, use_yuv) \
360 float h_offset = plugin->config.hue; \
361 float s_offset = ((float)plugin->config.saturation - MINSATURATION) / MAXSATURATION; \
362 float v_offset = ((float)plugin->config.value - MINVALUE) / MAXVALUE; \
363 for(int i = pkg->row1; i < pkg->row2; i++) \
365 type* in_row = (type*)plugin->input->get_rows()[i]; \
366 type* out_row = (type*)plugin->output->get_rows()[i]; \
368 for(int j = 0; j < w; j++) \
377 y = (int)in_row[0]; \
378 u = (int)in_row[1]; \
379 v = (int)in_row[2]; \
381 yuv.yuv_to_rgb_16(r_i, g_i, b_i, y, u, v); \
383 yuv.yuv_to_rgb_8(r_i, g_i, b_i, y, u, v); \
384 HSV::rgb_to_hsv((float)r_i / max, \
393 r = (float)in_row[0] / max; \
394 g = (float)in_row[1] / max; \
395 b = (float)in_row[2] / max; \
396 HSV::rgb_to_hsv(r, g, b, h, s, va); \
404 if(h >= 360) h -= 360; \
405 if(h < 0) h += 360; \
406 if(sizeof(type) < 4) \
416 HSV::hsv_to_yuv(y, u, v, h, s, va, max); \
423 HSV::hsv_to_rgb(r, g, b, h, s, va); \
424 if(sizeof(type) < 4) \
429 out_row[0] = (type)CLIP(r, 0, max); \
430 out_row[1] = (type)CLIP(g, 0, max); \
431 out_row[2] = (type)CLIP(b, 0, max); \
435 out_row[0] = (type)r; \
436 out_row[1] = (type)g; \
437 out_row[2] = (type)b; \
441 in_row += components; \
442 out_row += components; \
448 void HueUnit::process_package(LoadPackage *package)
450 HuePackage *pkg = (HuePackage*)package;
451 int w = plugin->input->get_w();
453 switch(plugin->input->get_color_model())
456 HUESATURATION(unsigned char, 0xff, 3, 0)
460 HUESATURATION(float, 1, 3, 0)
464 HUESATURATION(unsigned char, 0xff, 3, 1)
468 HUESATURATION(uint16_t, 0xffff, 3, 0)
472 HUESATURATION(uint16_t, 0xffff, 3, 1)
476 HUESATURATION(float, 1, 4, 0)
480 HUESATURATION(unsigned char, 0xff, 4, 0)
484 HUESATURATION(unsigned char, 0xff, 4, 1)
487 case BC_RGBA16161616:
488 HUESATURATION(uint16_t, 0xffff, 4, 0)
491 case BC_YUVA16161616:
492 HUESATURATION(uint16_t, 0xffff, 4, 1)
501 REGISTER_PLUGIN(HueEffect)
504 HueEffect::HueEffect(PluginServer *server)
505 : PluginVClient(server)
508 PLUGIN_CONSTRUCTOR_MACRO
510 HueEffect::~HueEffect()
512 PLUGIN_DESTRUCTOR_MACRO
513 if(engine) delete engine;
516 int HueEffect::process_realtime(VFrame *input, VFrame *output)
518 load_configuration();
520 this->output = output;
521 if(EQUIV(config.hue, 0) && EQUIV(config.saturation, 0) && EQUIV(config.value, 0))
523 if(input->get_rows()[0] != output->get_rows()[0])
524 output->copy_from(input);
528 if(!engine) engine = new HueEngine(this, PluginClient::smp + 1);
530 engine->process_packages();
535 char* HueEffect::plugin_title() { return N_("Hue saturation"); }
536 int HueEffect::is_realtime() { return 1; }
538 NEW_PICON_MACRO(HueEffect)
539 SHOW_GUI_MACRO(HueEffect, HueThread)
540 SET_STRING_MACRO(HueEffect)
541 RAISE_WINDOW_MACRO(HueEffect)
542 LOAD_CONFIGURATION_MACRO(HueEffect, HueConfig)
544 int HueEffect::load_defaults()
546 char directory[BCTEXTLEN];
547 sprintf(directory, "%shuesaturation.rc", BCASTDIR);
548 defaults = new BC_Hash(directory);
550 config.hue = defaults->get("HUE", config.hue);
551 config.saturation = defaults->get("SATURATION", config.saturation);
552 config.value = defaults->get("VALUE", config.value);
555 int HueEffect::save_defaults()
557 defaults->update("HUE", config.hue);
558 defaults->update("SATURATION", config.saturation);
559 defaults->update("VALUE", config.value);
563 void HueEffect::save_data(KeyFrame *keyframe)
566 output.set_shared_string(keyframe->data, MESSAGESIZE);
567 output.tag.set_title("HUESATURATION");
568 output.tag.set_property("HUE", config.hue);
569 output.tag.set_property("SATURATION", config.saturation);
570 output.tag.set_property("VALUE", config.value);
572 output.terminate_string();
574 void HueEffect::read_data(KeyFrame *keyframe)
577 input.set_shared_string(keyframe->data, strlen(keyframe->data));
578 while(!input.read_tag())
580 if(input.tag.title_is("HUESATURATION"))
582 config.hue = input.tag.get_property("HUE", config.hue);
583 config.saturation = input.tag.get_property("SATURATION", config.saturation);
584 config.value = input.tag.get_property("VALUE", config.value);
588 void HueEffect::update_gui()
592 thread->window->lock_window();
593 load_configuration();
594 thread->window->hue->update(config.hue);
595 thread->window->saturation->update(config.saturation);
596 thread->window->value->update(config.value);
597 thread->window->unlock_window();