add BC_SCALE env var for hi def monitors, cleanup theme data
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / irissquare / irissquare.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 "bcdisplayinfo.h"
23 #include "bchash.h"
24 #include "edl.inc"
25 #include "filexml.h"
26 #include "language.h"
27 #include "overlayframe.h"
28 #include "vframe.h"
29 #include "irissquare.h"
30
31
32 #include <stdint.h>
33 #include <string.h>
34
35
36 REGISTER_PLUGIN(IrisSquareMain)
37
38
39
40
41
42 IrisSquareIn::IrisSquareIn(IrisSquareMain *plugin,
43         IrisSquareWindow *window,
44         int x,
45         int y)
46  : BC_Radial(x,
47                 y,
48                 plugin->direction == 0,
49                 _("In"))
50 {
51         this->plugin = plugin;
52         this->window = window;
53 }
54
55 int IrisSquareIn::handle_event()
56 {
57         update(1);
58         plugin->direction = 0;
59         window->out->update(0);
60         plugin->send_configure_change();
61         return 0;
62 }
63
64 IrisSquareOut::IrisSquareOut(IrisSquareMain *plugin,
65         IrisSquareWindow *window,
66         int x,
67         int y)
68  : BC_Radial(x,
69                 y,
70                 plugin->direction == 1,
71                 _("Out"))
72 {
73         this->plugin = plugin;
74         this->window = window;
75 }
76
77 int IrisSquareOut::handle_event()
78 {
79         update(1);
80         plugin->direction = 1;
81         window->in->update(0);
82         plugin->send_configure_change();
83         return 0;
84 }
85
86
87
88
89
90
91
92
93 IrisSquareWindow::IrisSquareWindow(IrisSquareMain *plugin)
94  : PluginClientWindow(plugin,
95         xS(320),
96         yS(50),
97         xS(320),
98         yS(50),
99         0)
100 {
101         this->plugin = plugin;
102 }
103
104
105 void IrisSquareWindow::create_objects()
106 {
107         int xs10 = xS(10), xs100 = xS(100);
108         int ys10 = yS(10);
109         int x = xs10, y = ys10;
110         add_subwindow(new BC_Title(x, y, _("Direction:")));
111         x += xs100;
112         add_subwindow(in = new IrisSquareIn(plugin,
113                 this,
114                 x,
115                 y));
116         x += xs100;
117         add_subwindow(out = new IrisSquareOut(plugin,
118                 this,
119                 x,
120                 y));
121         show_window();
122         flush();
123 }
124
125
126
127
128
129
130
131
132
133
134 IrisSquareMain::IrisSquareMain(PluginServer *server)
135  : PluginVClient(server)
136 {
137         direction = 0;
138
139 }
140
141 IrisSquareMain::~IrisSquareMain()
142 {
143
144 }
145
146 const char* IrisSquareMain::plugin_title() { return N_("IrisSquare"); }
147 int IrisSquareMain::is_video() { return 1; }
148 int IrisSquareMain::is_transition() { return 1; }
149 int IrisSquareMain::uses_gui() { return 1; }
150
151 NEW_WINDOW_MACRO(IrisSquareMain, IrisSquareWindow)
152
153
154 void IrisSquareMain::save_data(KeyFrame *keyframe)
155 {
156         FileXML output;
157         output.set_shared_output(keyframe->xbuf);
158         output.tag.set_title("IRISSQUARE");
159         output.tag.set_property("DIRECTION", direction);
160         output.append_tag();
161         output.tag.set_title("/IRISSQUARE");
162         output.append_tag();
163         output.append_newline();
164         output.terminate_string();
165 }
166
167 void IrisSquareMain::read_data(KeyFrame *keyframe)
168 {
169         FileXML input;
170
171         input.set_shared_input(keyframe->xbuf);
172
173         while(!input.read_tag())
174         {
175                 if(input.tag.title_is("IRISSQUARE"))
176                 {
177                         direction = input.tag.get_property("DIRECTION", direction);
178                 }
179         }
180 }
181
182 int IrisSquareMain::load_configuration()
183 {
184         read_data(get_prev_keyframe(get_source_position()));
185         return 1;
186 }
187
188
189
190
191
192
193 #define IRISSQUARE(type, components) \
194 { \
195         if(direction == 0) \
196         { \
197                 int x1 = w / 2 - w / 2 *  \
198                         PluginClient::get_source_position() /  \
199                         PluginClient::get_total_len(); \
200                 int x2 = w / 2 + w / 2 *  \
201                         PluginClient::get_source_position() /  \
202                         PluginClient::get_total_len(); \
203                 int y1 = h / 2 - h / 2 *  \
204                         PluginClient::get_source_position() /  \
205                         PluginClient::get_total_len(); \
206                 int y2 = h / 2 + h / 2 *  \
207                         PluginClient::get_source_position() /  \
208                         PluginClient::get_total_len(); \
209                 for(int j = y1; j < y2; j++) \
210                 { \
211                         type *in_row = (type*)incoming->get_rows()[j]; \
212                         type *out_row = (type*)outgoing->get_rows()[j]; \
213  \
214                         for(int k = x1; k < x2; k++) \
215                         { \
216                                 out_row[k * components + 0] = in_row[k * components + 0]; \
217                                 out_row[k * components + 1] = in_row[k * components + 1]; \
218                                 out_row[k * components + 2] = in_row[k * components + 2]; \
219                                 if(components == 4) out_row[k * components + 3] = in_row[k * components + 3]; \
220                         } \
221                 } \
222         } \
223         else \
224         { \
225                 int x1 = w / 2 *  \
226                         PluginClient::get_source_position() /  \
227                         PluginClient::get_total_len(); \
228                 int x2 = w - w / 2 *  \
229                         PluginClient::get_source_position() /  \
230                         PluginClient::get_total_len(); \
231                 int y1 = h / 2 *  \
232                         PluginClient::get_source_position() /  \
233                         PluginClient::get_total_len(); \
234                 int y2 = h - h / 2 *  \
235                         PluginClient::get_source_position() /  \
236                         PluginClient::get_total_len(); \
237                 for(int j = 0; j < y1; j++) \
238                 { \
239                         type *in_row = (type*)incoming->get_rows()[j]; \
240                         type *out_row = (type*)outgoing->get_rows()[j]; \
241  \
242                         for(int k = 0; k < w; k++) \
243                         { \
244                                 out_row[k * components + 0] = in_row[k * components + 0]; \
245                                 out_row[k * components + 1] = in_row[k * components + 1]; \
246                                 out_row[k * components + 2] = in_row[k * components + 2]; \
247                                 if(components == 4) out_row[k * components + 3] = in_row[k * components + 3]; \
248                         } \
249                 } \
250                 for(int j = y1; j < y2; j++) \
251                 { \
252                         type *in_row = (type*)incoming->get_rows()[j]; \
253                         type *out_row = (type*)outgoing->get_rows()[j]; \
254  \
255                         for(int k = 0; k < x1; k++) \
256                         { \
257                                 out_row[k * components + 0] = in_row[k * components + 0]; \
258                                 out_row[k * components + 1] = in_row[k * components + 1]; \
259                                 out_row[k * components + 2] = in_row[k * components + 2]; \
260                                 if(components == 4) out_row[k * components + 3] = in_row[k * components + 3]; \
261                         } \
262                         for(int k = x2; k < w; k++) \
263                         { \
264                                 out_row[k * components + 0] = in_row[k * components + 0]; \
265                                 out_row[k * components + 1] = in_row[k * components + 1]; \
266                                 out_row[k * components + 2] = in_row[k * components + 2]; \
267                                 if(components == 4) out_row[k * components + 3] = in_row[k * components + 3]; \
268                         } \
269                 } \
270                 for(int j = y2; j < h; j++) \
271                 { \
272                         type *in_row = (type*)incoming->get_rows()[j]; \
273                         type *out_row = (type*)outgoing->get_rows()[j]; \
274  \
275                         for(int k = 0; k < w; k++) \
276                         { \
277                                 out_row[k * components + 0] = in_row[k * components + 0]; \
278                                 out_row[k * components + 1] = in_row[k * components + 1]; \
279                                 out_row[k * components + 2] = in_row[k * components + 2]; \
280                                 if(components == 4) out_row[k * components + 3] = in_row[k * components + 3]; \
281                         } \
282                 } \
283         } \
284 }
285
286
287
288
289
290 int IrisSquareMain::process_realtime(VFrame *incoming, VFrame *outgoing)
291 {
292         load_configuration();
293
294         int w = incoming->get_w();
295         int h = incoming->get_h();
296
297
298         switch(incoming->get_color_model())
299         {
300                 case BC_RGB_FLOAT:
301                         IRISSQUARE(float, 3);
302                         break;
303                 case BC_RGB888:
304                 case BC_YUV888:
305                         IRISSQUARE(unsigned char, 3)
306                         break;
307                 case BC_RGBA_FLOAT:
308                         IRISSQUARE(float, 4);
309                         break;
310                 case BC_RGBA8888:
311                 case BC_YUVA8888:
312                         IRISSQUARE(unsigned char, 4)
313                         break;
314                 case BC_RGB161616:
315                 case BC_YUV161616:
316                         IRISSQUARE(uint16_t, 3)
317                         break;
318                 case BC_RGBA16161616:
319                 case BC_YUVA16161616:
320                         IRISSQUARE(uint16_t, 4)
321                         break;
322         }
323         return 0;
324 }