r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / plugins / slide / slide.C
blob1e08de68d60657cbac7cadb34e5cb60ad83d40b1
1 #include "bcdisplayinfo.h"
2 #include "defaults.h"
3 #include "edl.inc"
4 #include "filexml.h"
5 #include "overlayframe.h"
6 #include "picon_png.h"
7 #include "vframe.h"
8 #include "slide.h"
11 #include <stdint.h>
12 #include <string.h>
14 #include <libintl.h>
15 #define _(String) gettext(String)
16 #define gettext_noop(String) String
17 #define N_(String) gettext_noop (String)
19 REGISTER_PLUGIN(SlideMain)
25 SlideLeft::SlideLeft(SlideMain *plugin, 
26         SlideWindow *window,
27         int x,
28         int y)
29  : BC_Radial(x, 
30                 y, 
31                 plugin->motion_direction == 0, 
32                 _("Left"))
34         this->plugin = plugin;
35         this->window = window;
38 int SlideLeft::handle_event()
40         update(1);
41         plugin->motion_direction = 0;
42         window->right->update(0);
43         plugin->send_configure_change();
44         return 0;
47 SlideRight::SlideRight(SlideMain *plugin, 
48         SlideWindow *window,
49         int x,
50         int y)
51  : BC_Radial(x, 
52                 y, 
53                 plugin->motion_direction == 1, 
54                 _("Right"))
56         this->plugin = plugin;
57         this->window = window;
60 int SlideRight::handle_event()
62         update(1);
63         plugin->motion_direction = 1;
64         window->left->update(0);
65         plugin->send_configure_change();
66         return 0;
69 SlideIn::SlideIn(SlideMain *plugin, 
70         SlideWindow *window,
71         int x,
72         int y)
73  : BC_Radial(x, 
74                 y, 
75                 plugin->direction == 0, 
76                 _("In"))
78         this->plugin = plugin;
79         this->window = window;
82 int SlideIn::handle_event()
84         update(1);
85         plugin->direction = 0;
86         window->out->update(0);
87         plugin->send_configure_change();
88         return 0;
91 SlideOut::SlideOut(SlideMain *plugin, 
92         SlideWindow *window,
93         int x,
94         int y)
95  : BC_Radial(x, 
96                 y, 
97                 plugin->direction == 1, 
98                 _("Out"))
100         this->plugin = plugin;
101         this->window = window;
104 int SlideOut::handle_event()
106         update(1);
107         plugin->direction = 1;
108         window->in->update(0);
109         plugin->send_configure_change();
110         return 0;
120 SlideWindow::SlideWindow(SlideMain *plugin, int x, int y)
121  : BC_Window(plugin->gui_string, 
122         x, 
123         y, 
124         320, 
125         100, 
126         320, 
127         100, 
128         0, 
129         0,
130         1)
132         this->plugin = plugin;
136 int SlideWindow::close_event()
138         set_done(1);
139         return 1;
142 void SlideWindow::create_objects()
144         int x = 10, y = 10;
145         add_subwindow(new BC_Title(x, y, _("Direction:")));
146         x += 100;
147         add_subwindow(left = new SlideLeft(plugin, 
148                 this,
149                 x,
150                 y));
151         x += 100;
152         add_subwindow(right = new SlideRight(plugin, 
153                 this,
154                 x,
155                 y));
157         y += 30;
158         x = 10;
159         add_subwindow(new BC_Title(x, y, _("Direction:")));
160         x += 100;
161         add_subwindow(in = new SlideIn(plugin, 
162                 this,
163                 x,
164                 y));
165         x += 100;
166         add_subwindow(out = new SlideOut(plugin, 
167                 this,
168                 x,
169                 y));
171         show_window();
172         flush();
178 PLUGIN_THREAD_OBJECT(SlideMain, SlideThread, SlideWindow)
185 SlideMain::SlideMain(PluginServer *server)
186  : PluginVClient(server)
188         motion_direction = 0;
189         direction = 0;
190         PLUGIN_CONSTRUCTOR_MACRO
193 SlideMain::~SlideMain()
195         PLUGIN_DESTRUCTOR_MACRO
198 char* SlideMain::plugin_title() { return _("Slide"); }
199 int SlideMain::is_video() { return 1; }
200 int SlideMain::is_transition() { return 1; }
201 int SlideMain::uses_gui() { return 1; }
202 SHOW_GUI_MACRO(SlideMain, SlideThread);
203 SET_STRING_MACRO(SlideMain)
204 RAISE_WINDOW_MACRO(SlideMain)
207 VFrame* SlideMain::new_picon()
209         return new VFrame(picon_png);
212 int SlideMain::load_defaults()
214         char directory[BCTEXTLEN];
215 // set the default directory
216         sprintf(directory, "%sslide.rc", BCASTDIR);
218 // load the defaults
219         defaults = new Defaults(directory);
220         defaults->load();
222         motion_direction = defaults->get("MOTION_DIRECTION", motion_direction);
223         direction = defaults->get("DIRECTION", direction);
224         return 0;
227 int SlideMain::save_defaults()
229         defaults->update("MOTION_DIRECTION", motion_direction);
230         defaults->update("DIRECTION", direction);
231         defaults->save();
232         return 0;
235 void SlideMain::save_data(KeyFrame *keyframe)
237         FileXML output;
238         output.set_shared_string(keyframe->data, MESSAGESIZE);
239         output.tag.set_title("SLIDE");
240         output.tag.set_property("MOTION_DIRECTION", motion_direction);
241         output.tag.set_property("DIRECTION", direction);
242         output.append_tag();
243         output.terminate_string();
246 void SlideMain::read_data(KeyFrame *keyframe)
248         FileXML input;
250         input.set_shared_string(keyframe->data, strlen(keyframe->data));
252         while(!input.read_tag())
253         {
254                 if(input.tag.title_is("SLIDE"))
255                 {
256                         motion_direction = input.tag.get_property("MOTION_DIRECTION", motion_direction);
257                         direction = input.tag.get_property("DIRECTION", direction);
258                 }
259         }
262 void SlideMain::load_configuration()
264         read_data(get_prev_keyframe(get_source_position()));
272 #define SLIDE(type, components) \
273 { \
274         if(direction == 0) \
275         { \
276                 if(motion_direction == 0) \
277                 { \
278                         for(int j = 0; j < h; j++) \
279                         { \
280                                 type *in_row = (type*)incoming->get_rows()[j]; \
281                                 type *out_row = (type*)outgoing->get_rows()[j]; \
282                                 int x = w *  \
283                                         PluginClient::get_source_position() /  \
284                                         PluginClient::get_total_len(); \
285          \
286                                 for(int k = 0, l = w - x; k < x; k++, l++) \
287                                 { \
288                                         out_row[k * components + 0] = in_row[l * components + 0]; \
289                                         out_row[k * components + 1] = in_row[l * components + 1]; \
290                                         out_row[k * components + 2] = in_row[l * components + 2]; \
291                                         if(components == 4) out_row[k * components + 3] = in_row[l * components + 3]; \
292                                 } \
293                         } \
294                 } \
295                 else \
296                 { \
297                         for(int j = 0; j < h; j++) \
298                         { \
299                                 type *in_row = (type*)incoming->get_rows()[j]; \
300                                 type *out_row = (type*)outgoing->get_rows()[j]; \
301                                 int x = w - w *  \
302                                         PluginClient::get_source_position() /  \
303                                         PluginClient::get_total_len(); \
304          \
305                                 for(int k = x, l = 0; k < w; k++, l++) \
306                                 { \
307                                         out_row[k * components + 0] = in_row[l * components + 0]; \
308                                         out_row[k * components + 1] = in_row[l * components + 1]; \
309                                         out_row[k * components + 2] = in_row[l * components + 2]; \
310                                         if(components == 4) out_row[k * components + 3] = in_row[l * components + 3]; \
311                                 } \
312                         } \
313                 } \
314         } \
315         else \
316         { \
317                 if(motion_direction == 0) \
318                 { \
319                         for(int j = 0; j < h; j++) \
320                         { \
321                                 type *in_row = (type*)incoming->get_rows()[j]; \
322                                 type *out_row = (type*)outgoing->get_rows()[j]; \
323                                 int x = w - w *  \
324                                         PluginClient::get_source_position() /  \
325                                         PluginClient::get_total_len(); \
326          \
327                                 int k, l; \
328                                 for(k = 0, l = w - x; k < x; k++, l++) \
329                                 { \
330                                         out_row[k * components + 0] = out_row[l * components + 0]; \
331                                         out_row[k * components + 1] = out_row[l * components + 1]; \
332                                         out_row[k * components + 2] = out_row[l * components + 2]; \
333                                         if(components == 4) out_row[k * components + 3] = out_row[l * components + 3]; \
334                                 } \
335                                 for( ; k < w; k++) \
336                                 { \
337                                         out_row[k * components + 0] = in_row[k * components + 0]; \
338                                         out_row[k * components + 1] = in_row[k * components + 1]; \
339                                         out_row[k * components + 2] = in_row[k * components + 2]; \
340                                         if(components == 4) out_row[k * components + 3] = in_row[k * components + 3]; \
341                                 } \
342                         } \
343                 } \
344                 else \
345                 { \
346                         for(int j = 0; j < h; j++) \
347                         { \
348                                 type *in_row = (type*)incoming->get_rows()[j]; \
349                                 type *out_row = (type*)outgoing->get_rows()[j]; \
350                                 int x = w *  \
351                                         PluginClient::get_source_position() /  \
352                                         PluginClient::get_total_len(); \
353          \
354                                 for(int k = w - 1, l = w - x - 1; k >= x; k--, l--) \
355                                 { \
356                                         out_row[k * components + 0] = out_row[l * components + 0]; \
357                                         out_row[k * components + 1] = out_row[l * components + 1]; \
358                                         out_row[k * components + 2] = out_row[l * components + 2]; \
359                                         if(components == 4) out_row[k * components + 3] = out_row[l * components + 3]; \
360                                 } \
361                                 for(int k = 0; k < x; k++) \
362                                 { \
363                                         out_row[k * components + 0] = in_row[k * components + 0]; \
364                                         out_row[k * components + 1] = in_row[k * components + 1]; \
365                                         out_row[k * components + 2] = in_row[k * components + 2]; \
366                                         if(components == 4) out_row[k * components + 3] = in_row[k * components + 3]; \
367                                 } \
368                         } \
369                 } \
370         } \
377 int SlideMain::process_realtime(VFrame *incoming, VFrame *outgoing)
379         load_configuration();
381         int w = incoming->get_w();
382         int h = incoming->get_h();
385         switch(incoming->get_color_model())
386         {
387                 case BC_RGB888:
388                 case BC_YUV888:
389                         SLIDE(unsigned char, 3)
390                         break;
391                 case BC_RGBA8888:
392                 case BC_YUVA8888:
393                         SLIDE(unsigned char, 4)
394                         break;
395                 case BC_RGB161616:
396                 case BC_YUV161616:
397                         SLIDE(uint16_t, 3)
398                         break;
399                 case BC_RGBA16161616:
400                 case BC_YUVA16161616:
401                         SLIDE(uint16_t, 4)
402                         break;
403         }
404         return 0;