c7c0911c017641dd7a5af18a6e6eb021e4a3bac7
[goodguy/history.git] / cinelerra-5.0 / 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 _("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.terminate_string();
160 }
161
162 void IrisSquareMain::read_data(KeyFrame *keyframe)
163 {
164         FileXML input;
165
166         input.set_shared_input(keyframe->get_data(), strlen(keyframe->get_data()));
167
168         while(!input.read_tag())
169         {
170                 if(input.tag.title_is("IRISSQUARE"))
171                 {
172                         direction = input.tag.get_property("DIRECTION", direction);
173                 }
174         }
175 }
176
177 int IrisSquareMain::load_configuration()
178 {
179         read_data(get_prev_keyframe(get_source_position()));
180         return 1;
181 }
182
183
184
185
186
187
188 #define IRISSQUARE(type, components) \
189 { \
190         if(direction == 0) \
191         { \
192                 int x1 = w / 2 - w / 2 *  \
193                         PluginClient::get_source_position() /  \
194                         PluginClient::get_total_len(); \
195                 int x2 = w / 2 + w / 2 *  \
196                         PluginClient::get_source_position() /  \
197                         PluginClient::get_total_len(); \
198                 int y1 = h / 2 - h / 2 *  \
199                         PluginClient::get_source_position() /  \
200                         PluginClient::get_total_len(); \
201                 int y2 = h / 2 + h / 2 *  \
202                         PluginClient::get_source_position() /  \
203                         PluginClient::get_total_len(); \
204                 for(int j = y1; j < y2; j++) \
205                 { \
206                         type *in_row = (type*)incoming->get_rows()[j]; \
207                         type *out_row = (type*)outgoing->get_rows()[j]; \
208  \
209                         for(int k = x1; k < x2; k++) \
210                         { \
211                                 out_row[k * components + 0] = in_row[k * components + 0]; \
212                                 out_row[k * components + 1] = in_row[k * components + 1]; \
213                                 out_row[k * components + 2] = in_row[k * components + 2]; \
214                                 if(components == 4) out_row[k * components + 3] = in_row[k * components + 3]; \
215                         } \
216                 } \
217         } \
218         else \
219         { \
220                 int x1 = w / 2 *  \
221                         PluginClient::get_source_position() /  \
222                         PluginClient::get_total_len(); \
223                 int x2 = w - w / 2 *  \
224                         PluginClient::get_source_position() /  \
225                         PluginClient::get_total_len(); \
226                 int y1 = h / 2 *  \
227                         PluginClient::get_source_position() /  \
228                         PluginClient::get_total_len(); \
229                 int y2 = h - h / 2 *  \
230                         PluginClient::get_source_position() /  \
231                         PluginClient::get_total_len(); \
232                 for(int j = 0; j < y1; j++) \
233                 { \
234                         type *in_row = (type*)incoming->get_rows()[j]; \
235                         type *out_row = (type*)outgoing->get_rows()[j]; \
236  \
237                         for(int k = 0; k < w; k++) \
238                         { \
239                                 out_row[k * components + 0] = in_row[k * components + 0]; \
240                                 out_row[k * components + 1] = in_row[k * components + 1]; \
241                                 out_row[k * components + 2] = in_row[k * components + 2]; \
242                                 if(components == 4) out_row[k * components + 3] = in_row[k * components + 3]; \
243                         } \
244                 } \
245                 for(int j = y1; j < y2; j++) \
246                 { \
247                         type *in_row = (type*)incoming->get_rows()[j]; \
248                         type *out_row = (type*)outgoing->get_rows()[j]; \
249  \
250                         for(int k = 0; k < x1; k++) \
251                         { \
252                                 out_row[k * components + 0] = in_row[k * components + 0]; \
253                                 out_row[k * components + 1] = in_row[k * components + 1]; \
254                                 out_row[k * components + 2] = in_row[k * components + 2]; \
255                                 if(components == 4) out_row[k * components + 3] = in_row[k * components + 3]; \
256                         } \
257                         for(int k = x2; k < w; k++) \
258                         { \
259                                 out_row[k * components + 0] = in_row[k * components + 0]; \
260                                 out_row[k * components + 1] = in_row[k * components + 1]; \
261                                 out_row[k * components + 2] = in_row[k * components + 2]; \
262                                 if(components == 4) out_row[k * components + 3] = in_row[k * components + 3]; \
263                         } \
264                 } \
265                 for(int j = y2; j < h; j++) \
266                 { \
267                         type *in_row = (type*)incoming->get_rows()[j]; \
268                         type *out_row = (type*)outgoing->get_rows()[j]; \
269  \
270                         for(int k = 0; k < w; k++) \
271                         { \
272                                 out_row[k * components + 0] = in_row[k * components + 0]; \
273                                 out_row[k * components + 1] = in_row[k * components + 1]; \
274                                 out_row[k * components + 2] = in_row[k * components + 2]; \
275                                 if(components == 4) out_row[k * components + 3] = in_row[k * components + 3]; \
276                         } \
277                 } \
278         } \
279 }
280
281
282
283
284
285 int IrisSquareMain::process_realtime(VFrame *incoming, VFrame *outgoing)
286 {
287         load_configuration();
288
289         int w = incoming->get_w();
290         int h = incoming->get_h();
291
292
293         switch(incoming->get_color_model())
294         {
295                 case BC_RGB_FLOAT:
296                         IRISSQUARE(float, 3);
297                         break;
298                 case BC_RGB888:
299                 case BC_YUV888:
300                         IRISSQUARE(unsigned char, 3)
301                         break;
302                 case BC_RGBA_FLOAT:
303                         IRISSQUARE(float, 4);
304                         break;
305                 case BC_RGBA8888:
306                 case BC_YUVA8888:
307                         IRISSQUARE(unsigned char, 4)
308                         break;
309                 case BC_RGB161616:
310                 case BC_YUV161616:
311                         IRISSQUARE(uint16_t, 3)
312                         break;
313                 case BC_RGBA16161616:
314                 case BC_YUVA16161616:
315                         IRISSQUARE(uint16_t, 4)
316                         break;
317         }
318         return 0;
319 }