r105: This commit was manufactured by cvs2svn to create tag
[cinelerra_cv/mob.git] / hvirtual / plugins / translate / translate.C
blob8f6cac5251715f608171a558394d4c327045f260
1 #include "clip.h"
2 #include "filexml.h"
3 #include "picon_png.h"
4 #include "translate.h"
5 #include "translatewin.h"
7 #include <string.h>
9 #include <libintl.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()
19         in_x = 0;
20         in_y = 0;
21         in_w = 720;
22         in_h = 480;
23         out_x = 0;
24         out_y = 0;
25         out_w = 720;
26         out_h = 480;
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)
43         in_x = that.in_x;
44         in_y = that.in_y;
45         in_w = that.in_w;
46         in_h = that.in_h;
47         out_x = that.out_x;
48         out_y = that.out_y;
49         out_w = that.out_w;
50         out_h = that.out_h;
53 void TranslateConfig::interpolate(TranslateConfig &prev, 
54         TranslateConfig &next, 
55         int64_t prev_frame, 
56         int64_t next_frame, 
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)
82         temp_frame = 0;
83         overlayer = 0;
84         PLUGIN_CONSTRUCTOR_MACRO
87 TranslateMain::~TranslateMain()
89         PLUGIN_DESTRUCTOR_MACRO
91         if(temp_frame) delete temp_frame;
92         temp_frame = 0;
93         if(overlayer) delete overlayer;
94         overlayer = 0;
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);
108 // load the defaults
109         defaults = new Defaults(directory);
110         defaults->load();
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);
133         defaults->save();
136 LOAD_CONFIGURATION_MACRO(TranslateMain, TranslateConfig)
138 void TranslateMain::save_data(KeyFrame *keyframe)
140         FileXML output;
142 // cause data to be stored directly in text
143         output.set_shared_string(keyframe->data, MESSAGESIZE);
145 // Store data
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);
155         output.append_tag();
157         output.terminate_string();
158 // data is now in *text
161 void TranslateMain::read_data(KeyFrame *keyframe)
163         FileXML input;
165         input.set_shared_string(keyframe->data, strlen(keyframe->data));
167         int result = 0;
169         while(!result)
170         {
171                 result = input.read_tag();
173                 if(!result)
174                 {
175                         if(input.tag.title_is("TRANSLATE"))
176                         {
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);
185                         }
186                 }
187         }
197 int TranslateMain::process_realtime(VFrame *input_ptr, VFrame *output_ptr)
199         VFrame *input, *output;
200         
201         
202         input = input_ptr;
203         output = output_ptr;
205         load_configuration();
207 //printf("TranslateMain::process_realtime 1 %p\n", input);
208         if(input->get_rows()[0] == output->get_rows()[0])
209         {
210                 if(!temp_frame) 
211                         temp_frame = new VFrame(0, 
212                                 input_ptr->get_w(), 
213                                 input_ptr->get_h(),
214                                 input->get_color_model());
215                 temp_frame->copy_from(input);
216                 input = temp_frame;
217         }
218 //printf("TranslateMain::process_realtime 2 %p\n", input);
221         if(!overlayer)
222         {
223                 overlayer = new OverlayFrame(smp + 1);
224         }
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", 
231 //      output,
232 //      input,
233 //      config.w, 
234 //      config.h,
235 //      in_x1, 
236 //      in_y1, 
237 //      in_x2, 
238 //      in_y2,
239 //      out_x1, 
240 //      out_y1, 
241 //      out_x2, 
242 //      out_y2);
243                 overlayer->overlay(output, 
244                         input,
245                         config.in_x, 
246                         config.in_y, 
247                         config.in_x + config.in_w,
248                         config.in_y + config.in_h,
249                         config.out_x, 
250                         config.out_y, 
251                         config.out_x + config.out_w,
252                         config.out_y + config.out_h,
253                         1,
254                         TRANSFER_REPLACE,
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()
270         if(thread)
271         {
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();
283         }