r370: Heroine Virutal's official release 1.2.1
[cinelerra_cv/mob.git] / hvirtual / plugins / wipe / wipe.C
blob2ff054c08d9f0d4cf9f1c78d8d91ac6d9e19bb6b
1 #include "bcdisplayinfo.h"
2 #include "defaults.h"
3 #include "edl.inc"
4 #include "filexml.h"
5 #include "language.h"
6 #include "overlayframe.h"
7 #include "picon_png.h"
8 #include "vframe.h"
9 #include "wipe.h"
12 #include <stdint.h>
13 #include <string.h>
16 REGISTER_PLUGIN(WipeMain)
22 WipeLeft::WipeLeft(WipeMain *plugin, 
23         WipeWindow *window,
24         int x,
25         int y)
26  : BC_Radial(x, 
27                 y, 
28                 plugin->direction == 0, 
29                 _("Left"))
31         this->plugin = plugin;
32         this->window = window;
35 int WipeLeft::handle_event()
37         update(1);
38         plugin->direction = 0;
39         window->right->update(0);
40         plugin->send_configure_change();
41         return 0;
44 WipeRight::WipeRight(WipeMain *plugin, 
45         WipeWindow *window,
46         int x,
47         int y)
48  : BC_Radial(x, 
49                 y, 
50                 plugin->direction == 1, 
51                 _("Right"))
53         this->plugin = plugin;
54         this->window = window;
57 int WipeRight::handle_event()
59         update(1);
60         plugin->direction = 1;
61         window->left->update(0);
62         plugin->send_configure_change();
63         return 0;
73 WipeWindow::WipeWindow(WipeMain *plugin, int x, int y)
74  : BC_Window(plugin->gui_string, 
75         x, 
76         y, 
77         320, 
78         50, 
79         320, 
80         50, 
81         0, 
82         0,
83         1)
85         this->plugin = plugin;
89 int WipeWindow::close_event()
91         set_done(1);
92         return 1;
95 void WipeWindow::create_objects()
97         int x = 10, y = 10;
98         add_subwindow(new BC_Title(x, y, _("Direction:")));
99         x += 100;
100         add_subwindow(left = new WipeLeft(plugin, 
101                 this,
102                 x,
103                 y));
104         x += 100;
105         add_subwindow(right = new WipeRight(plugin, 
106                 this,
107                 x,
108                 y));
109         show_window();
110         flush();
116 PLUGIN_THREAD_OBJECT(WipeMain, WipeThread, WipeWindow)
123 WipeMain::WipeMain(PluginServer *server)
124  : PluginVClient(server)
126         direction = 0;
127         PLUGIN_CONSTRUCTOR_MACRO
130 WipeMain::~WipeMain()
132         PLUGIN_DESTRUCTOR_MACRO
135 char* WipeMain::plugin_title() { return N_("Wipe"); }
136 int WipeMain::is_video() { return 1; }
137 int WipeMain::is_transition() { return 1; }
138 int WipeMain::uses_gui() { return 1; }
140 SHOW_GUI_MACRO(WipeMain, WipeThread);
141 SET_STRING_MACRO(WipeMain)
142 RAISE_WINDOW_MACRO(WipeMain)
145 VFrame* WipeMain::new_picon()
147         return new VFrame(picon_png);
150 int WipeMain::load_defaults()
152         char directory[BCTEXTLEN];
153 // set the default directory
154         sprintf(directory, "%swipe.rc", BCASTDIR);
156 // load the defaults
157         defaults = new Defaults(directory);
158         defaults->load();
160         direction = defaults->get("DIRECTION", direction);
161         return 0;
164 int WipeMain::save_defaults()
166         defaults->update("DIRECTION", direction);
167         defaults->save();
168         return 0;
171 void WipeMain::save_data(KeyFrame *keyframe)
173         FileXML output;
174         output.set_shared_string(keyframe->data, MESSAGESIZE);
175         output.tag.set_title("WIPE");
176         output.tag.set_property("DIRECTION", direction);
177         output.append_tag();
178         output.terminate_string();
181 void WipeMain::read_data(KeyFrame *keyframe)
183         FileXML input;
185         input.set_shared_string(keyframe->data, strlen(keyframe->data));
187         while(!input.read_tag())
188         {
189                 if(input.tag.title_is("WIPE"))
190                 {
191                         direction = input.tag.get_property("DIRECTION", direction);
192                 }
193         }
196 void WipeMain::load_configuration()
198         read_data(get_prev_keyframe(get_source_position()));
206 #define WIPE(type, components) \
207 { \
208         if(direction == 0) \
209         { \
210                 for(int j = 0; j < h; j++) \
211                 { \
212                         type *in_row = (type*)incoming->get_rows()[j]; \
213                         type *out_row = (type*)outgoing->get_rows()[j]; \
214                         int x = incoming->get_w() *  \
215                                 PluginClient::get_source_position() /  \
216                                 PluginClient::get_total_len(); \
218                         for(int k = 0; k < x; k++) \
219                         { \
220                                 out_row[k * components + 0] = in_row[k * components + 0]; \
221                                 out_row[k * components + 1] = in_row[k * components + 1]; \
222                                 out_row[k * components + 2] = in_row[k * components + 2]; \
223                                 if(components == 4) out_row[k * components + 3] = in_row[k * components + 3]; \
224                         } \
225                 } \
226         } \
227         else \
228         { \
229                 for(int j = 0; j < h; j++) \
230                 { \
231                         type *in_row = (type*)incoming->get_rows()[j]; \
232                         type *out_row = (type*)outgoing->get_rows()[j]; \
233                         int x = incoming->get_w() - incoming->get_w() *  \
234                                 PluginClient::get_source_position() /  \
235                                 PluginClient::get_total_len(); \
237                         for(int k = x; k < w; k++) \
238                         { \
239                                 out_row[k * components + 0] = in_row[k * components + 0]; \
240                                 out_row[k * components + 1] = in_row[k * components + 1]; \
241                                 out_row[k * components + 2] = in_row[k * components + 2]; \
242                                 if(components == 4) out_row[k * components + 3] = in_row[k * components + 3]; \
243                         } \
244                 } \
245         } \
252 int WipeMain::process_realtime(VFrame *incoming, VFrame *outgoing)
254         load_configuration();
256         int w = incoming->get_w();
257         int h = incoming->get_h();
260         switch(incoming->get_color_model())
261         {
262                 case BC_RGB_FLOAT:
263                         WIPE(float, 3)
264                         break;
265                 case BC_RGB888:
266                 case BC_YUV888:
267                         WIPE(unsigned char, 3)
268                         break;
269                 case BC_RGBA_FLOAT:
270                         WIPE(float, 4)
271                         break;
272                 case BC_RGBA8888:
273                 case BC_YUVA8888:
274                         WIPE(unsigned char, 4)
275                         break;
276                 case BC_RGB161616:
277                 case BC_YUV161616:
278                         WIPE(uint16_t, 3)
279                         break;
280                 case BC_RGBA16161616:
281                 case BC_YUVA16161616:
282                         WIPE(uint16_t, 4)
283                         break;
284         }
285         return 0;