font debug env var, drag fixes, cposer hide scrollbar, plugin tool tip
[goodguy/history.git] / cinelerra-5.1 / 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 _("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.tag.set_title("/SLIDE");
227         output.append_tag();
228         output.append_newline();
229         output.terminate_string();
230 }
231
232 void SlideMain::read_data(KeyFrame *keyframe)
233 {
234         FileXML input;
235
236         input.set_shared_input(keyframe->get_data(), strlen(keyframe->get_data()));
237
238         while(!input.read_tag())
239         {
240                 if(input.tag.title_is("SLIDE"))
241                 {
242                         motion_direction = input.tag.get_property("MOTION_DIRECTION", motion_direction);
243                         direction = input.tag.get_property("DIRECTION", direction);
244                 }
245         }
246 }
247
248 int SlideMain::load_configuration()
249 {
250         read_data(get_prev_keyframe(get_source_position()));
251         return 1;
252 }
253
254
255
256
257 #define SLIDE(type, components) \
258 { \
259         if(direction == 0) \
260         { \
261                 int in_add, out_add, cpy_len; \
262                 if(motion_direction == 0) \
263                 { \
264                         int x = w *  \
265                                 PluginClient::get_source_position() /  \
266                                 PluginClient::get_total_len(); \
267                         out_add = 0; \
268                         in_add = (w - x) * components * sizeof(type); \
269                         cpy_len = x * components * sizeof(type); \
270                 } \
271                 else \
272                 { \
273                         int x = w - w *  \
274                                 PluginClient::get_source_position() /  \
275                                 PluginClient::get_total_len(); \
276                         out_add = x * components * sizeof(type); \
277                         in_add = 0; \
278                         cpy_len = (w - x) * components * sizeof(type); \
279                 } \
280  \
281                 for(int j = 0; j < h; j++) \
282                 { \
283                         memcpy( ((char *)outgoing->get_rows()[j]) + out_add, \
284                                 ((char *)incoming->get_rows()[j]) + in_add, \
285                                 cpy_len); \
286                 } \
287         } \
288         else \
289         { \
290                 if(motion_direction == 0) \
291                 { \
292                         int x = w - w *  \
293                                 PluginClient::get_source_position() /  \
294                                 PluginClient::get_total_len(); \
295                         for(int j = 0; j < h; j++) \
296                         { \
297                                 char *in_row = (char*)incoming->get_rows()[j]; \
298                                 char *out_row = (char*)outgoing->get_rows()[j]; \
299                                 memmove(out_row + 0, out_row + ((w - x) * components * sizeof(type)), x * components * sizeof(type)); \
300                                 memcpy (out_row + x * components * sizeof(type), in_row + x * components * sizeof (type), (w - x) * components * sizeof(type)); \
301                         } \
302                 } \
303                 else \
304                 { \
305                         int x = w *  \
306                                 PluginClient::get_source_position() /  \
307                                 PluginClient::get_total_len(); \
308                         for(int j = 0; j < h; j++) \
309                         { \
310                                 char *in_row = (char*)incoming->get_rows()[j]; \
311                                 char *out_row = (char*)outgoing->get_rows()[j]; \
312          \
313                                 memmove(out_row + (x * components *sizeof(type)), out_row + 0, (w - x) * components * sizeof(type)); \
314                                 memcpy (out_row + 0, in_row + 0, (x) * components * sizeof(type)); \
315                         } \
316                 } \
317         } \
318 }
319
320
321
322
323
324 int SlideMain::process_realtime(VFrame *incoming, VFrame *outgoing)
325 {
326         load_configuration();
327
328         int w = incoming->get_w();
329         int h = incoming->get_h();
330
331 //      struct timeval start_time;
332 //      gettimeofday(&start_time, 0);
333
334         switch(incoming->get_color_model())
335         {
336                 case BC_RGB_FLOAT:
337                         SLIDE(float, 3)
338                         break;
339                 case BC_RGBA_FLOAT:
340                         SLIDE(float, 4)
341                         break;
342                 case BC_RGB888:
343                 case BC_YUV888:
344                         SLIDE(unsigned char, 3)
345                         break;
346                 case BC_RGBA8888:
347                 case BC_YUVA8888:
348                         SLIDE(unsigned char, 4)
349                         break;
350                 case BC_RGB161616:
351                 case BC_YUV161616:
352                         SLIDE(uint16_t, 3)
353                         break;
354                 case BC_RGBA16161616:
355                 case BC_YUVA16161616:
356                         SLIDE(uint16_t, 4)
357                         break;
358         }
359
360 //      int64_t dif= get_difference(&start_time);
361 //      printf("diff: %lli\n", dif);
362
363         return 0;
364 }