r370: Heroine Virutal's official release 1.2.1
[cinelerra_cv/mob.git] / hvirtual / plugins / bandslide / bandslide.C
blob3d3fd51b73345ba3ae83e4e3fdad3120d2a25cde
1 #include "bandslide.h"
2 #include "bcdisplayinfo.h"
3 #include "defaults.h"
4 #include "edl.inc"
5 #include "filexml.h"
6 #include "language.h"
7 #include "overlayframe.h"
8 #include "picon_png.h"
9 #include "vframe.h"
12 #include <stdint.h>
13 #include <string.h>
14 #include <libintl.h>
21 REGISTER_PLUGIN(BandSlideMain)
27 BandSlideCount::BandSlideCount(BandSlideMain *plugin, 
28         BandSlideWindow *window,
29         int x,
30         int y)
31  : BC_TumbleTextBox(window, 
32                 (int64_t)plugin->bands,
33                 (int64_t)0,
34                 (int64_t)1000,
35                 x, 
36                 y, 
37                 50)
39         this->plugin = plugin;
40         this->window = window;
43 int BandSlideCount::handle_event()
45         plugin->bands = atol(get_text());
46         plugin->send_configure_change();
47         return 0;
50 BandSlideIn::BandSlideIn(BandSlideMain *plugin, 
51         BandSlideWindow *window,
52         int x,
53         int y)
54  : BC_Radial(x, 
55                 y, 
56                 plugin->direction == 0, 
57                 _("In"))
59         this->plugin = plugin;
60         this->window = window;
63 int BandSlideIn::handle_event()
65         update(1);
66         plugin->direction = 0;
67         window->out->update(0);
68         plugin->send_configure_change();
69         return 0;
72 BandSlideOut::BandSlideOut(BandSlideMain *plugin, 
73         BandSlideWindow *window,
74         int x,
75         int y)
76  : BC_Radial(x, 
77                 y, 
78                 plugin->direction == 1, 
79                 _("Out"))
81         this->plugin = plugin;
82         this->window = window;
85 int BandSlideOut::handle_event()
87         update(1);
88         plugin->direction = 1;
89         window->in->update(0);
90         plugin->send_configure_change();
91         return 0;
101 BandSlideWindow::BandSlideWindow(BandSlideMain *plugin, int x, int y)
102  : BC_Window(plugin->gui_string, 
103         x, 
104         y, 
105         320, 
106         100, 
107         320, 
108         100, 
109         0, 
110         0,
111         1)
113         this->plugin = plugin;
117 int BandSlideWindow::close_event()
119         set_done(1);
120         return 1;
123 void BandSlideWindow::create_objects()
125         int x = 10, y = 10;
126         add_subwindow(new BC_Title(x, y, _("Bands:")));
127         x += 50;
128         count = new BandSlideCount(plugin, 
129                 this,
130                 x,
131                 y);
132         count->create_objects();
134         y += 30;
135         x = 10;
136         add_subwindow(new BC_Title(x, y, _("Direction:")));
137         x += 100;
138         add_subwindow(in = new BandSlideIn(plugin, 
139                 this,
140                 x,
141                 y));
142         x += 100;
143         add_subwindow(out = new BandSlideOut(plugin, 
144                 this,
145                 x,
146                 y));
148         show_window();
149         flush();
155 PLUGIN_THREAD_OBJECT(BandSlideMain, BandSlideThread, BandSlideWindow)
162 BandSlideMain::BandSlideMain(PluginServer *server)
163  : PluginVClient(server)
165         bands = 9;
166         direction = 0;
167         PLUGIN_CONSTRUCTOR_MACRO
170 BandSlideMain::~BandSlideMain()
172         PLUGIN_DESTRUCTOR_MACRO
175 char* BandSlideMain::plugin_title() { return N_("BandSlide"); }
176 int BandSlideMain::is_video() { return 1; }
177 int BandSlideMain::is_transition() { return 1; }
178 int BandSlideMain::uses_gui() { return 1; }
180 SHOW_GUI_MACRO(BandSlideMain, BandSlideThread);
181 SET_STRING_MACRO(BandSlideMain)
182 RAISE_WINDOW_MACRO(BandSlideMain)
185 VFrame* BandSlideMain::new_picon()
187         return new VFrame(picon_png);
190 int BandSlideMain::load_defaults()
192         char directory[BCTEXTLEN];
193 // set the default directory
194         sprintf(directory, "%sbandslide.rc", BCASTDIR);
196 // load the defaults
197         defaults = new Defaults(directory);
198         defaults->load();
200         bands = defaults->get("BANDS", bands);
201         direction = defaults->get("DIRECTION", direction);
202         return 0;
205 int BandSlideMain::save_defaults()
207         defaults->update("BANDS", bands);
208         defaults->update("DIRECTION", direction);
209         defaults->save();
210         return 0;
213 void BandSlideMain::save_data(KeyFrame *keyframe)
215         FileXML output;
216         output.set_shared_string(keyframe->data, MESSAGESIZE);
217         output.tag.set_title("BANDSLIDE");
218         output.tag.set_property("BANDS", bands);
219         output.tag.set_property("DIRECTION", direction);
220         output.append_tag();
221         output.terminate_string();
224 void BandSlideMain::read_data(KeyFrame *keyframe)
226         FileXML input;
228         input.set_shared_string(keyframe->data, strlen(keyframe->data));
230         while(!input.read_tag())
231         {
232                 if(input.tag.title_is("BANDSLIDE"))
233                 {
234                         bands = input.tag.get_property("BANDS", bands);
235                         direction = input.tag.get_property("DIRECTION", direction);
236                 }
237         }
240 void BandSlideMain::load_configuration()
242         read_data(get_prev_keyframe(get_source_position()));
247 #define BANDSLIDE(type, components) \
248 { \
249         if(direction == 0) \
250         { \
251                 int x = w * \
252                         PluginClient::get_source_position() / \
253                         PluginClient::get_total_len(); \
254                 for(int i = 0; i < bands; i++) \
255                 { \
256                         for(int j = 0; j < band_h; j++) \
257                         { \
258                                 int row = i * band_h + j; \
259                                  \
260                                 if(row >= 0 && row < h) \
261                                 { \
262                                         type *in_row = (type*)incoming->get_rows()[row]; \
263                                         type *out_row = (type*)outgoing->get_rows()[row]; \
264                                          \
265                                         if(i % 2) \
266                                         { \
267                                                 for(int k = 0, l = w - x; k < x; k++, l++) \
268                                                 { \
269                                                         out_row[k * components + 0] = in_row[l * components + 0]; \
270                                                         out_row[k * components + 1] = in_row[l * components + 1]; \
271                                                         out_row[k * components + 2] = in_row[l * components + 2]; \
272                                                         if(components == 4) out_row[k * components + 3] = in_row[l * components + 3]; \
273                                                 } \
274                                         } \
275                                         else \
276                                         { \
277                                                 for(int k = w - x, l = 0; k < w; k++, l++) \
278                                                 { \
279                                                         out_row[k * components + 0] = in_row[l * components + 0]; \
280                                                         out_row[k * components + 1] = in_row[l * components + 1]; \
281                                                         out_row[k * components + 2] = in_row[l * components + 2]; \
282                                                         if(components == 4) out_row[k * components + 3] = in_row[l * components + 3]; \
283                                                 } \
284                                         } \
285                                 } \
286                         } \
287                 } \
288         } \
289         else \
290         { \
291                 int x = w - w * \
292                         PluginClient::get_source_position() / \
293                         PluginClient::get_total_len(); \
294                 for(int i = 0; i < bands; i++) \
295                 { \
296                         for(int j = 0; j < band_h; j++) \
297                         { \
298                                 int row = i * band_h + j; \
300                                 if(row >= 0 && row < h) \
301                                 { \
302                                         type *in_row = (type*)incoming->get_rows()[row]; \
303                                         type *out_row = (type*)outgoing->get_rows()[row]; \
305                                         if(i % 2) \
306                                         { \
307                                                 int k, l; \
308                                                 for(k = 0, l = w - x; k < x; k++, l++) \
309                                                 { \
310                                                         out_row[k * components + 0] = out_row[l * components + 0]; \
311                                                         out_row[k * components + 1] = out_row[l * components + 1]; \
312                                                         out_row[k * components + 2] = out_row[l * components + 2]; \
313                                                         if(components == 4) out_row[k * components + 3] = out_row[l * components + 3]; \
314                                                 } \
315                                                 for( ; k < w; k++) \
316                                                 { \
317                                                         out_row[k * components + 0] = in_row[k * components + 0]; \
318                                                         out_row[k * components + 1] = in_row[k * components + 1]; \
319                                                         out_row[k * components + 2] = in_row[k * components + 2]; \
320                                                         if(components == 4) out_row[k * components + 3] = in_row[k * components + 3]; \
321                                                 } \
322                                         } \
323                                         else \
324                                         { \
325                                                 for(int k = w - 1, l = x - 1; k >= w - x; k--, l--) \
326                                                 { \
327                                                         out_row[k * components + 0] = out_row[l * components + 0]; \
328                                                         out_row[k * components + 1] = out_row[l * components + 1]; \
329                                                         out_row[k * components + 2] = out_row[l * components + 2]; \
330                                                         if(components == 4) out_row[k * components + 3] = out_row[l * components + 3]; \
331                                                 } \
332                                                 for(int k = 0; k < w - x; k++) \
333                                                 { \
334                                                         out_row[k * components + 0] = in_row[k * components + 0]; \
335                                                         out_row[k * components + 1] = in_row[k * components + 1]; \
336                                                         out_row[k * components + 2] = in_row[k * components + 2]; \
337                                                         if(components == 4) out_row[k * components + 3] = in_row[k * components + 3]; \
338                                                 } \
339                                         } \
340                                 } \
341                         } \
342                 } \
343         } \
348 int BandSlideMain::process_realtime(VFrame *incoming, VFrame *outgoing)
350         load_configuration();
352         int w = incoming->get_w();
353         int h = incoming->get_h();
354         int band_h = ((bands == 0) ? h : (h / bands + 1));
356         switch(incoming->get_color_model())
357         {
358                 case BC_RGB888:
359                 case BC_YUV888:
360                         BANDSLIDE(unsigned char, 3)
361                         break;
362                 case BC_RGB_FLOAT:
363                         BANDSLIDE(float, 3);
364                         break;
365                 case BC_RGBA8888:
366                 case BC_YUVA8888:
367                         BANDSLIDE(unsigned char, 4)
368                         break;
369                 case BC_RGBA_FLOAT:
370                         BANDSLIDE(float, 4);
371                         break;
372                 case BC_RGB161616:
373                 case BC_YUV161616:
374                         BANDSLIDE(uint16_t, 3)
375                         break;
376                 case BC_RGBA16161616:
377                 case BC_YUVA16161616:
378                         BANDSLIDE(uint16_t, 4)
379                         break;
380         }
382         return 0;