Condense the xml-cleanup into a short feature-branch
[cinelerra_cv/mob.git] / plugins / bandslide / bandslide.C
blob6fca9168928cd5fd117fd2101338bab813b69acf
1 #include "bandslide.h"
2 #include "bcdisplayinfo.h"
3 #include "bchash.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 BC_Hash(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.tag.set_title("/BANDSLIDE");
222         output.append_tag();
223         output.terminate_string();
226 void BandSlideMain::read_data(KeyFrame *keyframe)
228         FileXML input;
230         input.set_shared_string(keyframe->data, strlen(keyframe->data));
232         while(!input.read_tag())
233         {
234                 if(input.tag.title_is("BANDSLIDE"))
235                 {
236                         bands = input.tag.get_property("BANDS", bands);
237                         direction = input.tag.get_property("DIRECTION", direction);
238                 }
239         }
242 void BandSlideMain::load_configuration()
244         read_data(get_prev_keyframe(get_source_position()));
249 #define BANDSLIDE(type, components) \
250 { \
251         if(direction == 0) \
252         { \
253                 int x = w * \
254                         PluginClient::get_source_position() / \
255                         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]; \
266                                          \
267                                         if(i % 2) \
268                                         { \
269                                                 for(int k = 0, l = w - x; k < x; k++, l++) \
270                                                 { \
271                                                         out_row[k * components + 0] = in_row[l * components + 0]; \
272                                                         out_row[k * components + 1] = in_row[l * components + 1]; \
273                                                         out_row[k * components + 2] = in_row[l * components + 2]; \
274                                                         if(components == 4) out_row[k * components + 3] = in_row[l * components + 3]; \
275                                                 } \
276                                         } \
277                                         else \
278                                         { \
279                                                 for(int k = w - x, l = 0; k < w; k++, l++) \
280                                                 { \
281                                                         out_row[k * components + 0] = in_row[l * components + 0]; \
282                                                         out_row[k * components + 1] = in_row[l * components + 1]; \
283                                                         out_row[k * components + 2] = in_row[l * components + 2]; \
284                                                         if(components == 4) out_row[k * components + 3] = in_row[l * 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(); \
296                 for(int i = 0; i < bands; i++) \
297                 { \
298                         for(int j = 0; j < band_h; j++) \
299                         { \
300                                 int row = i * band_h + j; \
302                                 if(row >= 0 && row < h) \
303                                 { \
304                                         type *in_row = (type*)incoming->get_rows()[row]; \
305                                         type *out_row = (type*)outgoing->get_rows()[row]; \
307                                         if(i % 2) \
308                                         { \
309                                                 int k, l; \
310                                                 for(k = 0, l = w - x; k < x; k++, l++) \
311                                                 { \
312                                                         out_row[k * components + 0] = out_row[l * components + 0]; \
313                                                         out_row[k * components + 1] = out_row[l * components + 1]; \
314                                                         out_row[k * components + 2] = out_row[l * components + 2]; \
315                                                         if(components == 4) out_row[k * components + 3] = out_row[l * components + 3]; \
316                                                 } \
317                                                 for( ; k < w; k++) \
318                                                 { \
319                                                         out_row[k * components + 0] = in_row[k * components + 0]; \
320                                                         out_row[k * components + 1] = in_row[k * components + 1]; \
321                                                         out_row[k * components + 2] = in_row[k * components + 2]; \
322                                                         if(components == 4) out_row[k * components + 3] = in_row[k * components + 3]; \
323                                                 } \
324                                         } \
325                                         else \
326                                         { \
327                                                 for(int k = w - 1, l = x - 1; k >= w - x; k--, l--) \
328                                                 { \
329                                                         out_row[k * components + 0] = out_row[l * components + 0]; \
330                                                         out_row[k * components + 1] = out_row[l * components + 1]; \
331                                                         out_row[k * components + 2] = out_row[l * components + 2]; \
332                                                         if(components == 4) out_row[k * components + 3] = out_row[l * components + 3]; \
333                                                 } \
334                                                 for(int k = 0; k < w - x; k++) \
335                                                 { \
336                                                         out_row[k * components + 0] = in_row[k * components + 0]; \
337                                                         out_row[k * components + 1] = in_row[k * components + 1]; \
338                                                         out_row[k * components + 2] = in_row[k * components + 2]; \
339                                                         if(components == 4) out_row[k * components + 3] = in_row[k * components + 3]; \
340                                                 } \
341                                         } \
342                                 } \
343                         } \
344                 } \
345         } \
350 int BandSlideMain::process_realtime(VFrame *incoming, VFrame *outgoing)
352         load_configuration();
354         int w = incoming->get_w();
355         int h = incoming->get_h();
356         int band_h = ((bands == 0) ? h : (h / bands + 1));
358         switch(incoming->get_color_model())
359         {
360                 case BC_RGB888:
361                 case BC_YUV888:
362                         BANDSLIDE(unsigned char, 3)
363                         break;
364                 case BC_RGB_FLOAT:
365                         BANDSLIDE(float, 3);
366                         break;
367                 case BC_RGBA8888:
368                 case BC_YUVA8888:
369                         BANDSLIDE(unsigned char, 4)
370                         break;
371                 case BC_RGBA_FLOAT:
372                         BANDSLIDE(float, 4);
373                         break;
374                 case BC_RGB161616:
375                 case BC_YUV161616:
376                         BANDSLIDE(uint16_t, 3)
377                         break;
378                 case BC_RGBA16161616:
379                 case BC_YUVA16161616:
380                         BANDSLIDE(uint16_t, 4)
381                         break;
382         }
384         return 0;