r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / plugins / bandwipe / bandwipe.C
blob15858b4de5864006b0625d6caeabca61aff1f0ab
1 #include "bandwipe.h"
2 #include "bcdisplayinfo.h"
3 #include "defaults.h"
4 #include "edl.inc"
5 #include "filexml.h"
6 #include "overlayframe.h"
7 #include "picon_png.h"
8 #include "vframe.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)
24 REGISTER_PLUGIN(BandWipeMain)
30 BandWipeCount::BandWipeCount(BandWipeMain *plugin, 
31         BandWipeWindow *window,
32         int x,
33         int y)
34  : BC_TumbleTextBox(window, 
35                 (int64_t)plugin->bands,
36                 (int64_t)0,
37                 (int64_t)1000,
38                 x, 
39                 y, 
40                 50)
42         this->plugin = plugin;
43         this->window = window;
46 int BandWipeCount::handle_event()
48         plugin->bands = atol(get_text());
49         plugin->send_configure_change();
50         return 0;
54 BandWipeIn::BandWipeIn(BandWipeMain *plugin, 
55         BandWipeWindow *window,
56         int x,
57         int y)
58  : BC_Radial(x, 
59                 y, 
60                 plugin->direction == 0, 
61                 _("In"))
63         this->plugin = plugin;
64         this->window = window;
67 int BandWipeIn::handle_event()
69         update(1);
70         plugin->direction = 0;
71         window->out->update(0);
72         plugin->send_configure_change();
73         return 0;
76 BandWipeOut::BandWipeOut(BandWipeMain *plugin, 
77         BandWipeWindow *window,
78         int x,
79         int y)
80  : BC_Radial(x, 
81                 y, 
82                 plugin->direction == 1, 
83                 _("Out"))
85         this->plugin = plugin;
86         this->window = window;
89 int BandWipeOut::handle_event()
91         update(1);
92         plugin->direction = 1;
93         window->in->update(0);
94         plugin->send_configure_change();
95         return 0;
104 BandWipeWindow::BandWipeWindow(BandWipeMain *plugin, int x, int y)
105  : BC_Window(plugin->gui_string, 
106         x, 
107         y, 
108         320, 
109         50, 
110         320, 
111         50, 
112         0, 
113         0,
114         1)
116         this->plugin = plugin;
120 int BandWipeWindow::close_event()
122         set_done(1);
123         return 1;
126 void BandWipeWindow::create_objects()
128         int x = 10, y = 10;
129         add_subwindow(new BC_Title(x, y, _("Bands:")));
130         x += 50;
131         count = new BandWipeCount(plugin, 
132                 this,
133                 x,
134                 y);
135         count->create_objects();
136 //      y += 30;
137 //      add_subwindow(new BC_Title(x, y, _("Direction:")));
138 //      x += 100;
139 //      add_subwindow(in = new BandWipeIn(plugin, 
140 //              this,
141 //              x,
142 //              y));
143 //      x += 100;
144 //      x = 10;
145 //      add_subwindow(out = new BandWipeOut(plugin, 
146 //              this,
147 //              x,
148 //              y));
149         
150         show_window();
151         flush();
157 PLUGIN_THREAD_OBJECT(BandWipeMain, BandWipeThread, BandWipeWindow)
164 BandWipeMain::BandWipeMain(PluginServer *server)
165  : PluginVClient(server)
167         bands = 9;
168         direction = 0;
169         PLUGIN_CONSTRUCTOR_MACRO
172 BandWipeMain::~BandWipeMain()
174         PLUGIN_DESTRUCTOR_MACRO
177 char* BandWipeMain::plugin_title() { return _("BandWipe"); }
178 int BandWipeMain::is_video() { return 1; }
179 int BandWipeMain::is_transition() { return 1; }
180 int BandWipeMain::uses_gui() { return 1; }
181 SHOW_GUI_MACRO(BandWipeMain, BandWipeThread);
182 SET_STRING_MACRO(BandWipeMain)
183 RAISE_WINDOW_MACRO(BandWipeMain)
186 VFrame* BandWipeMain::new_picon()
188         return new VFrame(picon_png);
191 int BandWipeMain::load_defaults()
193         char directory[BCTEXTLEN];
194 // set the default directory
195         sprintf(directory, "%sbandwipe.rc", BCASTDIR);
197 // load the defaults
198         defaults = new Defaults(directory);
199         defaults->load();
201         bands = defaults->get("BANDS", bands);
202         direction = defaults->get("DIRECTION", direction);
203         return 0;
206 int BandWipeMain::save_defaults()
208         defaults->update("BANDS", bands);
209         defaults->update("DIRECTION", direction);
210         defaults->save();
211         return 0;
214 void BandWipeMain::save_data(KeyFrame *keyframe)
216         FileXML output;
217         output.set_shared_string(keyframe->data, MESSAGESIZE);
218         output.tag.set_title("BANDWIPE");
219         output.tag.set_property("BANDS", bands);
220         output.tag.set_property("DIRECTION", direction);
221         output.append_tag();
222         output.terminate_string();
225 void BandWipeMain::read_data(KeyFrame *keyframe)
227         FileXML input;
229         input.set_shared_string(keyframe->data, strlen(keyframe->data));
231         while(!input.read_tag())
232         {
233                 if(input.tag.title_is("BANDWIPE"))
234                 {
235                         bands = input.tag.get_property("BANDS", bands);
236                         direction = input.tag.get_property("DIRECTION", direction);
237                 }
238         }
241 void BandWipeMain::load_configuration()
243         read_data(get_prev_keyframe(get_source_position()));
248 #define BANDWIPE(type, components) \
249 { \
250         if(direction == 0) \
251         { \
252                 int x = w * \
253                         PluginClient::get_source_position() / \
254                         PluginClient::get_total_len(); \
256                 for(int i = 0; i < bands; i++) \
257                 { \
258                         for(int j = 0; j < band_h; j++) \
259                         { \
260                                 int row = i * band_h + j; \
261                                  \
262                                 if(row >= 0 && row < h) \
263                                 { \
264                                         type *in_row = (type*)incoming->get_rows()[row]; \
265                                         type *out_row = (type*)outgoing->get_rows()[row]; \
267                                         if(i % 2) \
268                                         { \
269                                                 for(int k = 0; k < x; k++) \
270                                                 { \
271                                                         out_row[k * components + 0] = in_row[k * components + 0]; \
272                                                         out_row[k * components + 1] = in_row[k * components + 1]; \
273                                                         out_row[k * components + 2] = in_row[k * components + 2]; \
274                                                         if(components == 4) out_row[k * components + 3] = in_row[k * components + 3]; \
275                                                 } \
276                                         } \
277                                         else \
278                                         { \
279                                                 for(int k = w - x; k < w; k++) \
280                                                 { \
281                                                         out_row[k * components + 0] = in_row[k * components + 0]; \
282                                                         out_row[k * components + 1] = in_row[k * components + 1]; \
283                                                         out_row[k * components + 2] = in_row[k * components + 2]; \
284                                                         if(components == 4) out_row[k * components + 3] = in_row[k * components + 3]; \
285                                                 } \
286                                         } \
287                                 } \
288                         } \
289                 } \
290         } \
291         else \
292         { \
293                 int x = w - w * \
294                         PluginClient::get_source_position() / \
295                         PluginClient::get_total_len(); \
297                 for(int i = 0; i < bands; i++) \
298                 { \
299                         for(int j = 0; j < band_h; j++) \
300                         { \
301                                 int row = i * band_h + j; \
302                                  \
303                                 if(row >= 0 && row < h) \
304                                 { \
305                                         type *in_row = (type*)incoming->get_rows()[row]; \
306                                         type *out_row = (type*)outgoing->get_rows()[row]; \
308                                         if(i % 2) \
309                                         { \
310                                                 for(int k = x; k < w; k++) \
311                                                 { \
312                                                         out_row[k * components + 0] = in_row[k * components + 0]; \
313                                                         out_row[k * components + 1] = in_row[k * components + 1]; \
314                                                         out_row[k * components + 2] = in_row[k * components + 2]; \
315                                                         if(components == 4) out_row[k * components + 3] = in_row[k * components + 3]; \
316                                                 } \
317                                         } \
318                                         else \
319                                         { \
320                                                 for(int k = 0; k < w - x; k++) \
321                                                 { \
322                                                         out_row[k * components + 0] = in_row[k * components + 0]; \
323                                                         out_row[k * components + 1] = in_row[k * components + 1]; \
324                                                         out_row[k * components + 2] = in_row[k * components + 2]; \
325                                                         if(components == 4) out_row[k * components + 3] = in_row[k * components + 3]; \
326                                                 } \
327                                         } \
328                                 } \
329                         } \
330                 } \
331         } \
336 int BandWipeMain::process_realtime(VFrame *incoming, VFrame *outgoing)
338         load_configuration();
340         int w = incoming->get_w();
341         int h = incoming->get_h();
342         int band_h = ((bands == 0) ? h : (h / bands + 1));
344         switch(incoming->get_color_model())
345         {
346                 case BC_RGB888:
347                 case BC_YUV888:
348                         BANDWIPE(unsigned char, 3)
349                         break;
350                 case BC_RGBA8888:
351                 case BC_YUVA8888:
352                         BANDWIPE(unsigned char, 4)
353                         break;
354                 case BC_RGB161616:
355                 case BC_YUV161616:
356                         BANDWIPE(uint16_t, 3)
357                         break;
358                 case BC_RGBA16161616:
359                 case BC_YUVA16161616:
360                         BANDWIPE(uint16_t, 4)
361                         break;
362         }
364         return 0;