5 #include "translatewin.h"
10 #define _(String) gettext(String)
11 #define gettext_noop(String) String
12 #define N_(String) gettext_noop (String)
15 REGISTER_PLUGIN(TranslateMain)
17 TranslateConfig::TranslateConfig()
29 int TranslateConfig::equivalent(TranslateConfig &that)
31 return EQUIV(in_x, that.in_x) &&
32 EQUIV(in_y, that.in_y) &&
33 EQUIV(in_w, that.in_w) &&
34 EQUIV(in_h, that.in_h) &&
35 EQUIV(out_x, that.out_x) &&
36 EQUIV(out_y, that.out_y) &&
37 EQUIV(out_w, that.out_w) &&
38 EQUIV(out_h, that.out_h);
41 void TranslateConfig::copy_from(TranslateConfig &that)
53 void TranslateConfig::interpolate(TranslateConfig &prev,
54 TranslateConfig &next,
57 int64_t current_frame)
59 double next_scale = (double)(current_frame - prev_frame) / (next_frame - prev_frame);
60 double prev_scale = (double)(next_frame - current_frame) / (next_frame - prev_frame);
62 this->in_x = prev.in_x * prev_scale + next.in_x * next_scale;
63 this->in_y = prev.in_y * prev_scale + next.in_y * next_scale;
64 this->in_w = prev.in_w * prev_scale + next.in_w * next_scale;
65 this->in_h = prev.in_h * prev_scale + next.in_h * next_scale;
66 this->out_x = prev.out_x * prev_scale + next.out_x * next_scale;
67 this->out_y = prev.out_y * prev_scale + next.out_y * next_scale;
68 this->out_w = prev.out_w * prev_scale + next.out_w * next_scale;
69 this->out_h = prev.out_h * prev_scale + next.out_h * next_scale;
79 TranslateMain::TranslateMain(PluginServer *server)
80 : PluginVClient(server)
84 PLUGIN_CONSTRUCTOR_MACRO
87 TranslateMain::~TranslateMain()
89 PLUGIN_DESTRUCTOR_MACRO
91 if(temp_frame) delete temp_frame;
93 if(overlayer) delete overlayer;
97 char* TranslateMain::plugin_title() { return _("Translate"); }
98 int TranslateMain::is_realtime() { return 1; }
100 NEW_PICON_MACRO(TranslateMain)
102 int TranslateMain::load_defaults()
104 char directory[1024], string[1024];
105 // set the default directory
106 sprintf(directory, "%stranslate.rc", BCASTDIR);
109 defaults = new Defaults(directory);
113 config.in_x = defaults->get("IN_X", config.in_x);
114 config.in_y = defaults->get("IN_Y", config.in_y);
115 config.in_w = defaults->get("IN_W", config.in_w);
116 config.in_h = defaults->get("IN_H", config.in_h);
117 config.out_x = defaults->get("OUT_X", config.out_x);
118 config.out_y = defaults->get("OUT_Y", config.out_y);
119 config.out_w = defaults->get("OUT_W", config.out_w);
120 config.out_h = defaults->get("OUT_H", config.out_h);
123 int TranslateMain::save_defaults()
125 defaults->update("IN_X", config.in_x);
126 defaults->update("IN_Y", config.in_y);
127 defaults->update("IN_W", config.in_w);
128 defaults->update("IN_H", config.in_h);
129 defaults->update("OUT_X", config.out_x);
130 defaults->update("OUT_Y", config.out_y);
131 defaults->update("OUT_W", config.out_w);
132 defaults->update("OUT_H", config.out_h);
136 LOAD_CONFIGURATION_MACRO(TranslateMain, TranslateConfig)
138 void TranslateMain::save_data(KeyFrame *keyframe)
142 // cause data to be stored directly in text
143 output.set_shared_string(keyframe->data, MESSAGESIZE);
146 output.tag.set_title("TRANSLATE");
147 output.tag.set_property("IN_X", config.in_x);
148 output.tag.set_property("IN_Y", config.in_y);
149 output.tag.set_property("IN_W", config.in_w);
150 output.tag.set_property("IN_H", config.in_h);
151 output.tag.set_property("OUT_X", config.out_x);
152 output.tag.set_property("OUT_Y", config.out_y);
153 output.tag.set_property("OUT_W", config.out_w);
154 output.tag.set_property("OUT_H", config.out_h);
157 output.terminate_string();
158 // data is now in *text
161 void TranslateMain::read_data(KeyFrame *keyframe)
165 input.set_shared_string(keyframe->data, strlen(keyframe->data));
171 result = input.read_tag();
175 if(input.tag.title_is("TRANSLATE"))
177 config.in_x = input.tag.get_property("IN_X", config.in_x);
178 config.in_y = input.tag.get_property("IN_Y", config.in_y);
179 config.in_w = input.tag.get_property("IN_W", config.in_w);
180 config.in_h = input.tag.get_property("IN_H", config.in_h);
181 config.out_x = input.tag.get_property("OUT_X", config.out_x);
182 config.out_y = input.tag.get_property("OUT_Y", config.out_y);
183 config.out_w = input.tag.get_property("OUT_W", config.out_w);
184 config.out_h = input.tag.get_property("OUT_H", config.out_h);
197 int TranslateMain::process_realtime(VFrame *input_ptr, VFrame *output_ptr)
199 VFrame *input, *output;
205 load_configuration();
207 //printf("TranslateMain::process_realtime 1 %p\n", input);
208 if(input->get_rows()[0] == output->get_rows()[0])
211 temp_frame = new VFrame(0,
214 input->get_color_model());
215 temp_frame->copy_from(input);
218 //printf("TranslateMain::process_realtime 2 %p\n", input);
223 overlayer = new OverlayFrame(smp + 1);
226 output->clear_frame();
229 // printf("TranslateMain::process_realtime 3 output=%p input=%p config.w=%f config.h=%f"
230 // "%f %f %f %f -> %f %f %f %f\n",
243 overlayer->overlay(output,
247 config.in_x + config.in_w,
248 config.in_y + config.in_h,
251 config.out_x + config.out_w,
252 config.out_y + config.out_h,
255 get_interpolation_type());
262 SHOW_GUI_MACRO(TranslateMain, TranslateThread)
264 RAISE_WINDOW_MACRO(TranslateMain)
266 SET_STRING_MACRO(TranslateMain)
268 void TranslateMain::update_gui()
272 load_configuration();
273 thread->window->lock_window();
274 thread->window->in_x->update(config.in_x);
275 thread->window->in_y->update(config.in_y);
276 thread->window->in_w->update(config.in_w);
277 thread->window->in_h->update(config.in_h);
278 thread->window->out_x->update(config.out_x);
279 thread->window->out_y->update(config.out_y);
280 thread->window->out_w->update(config.out_w);
281 thread->window->out_h->update(config.out_h);
282 thread->window->unlock_window();