r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / plugins / bandslide / bandslide.C
blob874d80c096f2636247c8f113fb18c7d3cf9fb220
1 #include "bandslide.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>
13 #include <libintl.h>
14 #define _(String) gettext(String)
15 #define gettext_noop(String) String
16 #define N_(String) gettext_noop (String)
23 REGISTER_PLUGIN(BandSlideMain)
29 BandSlideCount::BandSlideCount(BandSlideMain *plugin, 
30         BandSlideWindow *window,
31         int x,
32         int y)
33  : BC_TumbleTextBox(window, 
34                 (int64_t)plugin->bands,
35                 (int64_t)0,
36                 (int64_t)1000,
37                 x, 
38                 y, 
39                 50)
41         this->plugin = plugin;
42         this->window = window;
45 int BandSlideCount::handle_event()
47         plugin->bands = atol(get_text());
48         plugin->send_configure_change();
49         return 0;
52 BandSlideIn::BandSlideIn(BandSlideMain *plugin, 
53         BandSlideWindow *window,
54         int x,
55         int y)
56  : BC_Radial(x, 
57                 y, 
58                 plugin->direction == 0, 
59                 _("In"))
61         this->plugin = plugin;
62         this->window = window;
65 int BandSlideIn::handle_event()
67         update(1);
68         plugin->direction = 0;
69         window->out->update(0);
70         plugin->send_configure_change();
71         return 0;
74 BandSlideOut::BandSlideOut(BandSlideMain *plugin, 
75         BandSlideWindow *window,
76         int x,
77         int y)
78  : BC_Radial(x, 
79                 y, 
80                 plugin->direction == 1, 
81                 _("Out"))
83         this->plugin = plugin;
84         this->window = window;
87 int BandSlideOut::handle_event()
89         update(1);
90         plugin->direction = 1;
91         window->in->update(0);
92         plugin->send_configure_change();
93         return 0;
103 BandSlideWindow::BandSlideWindow(BandSlideMain *plugin, int x, int y)
104  : BC_Window(plugin->gui_string, 
105         x, 
106         y, 
107         320, 
108         100, 
109         320, 
110         100, 
111         0, 
112         0,
113         1)
115         this->plugin = plugin;
119 int BandSlideWindow::close_event()
121         set_done(1);
122         return 1;
125 void BandSlideWindow::create_objects()
127         int x = 10, y = 10;
128         add_subwindow(new BC_Title(x, y, _("Bands:")));
129         x += 50;
130         count = new BandSlideCount(plugin, 
131                 this,
132                 x,
133                 y);
134         count->create_objects();
136         y += 30;
137         x = 10;
138         add_subwindow(new BC_Title(x, y, _("Direction:")));
139         x += 100;
140         add_subwindow(in = new BandSlideIn(plugin, 
141                 this,
142                 x,
143                 y));
144         x += 100;
145         add_subwindow(out = new BandSlideOut(plugin, 
146                 this,
147                 x,
148                 y));
150         show_window();
151         flush();
157 PLUGIN_THREAD_OBJECT(BandSlideMain, BandSlideThread, BandSlideWindow)
164 BandSlideMain::BandSlideMain(PluginServer *server)
165  : PluginVClient(server)
167         bands = 9;
168         direction = 0;
169         PLUGIN_CONSTRUCTOR_MACRO
172 BandSlideMain::~BandSlideMain()
174         PLUGIN_DESTRUCTOR_MACRO
177 char* BandSlideMain::plugin_title() { return _("BandSlide"); }
178 int BandSlideMain::is_video() { return 1; }
179 int BandSlideMain::is_transition() { return 1; }
180 int BandSlideMain::uses_gui() { return 1; }
181 SHOW_GUI_MACRO(BandSlideMain, BandSlideThread);
182 SET_STRING_MACRO(BandSlideMain)
183 RAISE_WINDOW_MACRO(BandSlideMain)
186 VFrame* BandSlideMain::new_picon()
188         return new VFrame(picon_png);
191 int BandSlideMain::load_defaults()
193         char directory[BCTEXTLEN];
194 // set the default directory
195         sprintf(directory, "%sbandslide.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 BandSlideMain::save_defaults()
208         defaults->update("BANDS", bands);
209         defaults->update("DIRECTION", direction);
210         defaults->save();
211         return 0;
214 void BandSlideMain::save_data(KeyFrame *keyframe)
216         FileXML output;
217         output.set_shared_string(keyframe->data, MESSAGESIZE);
218         output.tag.set_title("BANDSLIDE");
219         output.tag.set_property("BANDS", bands);
220         output.tag.set_property("DIRECTION", direction);
221         output.append_tag();
222         output.terminate_string();
225 void BandSlideMain::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("BANDSLIDE"))
234                 {
235                         bands = input.tag.get_property("BANDS", bands);
236                         direction = input.tag.get_property("DIRECTION", direction);
237                 }
238         }
241 void BandSlideMain::load_configuration()
243         read_data(get_prev_keyframe(get_source_position()));
248 #define BANDSLIDE(type, components) \
249 { \
250         if(direction == 0) \
251         { \
252                 int x = w * \
253                         PluginClient::get_source_position() / \
254                         PluginClient::get_total_len(); \
255                 for(int i = 0; i < bands; i++) \
256                 { \
257                         for(int j = 0; j < band_h; j++) \
258                         { \
259                                 int row = i * band_h + j; \
260                                  \
261                                 if(row >= 0 && row < h) \
262                                 { \
263                                         type *in_row = (type*)incoming->get_rows()[row]; \
264                                         type *out_row = (type*)outgoing->get_rows()[row]; \
265                                          \
266                                         if(i % 2) \
267                                         { \
268                                                 for(int k = 0, l = w - x; k < x; k++, l++) \
269                                                 { \
270                                                         out_row[k * components + 0] = in_row[l * components + 0]; \
271                                                         out_row[k * components + 1] = in_row[l * components + 1]; \
272                                                         out_row[k * components + 2] = in_row[l * components + 2]; \
273                                                         if(components == 4) out_row[k * components + 3] = in_row[l * components + 3]; \
274                                                 } \
275                                         } \
276                                         else \
277                                         { \
278                                                 for(int k = w - x, l = 0; k < w; k++, l++) \
279                                                 { \
280                                                         out_row[k * components + 0] = in_row[l * components + 0]; \
281                                                         out_row[k * components + 1] = in_row[l * components + 1]; \
282                                                         out_row[k * components + 2] = in_row[l * components + 2]; \
283                                                         if(components == 4) out_row[k * components + 3] = in_row[l * components + 3]; \
284                                                 } \
285                                         } \
286                                 } \
287                         } \
288                 } \
289         } \
290         else \
291         { \
292                 int x = w - w * \
293                         PluginClient::get_source_position() / \
294                         PluginClient::get_total_len(); \
295                 for(int i = 0; i < bands; i++) \
296                 { \
297                         for(int j = 0; j < band_h; j++) \
298                         { \
299                                 int row = i * band_h + j; \
301                                 if(row >= 0 && row < h) \
302                                 { \
303                                         type *in_row = (type*)incoming->get_rows()[row]; \
304                                         type *out_row = (type*)outgoing->get_rows()[row]; \
306                                         if(i % 2) \
307                                         { \
308                                                 int k, l; \
309                                                 for(k = 0, l = w - x; k < x; k++, l++) \
310                                                 { \
311                                                         out_row[k * components + 0] = out_row[l * components + 0]; \
312                                                         out_row[k * components + 1] = out_row[l * components + 1]; \
313                                                         out_row[k * components + 2] = out_row[l * components + 2]; \
314                                                         if(components == 4) out_row[k * components + 3] = out_row[l * components + 3]; \
315                                                 } \
316                                                 for( ; k < w; k++) \
317                                                 { \
318                                                         out_row[k * components + 0] = in_row[k * components + 0]; \
319                                                         out_row[k * components + 1] = in_row[k * components + 1]; \
320                                                         out_row[k * components + 2] = in_row[k * components + 2]; \
321                                                         if(components == 4) out_row[k * components + 3] = in_row[k * components + 3]; \
322                                                 } \
323                                         } \
324                                         else \
325                                         { \
326                                                 for(int k = w - 1, l = x - 1; k >= w - x; k--, l--) \
327                                                 { \
328                                                         out_row[k * components + 0] = out_row[l * components + 0]; \
329                                                         out_row[k * components + 1] = out_row[l * components + 1]; \
330                                                         out_row[k * components + 2] = out_row[l * components + 2]; \
331                                                         if(components == 4) out_row[k * components + 3] = out_row[l * components + 3]; \
332                                                 } \
333                                                 for(int k = 0; k < w - x; k++) \
334                                                 { \
335                                                         out_row[k * components + 0] = in_row[k * components + 0]; \
336                                                         out_row[k * components + 1] = in_row[k * components + 1]; \
337                                                         out_row[k * components + 2] = in_row[k * components + 2]; \
338                                                         if(components == 4) out_row[k * components + 3] = in_row[k * components + 3]; \
339                                                 } \
340                                         } \
341                                 } \
342                         } \
343                 } \
344         } \
349 int BandSlideMain::process_realtime(VFrame *incoming, VFrame *outgoing)
351         load_configuration();
353         int w = incoming->get_w();
354         int h = incoming->get_h();
355         int band_h = ((bands == 0) ? h : (h / bands + 1));
357         switch(incoming->get_color_model())
358         {
359                 case BC_RGB888:
360                 case BC_YUV888:
361                         BANDSLIDE(unsigned char, 3)
362                         break;
363                 case BC_RGBA8888:
364                 case BC_YUVA8888:
365                         BANDSLIDE(unsigned char, 4)
366                         break;
367                 case BC_RGB161616:
368                 case BC_YUV161616:
369                         BANDSLIDE(uint16_t, 3)
370                         break;
371                 case BC_RGBA16161616:
372                 case BC_YUVA16161616:
373                         BANDSLIDE(uint16_t, 4)
374                         break;
375         }
377         return 0;