r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / plugins / wipe / wipe.C
blobe105dd71f2018da3c7949d40915c6d8a2d12fa1b
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 "wipe.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(WipeMain)
25 WipeLeft::WipeLeft(WipeMain *plugin, 
26         WipeWindow *window,
27         int x,
28         int y)
29  : BC_Radial(x, 
30                 y, 
31                 plugin->direction == 0, 
32                 _("Left"))
34         this->plugin = plugin;
35         this->window = window;
38 int WipeLeft::handle_event()
40         update(1);
41         plugin->direction = 0;
42         window->right->update(0);
43         plugin->send_configure_change();
44         return 0;
47 WipeRight::WipeRight(WipeMain *plugin, 
48         WipeWindow *window,
49         int x,
50         int y)
51  : BC_Radial(x, 
52                 y, 
53                 plugin->direction == 1, 
54                 _("Right"))
56         this->plugin = plugin;
57         this->window = window;
60 int WipeRight::handle_event()
62         update(1);
63         plugin->direction = 1;
64         window->left->update(0);
65         plugin->send_configure_change();
66         return 0;
76 WipeWindow::WipeWindow(WipeMain *plugin, int x, int y)
77  : BC_Window(plugin->gui_string, 
78         x, 
79         y, 
80         320, 
81         50, 
82         320, 
83         50, 
84         0, 
85         0,
86         1)
88         this->plugin = plugin;
92 int WipeWindow::close_event()
94         set_done(1);
95         return 1;
98 void WipeWindow::create_objects()
100         int x = 10, y = 10;
101         add_subwindow(new BC_Title(x, y, _("Direction:")));
102         x += 100;
103         add_subwindow(left = new WipeLeft(plugin, 
104                 this,
105                 x,
106                 y));
107         x += 100;
108         add_subwindow(right = new WipeRight(plugin, 
109                 this,
110                 x,
111                 y));
112         show_window();
113         flush();
119 PLUGIN_THREAD_OBJECT(WipeMain, WipeThread, WipeWindow)
126 WipeMain::WipeMain(PluginServer *server)
127  : PluginVClient(server)
129         direction = 0;
130         PLUGIN_CONSTRUCTOR_MACRO
133 WipeMain::~WipeMain()
135         PLUGIN_DESTRUCTOR_MACRO
138 char* WipeMain::plugin_title() { return _("Wipe"); }
139 int WipeMain::is_video() { return 1; }
140 int WipeMain::is_transition() { return 1; }
141 int WipeMain::uses_gui() { return 1; }
142 SHOW_GUI_MACRO(WipeMain, WipeThread);
143 SET_STRING_MACRO(WipeMain)
144 RAISE_WINDOW_MACRO(WipeMain)
147 VFrame* WipeMain::new_picon()
149         return new VFrame(picon_png);
152 int WipeMain::load_defaults()
154         char directory[BCTEXTLEN];
155 // set the default directory
156         sprintf(directory, "%swipe.rc", BCASTDIR);
158 // load the defaults
159         defaults = new Defaults(directory);
160         defaults->load();
162         direction = defaults->get("DIRECTION", direction);
163         return 0;
166 int WipeMain::save_defaults()
168         defaults->update("DIRECTION", direction);
169         defaults->save();
170         return 0;
173 void WipeMain::save_data(KeyFrame *keyframe)
175         FileXML output;
176         output.set_shared_string(keyframe->data, MESSAGESIZE);
177         output.tag.set_title("WIPE");
178         output.tag.set_property("DIRECTION", direction);
179         output.append_tag();
180         output.terminate_string();
183 void WipeMain::read_data(KeyFrame *keyframe)
185         FileXML input;
187         input.set_shared_string(keyframe->data, strlen(keyframe->data));
189         while(!input.read_tag())
190         {
191                 if(input.tag.title_is("WIPE"))
192                 {
193                         direction = input.tag.get_property("DIRECTION", direction);
194                 }
195         }
198 void WipeMain::load_configuration()
200         read_data(get_prev_keyframe(get_source_position()));
208 #define WIPE(type, components) \
209 { \
210         if(direction == 0) \
211         { \
212                 for(int j = 0; j < h; j++) \
213                 { \
214                         type *in_row = (type*)incoming->get_rows()[j]; \
215                         type *out_row = (type*)outgoing->get_rows()[j]; \
216                         int x = incoming->get_w() *  \
217                                 PluginClient::get_source_position() /  \
218                                 PluginClient::get_total_len(); \
220                         for(int k = 0; k < x; k++) \
221                         { \
222                                 out_row[k * components + 0] = in_row[k * components + 0]; \
223                                 out_row[k * components + 1] = in_row[k * components + 1]; \
224                                 out_row[k * components + 2] = in_row[k * components + 2]; \
225                                 if(components == 4) out_row[k * components + 3] = in_row[k * components + 3]; \
226                         } \
227                 } \
228         } \
229         else \
230         { \
231                 for(int j = 0; j < h; j++) \
232                 { \
233                         type *in_row = (type*)incoming->get_rows()[j]; \
234                         type *out_row = (type*)outgoing->get_rows()[j]; \
235                         int x = incoming->get_w() - incoming->get_w() *  \
236                                 PluginClient::get_source_position() /  \
237                                 PluginClient::get_total_len(); \
239                         for(int k = x; k < w; k++) \
240                         { \
241                                 out_row[k * components + 0] = in_row[k * components + 0]; \
242                                 out_row[k * components + 1] = in_row[k * components + 1]; \
243                                 out_row[k * components + 2] = in_row[k * components + 2]; \
244                                 if(components == 4) out_row[k * components + 3] = in_row[k * components + 3]; \
245                         } \
246                 } \
247         } \
254 int WipeMain::process_realtime(VFrame *incoming, VFrame *outgoing)
256         load_configuration();
258         int w = incoming->get_w();
259         int h = incoming->get_h();
262         switch(incoming->get_color_model())
263         {
264                 case BC_RGB888:
265                 case BC_YUV888:
266                         WIPE(unsigned char, 3)
267                         break;
268                 case BC_RGBA8888:
269                 case BC_YUVA8888:
270                         WIPE(unsigned char, 4)
271                         break;
272                 case BC_RGB161616:
273                 case BC_YUV161616:
274                         WIPE(uint16_t, 3)
275                         break;
276                 case BC_RGBA16161616:
277                 case BC_YUVA16161616:
278                         WIPE(uint16_t, 4)
279                         break;
280         }
281         return 0;