edl plugin names eng, fix segv for opengl brender, renderfarm rework strategy, perf...
[goodguy/history.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         320,
96         50,
97         320,
98         50,
99         0)
100 {
101         this->plugin = plugin;
102 }
103
104
105 void IrisSquareWindow::create_objects()
106 {
107         int x = 10, y = 10;
108         add_subwindow(new BC_Title(x, y, _("Direction:")));
109         x += 100;
110         add_subwindow(in = new IrisSquareIn(plugin,
111                 this,
112                 x,
113                 y));
114         x += 100;
115         add_subwindow(out = new IrisSquareOut(plugin,
116                 this,
117                 x,
118                 y));
119         show_window();
120         flush();
121 }
122
123
124
125
126
127
128
129
130
131
132 IrisSquareMain::IrisSquareMain(PluginServer *server)
133  : PluginVClient(server)
134 {
135         direction = 0;
136
137 }
138
139 IrisSquareMain::~IrisSquareMain()
140 {
141
142 }
143
144 const char* IrisSquareMain::plugin_title() { return N_("IrisSquare"); }
145 int IrisSquareMain::is_video() { return 1; }
146 int IrisSquareMain::is_transition() { return 1; }
147 int IrisSquareMain::uses_gui() { return 1; }
148
149 NEW_WINDOW_MACRO(IrisSquareMain, IrisSquareWindow)
150
151
152 void IrisSquareMain::save_data(KeyFrame *keyframe)
153 {
154         FileXML output;
155         output.set_shared_output(keyframe->get_data(), MESSAGESIZE);
156         output.tag.set_title("IRISSQUARE");
157         output.tag.set_property("DIRECTION", direction);
158         output.append_tag();
159         output.tag.set_title("/IRISSQUARE");
160         output.append_tag();
161         output.append_newline();
162         output.terminate_string();
163 }
164
165 void IrisSquareMain::read_data(KeyFrame *keyframe)
166 {
167         FileXML input;
168
169         input.set_shared_input(keyframe->get_data(), strlen(keyframe->get_data()));
170
171         while(!input.read_tag())
172         {
173                 if(input.tag.title_is("IRISSQUARE"))
174                 {
175                         direction = input.tag.get_property("DIRECTION", direction);
176                 }
177         }
178 }
179
180 int IrisSquareMain::load_configuration()
181 {
182         read_data(get_prev_keyframe(get_source_position()));
183         return 1;
184 }
185
186
187
188
189
190
191 #define IRISSQUARE(type, components) \
192 { \
193         if(direction == 0) \
194         { \
195                 int x1 = w / 2 - w / 2 *  \
196                         PluginClient::get_source_position() /  \
197                         PluginClient::get_total_len(); \
198                 int x2 = w / 2 + w / 2 *  \
199                         PluginClient::get_source_position() /  \
200                         PluginClient::get_total_len(); \
201                 int y1 = h / 2 - h / 2 *  \
202                         PluginClient::get_source_position() /  \
203                         PluginClient::get_total_len(); \
204                 int y2 = h / 2 + h / 2 *  \
205                         PluginClient::get_source_position() /  \
206                         PluginClient::get_total_len(); \
207                 for(int j = y1; j < y2; j++) \
208                 { \
209                         type *in_row = (type*)incoming->get_rows()[j]; \
210                         type *out_row = (type*)outgoing->get_rows()[j]; \
211  \
212                         for(int k = x1; k < x2; k++) \
213                         { \
214                                 out_row[k * components + 0] = in_row[k * components + 0]; \
215                                 out_row[k * components + 1] = in_row[k * components + 1]; \
216                                 out_row[k * components + 2] = in_row[k * components + 2]; \
217                                 if(components == 4) out_row[k * components + 3] = in_row[k * components + 3]; \
218                         } \
219                 } \
220         } \
221         else \
222         { \
223                 int x1 = w / 2 *  \
224                         PluginClient::get_source_position() /  \
225                         PluginClient::get_total_len(); \
226                 int x2 = w - w / 2 *  \
227                         PluginClient::get_source_position() /  \
228                         PluginClient::get_total_len(); \
229                 int y1 = h / 2 *  \
230                         PluginClient::get_source_position() /  \
231                         PluginClient::get_total_len(); \
232                 int y2 = h - h / 2 *  \
233                         PluginClient::get_source_position() /  \
234                         PluginClient::get_total_len(); \
235                 for(int j = 0; j < y1; j++) \
236                 { \
237                         type *in_row = (type*)incoming->get_rows()[j]; \
238                         type *out_row = (type*)outgoing->get_rows()[j]; \
239  \
240                         for(int k = 0; k < w; k++) \
241                         { \
242                                 out_row[k * components + 0] = in_row[k * components + 0]; \
243                                 out_row[k * components + 1] = in_row[k * components + 1]; \
244                                 out_row[k * components + 2] = in_row[k * components + 2]; \
245                                 if(components == 4) out_row[k * components + 3] = in_row[k * components + 3]; \
246                         } \
247                 } \
248                 for(int j = y1; j < y2; j++) \
249                 { \
250                         type *in_row = (type*)incoming->get_rows()[j]; \
251                         type *out_row = (type*)outgoing->get_rows()[j]; \
252  \
253                         for(int k = 0; k < x1; k++) \
254                         { \
255                                 out_row[k * components + 0] = in_row[k * components + 0]; \
256                                 out_row[k * components + 1] = in_row[k * components + 1]; \
257                                 out_row[k * components + 2] = in_row[k * components + 2]; \
258                                 if(components == 4) out_row[k * components + 3] = in_row[k * components + 3]; \
259                         } \
260                         for(int k = x2; k < w; k++) \
261                         { \
262                                 out_row[k * components + 0] = in_row[k * components + 0]; \
263                                 out_row[k * components + 1] = in_row[k * components + 1]; \
264                                 out_row[k * components + 2] = in_row[k * components + 2]; \
265                                 if(components == 4) out_row[k * components + 3] = in_row[k * components + 3]; \
266                         } \
267                 } \
268                 for(int j = y2; j < h; j++) \
269                 { \
270                         type *in_row = (type*)incoming->get_rows()[j]; \
271                         type *out_row = (type*)outgoing->get_rows()[j]; \
272  \
273                         for(int k = 0; k < w; k++) \
274                         { \
275                                 out_row[k * components + 0] = in_row[k * components + 0]; \
276                                 out_row[k * components + 1] = in_row[k * components + 1]; \
277                                 out_row[k * components + 2] = in_row[k * components + 2]; \
278                                 if(components == 4) out_row[k * components + 3] = in_row[k * components + 3]; \
279                         } \
280                 } \
281         } \
282 }
283
284
285
286
287
288 int IrisSquareMain::process_realtime(VFrame *incoming, VFrame *outgoing)
289 {
290         load_configuration();
291
292         int w = incoming->get_w();
293         int h = incoming->get_h();
294
295
296         switch(incoming->get_color_model())
297         {
298                 case BC_RGB_FLOAT:
299                         IRISSQUARE(float, 3);
300                         break;
301                 case BC_RGB888:
302                 case BC_YUV888:
303                         IRISSQUARE(unsigned char, 3)
304                         break;
305                 case BC_RGBA_FLOAT:
306                         IRISSQUARE(float, 4);
307                         break;
308                 case BC_RGBA8888:
309                 case BC_YUVA8888:
310                         IRISSQUARE(unsigned char, 4)
311                         break;
312                 case BC_RGB161616:
313                 case BC_YUV161616:
314                         IRISSQUARE(uint16_t, 3)
315                         break;
316                 case BC_RGBA16161616:
317                 case BC_YUVA16161616:
318                         IRISSQUARE(uint16_t, 4)
319                         break;
320         }
321         return 0;
322 }