initial commit
[goodguy/history.git] / cinelerra-5.0 / plugins / slide / slide.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  * 
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * 
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  * 
20  */
21
22 #include "bcdisplayinfo.h"
23 #include "bchash.h"
24 #include "edl.inc"
25 #include "filexml.h"
26 #include "language.h"
27 #include "overlayframe.h"
28 #include "vframe.h"
29 #include "slide.h"
30
31
32 #include <stdint.h>
33 #include <string.h>
34
35
36
37 REGISTER_PLUGIN(SlideMain)
38
39
40
41
42
43 SlideLeft::SlideLeft(SlideMain *plugin, 
44         SlideWindow *window,
45         int x,
46         int y)
47  : BC_Radial(x, 
48                 y, 
49                 plugin->motion_direction == 0, 
50                 _("Left"))
51 {
52         this->plugin = plugin;
53         this->window = window;
54 }
55
56 int SlideLeft::handle_event()
57 {
58         update(1);
59         plugin->motion_direction = 0;
60         window->right->update(0);
61         plugin->send_configure_change();
62         return 0;
63 }
64
65 SlideRight::SlideRight(SlideMain *plugin, 
66         SlideWindow *window,
67         int x,
68         int y)
69  : BC_Radial(x, 
70                 y, 
71                 plugin->motion_direction == 1, 
72                 _("Right"))
73 {
74         this->plugin = plugin;
75         this->window = window;
76 }
77
78 int SlideRight::handle_event()
79 {
80         update(1);
81         plugin->motion_direction = 1;
82         window->left->update(0);
83         plugin->send_configure_change();
84         return 0;
85 }
86
87 SlideIn::SlideIn(SlideMain *plugin, 
88         SlideWindow *window,
89         int x,
90         int y)
91  : BC_Radial(x, 
92                 y, 
93                 plugin->direction == 0, 
94                 _("In"))
95 {
96         this->plugin = plugin;
97         this->window = window;
98 }
99
100 int SlideIn::handle_event()
101 {
102         update(1);
103         plugin->direction = 0;
104         window->out->update(0);
105         plugin->send_configure_change();
106         return 0;
107 }
108
109 SlideOut::SlideOut(SlideMain *plugin, 
110         SlideWindow *window,
111         int x,
112         int y)
113  : BC_Radial(x, 
114                 y, 
115                 plugin->direction == 1, 
116                 _("Out"))
117 {
118         this->plugin = plugin;
119         this->window = window;
120 }
121
122 int SlideOut::handle_event()
123 {
124         update(1);
125         plugin->direction = 1;
126         window->in->update(0);
127         plugin->send_configure_change();
128         return 0;
129 }
130
131
132
133
134
135
136
137
138 SlideWindow::SlideWindow(SlideMain *plugin)
139  : PluginClientWindow(plugin, 
140         320, 
141         100, 
142         320, 
143         100, 
144         0)
145 {
146         this->plugin = plugin;
147 }
148
149
150
151
152
153
154 void SlideWindow::create_objects()
155 {
156         int x = 10, y = 10;
157         add_subwindow(new BC_Title(x, y, _("Direction:")));
158         x += 100;
159         add_subwindow(left = new SlideLeft(plugin, 
160                 this,
161                 x,
162                 y));
163         x += 100;
164         add_subwindow(right = new SlideRight(plugin, 
165                 this,
166                 x,
167                 y));
168
169         y += 30;
170         x = 10;
171         add_subwindow(new BC_Title(x, y, _("Direction:")));
172         x += 100;
173         add_subwindow(in = new SlideIn(plugin, 
174                 this,
175                 x,
176                 y));
177         x += 100;
178         add_subwindow(out = new SlideOut(plugin, 
179                 this,
180                 x,
181                 y));
182
183         show_window();
184         flush();
185 }
186
187
188
189
190
191
192
193
194
195
196
197 SlideMain::SlideMain(PluginServer *server)
198  : PluginVClient(server)
199 {
200         motion_direction = 0;
201         direction = 0;
202         
203 }
204
205 SlideMain::~SlideMain()
206 {
207         
208 }
209
210 const char* SlideMain::plugin_title() { return N_("Slide"); }
211 int SlideMain::is_video() { return 1; }
212 int SlideMain::is_transition() { return 1; }
213 int SlideMain::uses_gui() { return 1; }
214
215 NEW_WINDOW_MACRO(SlideMain, SlideWindow)
216
217
218 void SlideMain::save_data(KeyFrame *keyframe)
219 {
220         FileXML output;
221         output.set_shared_output(keyframe->get_data(), MESSAGESIZE);
222         output.tag.set_title("SLIDE");
223         output.tag.set_property("MOTION_DIRECTION", motion_direction);
224         output.tag.set_property("DIRECTION", direction);
225         output.append_tag();
226         output.terminate_string();
227 }
228
229 void SlideMain::read_data(KeyFrame *keyframe)
230 {
231         FileXML input;
232
233         input.set_shared_input(keyframe->get_data(), strlen(keyframe->get_data()));
234
235         while(!input.read_tag())
236         {
237                 if(input.tag.title_is("SLIDE"))
238                 {
239                         motion_direction = input.tag.get_property("MOTION_DIRECTION", motion_direction);
240                         direction = input.tag.get_property("DIRECTION", direction);
241                 }
242         }
243 }
244
245 int SlideMain::load_configuration()
246 {
247         read_data(get_prev_keyframe(get_source_position()));
248         return 1;
249 }
250
251
252
253
254 #define SLIDE(type, components) \
255 { \
256         if(direction == 0) \
257         { \
258                 int in_add, out_add, cpy_len; \
259                 if(motion_direction == 0) \
260                 { \
261                         int x = w *  \
262                                 PluginClient::get_source_position() /  \
263                                 PluginClient::get_total_len(); \
264                         out_add = 0; \
265                         in_add = (w - x) * components * sizeof(type); \
266                         cpy_len = x * components * sizeof(type); \
267                 } \
268                 else \
269                 { \
270                         int x = w - w *  \
271                                 PluginClient::get_source_position() /  \
272                                 PluginClient::get_total_len(); \
273                         out_add = x * components * sizeof(type); \
274                         in_add = 0; \
275                         cpy_len = (w - x) * components * sizeof(type); \
276                 } \
277  \
278                 for(int j = 0; j < h; j++) \
279                 { \
280                         memcpy( ((char *)outgoing->get_rows()[j]) + out_add, \
281                                 ((char *)incoming->get_rows()[j]) + in_add, \
282                                 cpy_len); \
283                 } \
284         } \
285         else \
286         { \
287                 if(motion_direction == 0) \
288                 { \
289                         int x = w - w *  \
290                                 PluginClient::get_source_position() /  \
291                                 PluginClient::get_total_len(); \
292                         for(int j = 0; j < h; j++) \
293                         { \
294                                 char *in_row = (char*)incoming->get_rows()[j]; \
295                                 char *out_row = (char*)outgoing->get_rows()[j]; \
296                                 memmove(out_row + 0, out_row + ((w - x) * components * sizeof(type)), x * components * sizeof(type)); \
297                                 memcpy (out_row + x * components * sizeof(type), in_row + x * components * sizeof (type), (w - x) * components * sizeof(type)); \
298                         } \
299                 } \
300                 else \
301                 { \
302                         int x = w *  \
303                                 PluginClient::get_source_position() /  \
304                                 PluginClient::get_total_len(); \
305                         for(int j = 0; j < h; j++) \
306                         { \
307                                 char *in_row = (char*)incoming->get_rows()[j]; \
308                                 char *out_row = (char*)outgoing->get_rows()[j]; \
309          \
310                                 memmove(out_row + (x * components *sizeof(type)), out_row + 0, (w - x) * components * sizeof(type)); \
311                                 memcpy (out_row + 0, in_row + 0, (x) * components * sizeof(type)); \
312                         } \
313                 } \
314         } \
315 }
316
317
318
319
320
321 int SlideMain::process_realtime(VFrame *incoming, VFrame *outgoing)
322 {
323         load_configuration();
324
325         int w = incoming->get_w();
326         int h = incoming->get_h();
327
328 //      struct timeval start_time;
329 //      gettimeofday(&start_time, 0);
330
331         switch(incoming->get_color_model())
332         {
333                 case BC_RGB_FLOAT:
334                         SLIDE(float, 3)
335                         break;
336                 case BC_RGBA_FLOAT:
337                         SLIDE(float, 4)
338                         break;
339                 case BC_RGB888:
340                 case BC_YUV888:
341                         SLIDE(unsigned char, 3)
342                         break;
343                 case BC_RGBA8888:
344                 case BC_YUVA8888:
345                         SLIDE(unsigned char, 4)
346                         break;
347                 case BC_RGB161616:
348                 case BC_YUV161616:
349                         SLIDE(uint16_t, 3)
350                         break;
351                 case BC_RGBA16161616:
352                 case BC_YUVA16161616:
353                         SLIDE(uint16_t, 4)
354                         break;
355         }
356         
357 //      int64_t dif= get_difference(&start_time);
358 //      printf("diff: %lli\n", dif);
359
360         return 0;
361 }