Fixed initialisation of tf in file_open(). Without setting the memory to 0,
[cinelerra_cv/mob.git] / plugins / slide / slide.C
blobff34aeeacf0507d95d15173fd0f12f04ddc77f23
1 #include "bcdisplayinfo.h"
2 #include "bchash.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 N_("Slide"); }
199 int SlideMain::is_video() { return 1; }
200 int SlideMain::is_transition() { return 1; }
201 int SlideMain::uses_gui() { return 1; }
203 SHOW_GUI_MACRO(SlideMain, SlideThread);
204 SET_STRING_MACRO(SlideMain)
205 RAISE_WINDOW_MACRO(SlideMain)
208 VFrame* SlideMain::new_picon()
210         return new VFrame(picon_png);
213 int SlideMain::load_defaults()
215         char directory[BCTEXTLEN];
216 // set the default directory
217         sprintf(directory, "%sslide.rc", BCASTDIR);
219 // load the defaults
220         defaults = new BC_Hash(directory);
221         defaults->load();
223         motion_direction = defaults->get("MOTION_DIRECTION", motion_direction);
224         direction = defaults->get("DIRECTION", direction);
225         return 0;
228 int SlideMain::save_defaults()
230         defaults->update("MOTION_DIRECTION", motion_direction);
231         defaults->update("DIRECTION", direction);
232         defaults->save();
233         return 0;
236 void SlideMain::save_data(KeyFrame *keyframe)
238         FileXML output;
239         output.set_shared_string(keyframe->data, MESSAGESIZE);
240         output.tag.set_title("SLIDE");
241         output.tag.set_property("MOTION_DIRECTION", motion_direction);
242         output.tag.set_property("DIRECTION", direction);
243         output.append_tag();
244         output.terminate_string();
247 void SlideMain::read_data(KeyFrame *keyframe)
249         FileXML input;
251         input.set_shared_string(keyframe->data, strlen(keyframe->data));
253         while(!input.read_tag())
254         {
255                 if(input.tag.title_is("SLIDE"))
256                 {
257                         motion_direction = input.tag.get_property("MOTION_DIRECTION", motion_direction);
258                         direction = input.tag.get_property("DIRECTION", direction);
259                 }
260         }
263 void SlideMain::load_configuration()
265         read_data(get_prev_keyframe(get_source_position()));
271 #define SLIDE(type, components) \
272 { \
273         if(direction == 0) \
274         { \
275                 int in_add, out_add, cpy_len; \
276                 if(motion_direction == 0) \
277                 { \
278                         int x = w *  \
279                                 PluginClient::get_source_position() /  \
280                                 PluginClient::get_total_len(); \
281                         out_add = 0; \
282                         in_add = (w - x) * components * sizeof(type); \
283                         cpy_len = x * components * sizeof(type); \
284                 } \
285                 else \
286                 { \
287                         int x = w - w *  \
288                                 PluginClient::get_source_position() /  \
289                                 PluginClient::get_total_len(); \
290                         out_add = x * components * sizeof(type); \
291                         in_add = 0; \
292                         cpy_len = (w - x) * components * sizeof(type); \
293                 } \
295                 for(int j = 0; j < h; j++) \
296                 { \
297                         memcpy( ((char *)outgoing->get_rows()[j]) + out_add, \
298                                 ((char *)incoming->get_rows()[j]) + in_add, \
299                                 cpy_len); \
300                 } \
301         } \
302         else \
303         { \
304                 if(motion_direction == 0) \
305                 { \
306                         int x = w - w *  \
307                                 PluginClient::get_source_position() /  \
308                                 PluginClient::get_total_len(); \
309                         for(int j = 0; j < h; j++) \
310                         { \
311                                 char *in_row = (char*)incoming->get_rows()[j]; \
312                                 char *out_row = (char*)outgoing->get_rows()[j]; \
313                                 memmove(out_row + 0, out_row + ((w - x) * components * sizeof(type)), x * components * sizeof(type)); \
314                                 memcpy (out_row + x * components * sizeof(type), in_row + x * components * sizeof (type), (w - x) * components * sizeof(type)); \
315                         } \
316                 } \
317                 else \
318                 { \
319                         int x = w *  \
320                                 PluginClient::get_source_position() /  \
321                                 PluginClient::get_total_len(); \
322                         for(int j = 0; j < h; j++) \
323                         { \
324                                 char *in_row = (char*)incoming->get_rows()[j]; \
325                                 char *out_row = (char*)outgoing->get_rows()[j]; \
326          \
327                                 memmove(out_row + (x * components *sizeof(type)), out_row + 0, (w - x) * components * sizeof(type)); \
328                                 memcpy (out_row + 0, in_row + 0, (x) * components * sizeof(type)); \
329                         } \
330                 } \
331         } \
338 int SlideMain::process_realtime(VFrame *incoming, VFrame *outgoing)
340         load_configuration();
342         int w = incoming->get_w();
343         int h = incoming->get_h();
345 //      struct timeval start_time;
346 //      gettimeofday(&start_time, 0);
348         switch(incoming->get_color_model())
349         {
350                 case BC_RGB_FLOAT:
351                         SLIDE(float, 3)
352                         break;
353                 case BC_RGBA_FLOAT:
354                         SLIDE(float, 4)
355                         break;
356                 case BC_RGB888:
357                 case BC_YUV888:
358                         SLIDE(unsigned char, 3)
359                         break;
360                 case BC_RGBA8888:
361                 case BC_YUVA8888:
362                         SLIDE(unsigned char, 4)
363                         break;
364                 case BC_RGB161616:
365                 case BC_YUV161616:
366                         SLIDE(uint16_t, 3)
367                         break;
368                 case BC_RGBA16161616:
369                 case BC_YUVA16161616:
370                         SLIDE(uint16_t, 4)
371                         break;
372         }
373         
374 //      int64_t dif= get_difference(&start_time);
375 //      printf("diff: %lli\n", dif);
377         return 0;