add BC_SCALE env var for hi def monitors, cleanup theme data
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / bandslide / bandslide.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #include "bandslide.h"
23 #include "bcdisplayinfo.h"
24 #include "bchash.h"
25 #include "edl.inc"
26 #include "filexml.h"
27 #include "language.h"
28 #include "overlayframe.h"
29 #include "vframe.h"
30
31
32 #include <stdint.h>
33 #include <string.h>
34 #include <libintl.h>
35
36
37
38
39
40
41 REGISTER_PLUGIN(BandSlideMain)
42
43
44
45
46
47 BandSlideCount::BandSlideCount(BandSlideMain *plugin,
48         BandSlideWindow *window,
49         int x,
50         int y)
51  : BC_TumbleTextBox(window,
52                 (int64_t)plugin->bands,
53                 (int64_t)0,
54                 (int64_t)1000,
55                 x,
56                 y,
57                 50)
58 {
59         this->plugin = plugin;
60         this->window = window;
61 }
62
63 int BandSlideCount::handle_event()
64 {
65         plugin->bands = atol(get_text());
66         plugin->send_configure_change();
67         return 0;
68 }
69
70 BandSlideIn::BandSlideIn(BandSlideMain *plugin,
71         BandSlideWindow *window,
72         int x,
73         int y)
74  : BC_Radial(x,
75                 y,
76                 plugin->direction == 0,
77                 _("In"))
78 {
79         this->plugin = plugin;
80         this->window = window;
81 }
82
83 int BandSlideIn::handle_event()
84 {
85         update(1);
86         plugin->direction = 0;
87         window->out->update(0);
88         plugin->send_configure_change();
89         return 0;
90 }
91
92 BandSlideOut::BandSlideOut(BandSlideMain *plugin,
93         BandSlideWindow *window,
94         int x,
95         int y)
96  : BC_Radial(x,
97                 y,
98                 plugin->direction == 1,
99                 _("Out"))
100 {
101         this->plugin = plugin;
102         this->window = window;
103 }
104
105 int BandSlideOut::handle_event()
106 {
107         update(1);
108         plugin->direction = 1;
109         window->in->update(0);
110         plugin->send_configure_change();
111         return 0;
112 }
113
114
115
116
117
118
119
120
121 BandSlideWindow::BandSlideWindow(BandSlideMain *plugin)
122  : PluginClientWindow(plugin,
123         xS(320),
124         yS(100),
125         xS(320),
126         yS(100),
127         0)
128 {
129         this->plugin = plugin;
130 }
131
132
133 void BandSlideWindow::create_objects()
134 {
135         int xs10 = xS(10), xs50 = xS(50), xs100 = xS(100);
136         int ys10 = yS(10), ys30 = yS(30);
137         int x = xs10, y = ys10;
138         add_subwindow(new BC_Title(x, y, _("Bands:")));
139         x += xs50;
140         count = new BandSlideCount(plugin,
141                 this,
142                 x,
143                 y);
144         count->create_objects();
145
146         y += ys30;
147         x = xs10;
148         add_subwindow(new BC_Title(x, y, _("Direction:")));
149         x += xs100;
150         add_subwindow(in = new BandSlideIn(plugin,
151                 this,
152                 x,
153                 y));
154         x += xs100;
155         add_subwindow(out = new BandSlideOut(plugin,
156                 this,
157                 x,
158                 y));
159
160         show_window();
161         flush();
162 }
163
164
165
166
167
168
169
170
171
172
173 BandSlideMain::BandSlideMain(PluginServer *server)
174  : PluginVClient(server)
175 {
176         bands = 9;
177         direction = 0;
178
179 }
180
181 BandSlideMain::~BandSlideMain()
182 {
183
184 }
185
186 const char* BandSlideMain::plugin_title() { return N_("BandSlide"); }
187 int BandSlideMain::is_transition() { return 1; }
188 int BandSlideMain::uses_gui() { return 1; }
189
190 NEW_WINDOW_MACRO(BandSlideMain, BandSlideWindow);
191
192
193 void BandSlideMain::save_data(KeyFrame *keyframe)
194 {
195         FileXML output;
196         output.set_shared_output(keyframe->xbuf);
197         output.tag.set_title("BANDSLIDE");
198         output.tag.set_property("BANDS", bands);
199         output.tag.set_property("DIRECTION", direction);
200         output.append_tag();
201         output.tag.set_title("/BANDSLIDE");
202         output.append_tag();
203         output.append_newline();
204         output.terminate_string();
205 }
206
207 void BandSlideMain::read_data(KeyFrame *keyframe)
208 {
209         FileXML input;
210
211         input.set_shared_input(keyframe->xbuf);
212
213         while(!input.read_tag())
214         {
215                 if(input.tag.title_is("BANDSLIDE"))
216                 {
217                         bands = input.tag.get_property("BANDS", bands);
218                         direction = input.tag.get_property("DIRECTION", direction);
219                 }
220         }
221 }
222
223 int BandSlideMain::load_configuration()
224 {
225         read_data(get_prev_keyframe(get_source_position()));
226         return 1;
227 }
228
229
230
231 #define BANDSLIDE(type, components) \
232 { \
233         if(direction == 0) \
234         { \
235                 int x = w * \
236                         PluginClient::get_source_position() / \
237                         PluginClient::get_total_len(); \
238                 for(int i = 0; i < bands; i++) \
239                 { \
240                         for(int j = 0; j < band_h; j++) \
241                         { \
242                                 int row = i * band_h + j; \
243                                  \
244                                 if(row >= 0 && row < h) \
245                                 { \
246                                         type *in_row = (type*)incoming->get_rows()[row]; \
247                                         type *out_row = (type*)outgoing->get_rows()[row]; \
248                                          \
249                                         if(i % 2) \
250                                         { \
251                                                 for(int k = 0, l = w - x; k < x; k++, l++) \
252                                                 { \
253                                                         out_row[k * components + 0] = in_row[l * components + 0]; \
254                                                         out_row[k * components + 1] = in_row[l * components + 1]; \
255                                                         out_row[k * components + 2] = in_row[l * components + 2]; \
256                                                         if(components == 4) out_row[k * components + 3] = in_row[l * components + 3]; \
257                                                 } \
258                                         } \
259                                         else \
260                                         { \
261                                                 for(int k = w - x, l = 0; k < w; k++, l++) \
262                                                 { \
263                                                         out_row[k * components + 0] = in_row[l * components + 0]; \
264                                                         out_row[k * components + 1] = in_row[l * components + 1]; \
265                                                         out_row[k * components + 2] = in_row[l * components + 2]; \
266                                                         if(components == 4) out_row[k * components + 3] = in_row[l * components + 3]; \
267                                                 } \
268                                         } \
269                                 } \
270                         } \
271                 } \
272         } \
273         else \
274         { \
275                 int x = w - w * \
276                         PluginClient::get_source_position() / \
277                         PluginClient::get_total_len(); \
278                 for(int i = 0; i < bands; i++) \
279                 { \
280                         for(int j = 0; j < band_h; j++) \
281                         { \
282                                 int row = i * band_h + j; \
283  \
284                                 if(row >= 0 && row < h) \
285                                 { \
286                                         type *in_row = (type*)incoming->get_rows()[row]; \
287                                         type *out_row = (type*)outgoing->get_rows()[row]; \
288  \
289                                         if(i % 2) \
290                                         { \
291                                                 int k, l; \
292                                                 for(k = 0, l = w - x; k < x; k++, l++) \
293                                                 { \
294                                                         out_row[k * components + 0] = out_row[l * components + 0]; \
295                                                         out_row[k * components + 1] = out_row[l * components + 1]; \
296                                                         out_row[k * components + 2] = out_row[l * components + 2]; \
297                                                         if(components == 4) out_row[k * components + 3] = out_row[l * components + 3]; \
298                                                 } \
299                                                 for( ; k < w; k++) \
300                                                 { \
301                                                         out_row[k * components + 0] = in_row[k * components + 0]; \
302                                                         out_row[k * components + 1] = in_row[k * components + 1]; \
303                                                         out_row[k * components + 2] = in_row[k * components + 2]; \
304                                                         if(components == 4) out_row[k * components + 3] = in_row[k * components + 3]; \
305                                                 } \
306                                         } \
307                                         else \
308                                         { \
309                                                 for(int k = w - 1, l = x - 1; k >= w - 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(int k = 0; k < w - x; 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                                 } \
325                         } \
326                 } \
327         } \
328 }
329
330
331
332 int BandSlideMain::process_realtime(VFrame *incoming, VFrame *outgoing)
333 {
334         load_configuration();
335
336         int w = incoming->get_w();
337         int h = incoming->get_h();
338         int band_h = ((bands == 0) ? h : (h / bands + 1));
339
340         switch(incoming->get_color_model())
341         {
342                 case BC_RGB888:
343                 case BC_YUV888:
344                         BANDSLIDE(unsigned char, 3)
345                         break;
346                 case BC_RGB_FLOAT:
347                         BANDSLIDE(float, 3);
348                         break;
349                 case BC_RGBA8888:
350                 case BC_YUVA8888:
351                         BANDSLIDE(unsigned char, 4)
352                         break;
353                 case BC_RGBA_FLOAT:
354                         BANDSLIDE(float, 4);
355                         break;
356                 case BC_RGB161616:
357                 case BC_YUV161616:
358                         BANDSLIDE(uint16_t, 3)
359                         break;
360                 case BC_RGBA16161616:
361                 case BC_YUVA16161616:
362                         BANDSLIDE(uint16_t, 4)
363                         break;
364         }
365
366         return 0;
367 }