Fixed initialisation of tf in file_open(). Without setting the memory to 0,
[cinelerra_cv/mob.git] / plugins / irissquare / irissquare.C
blob960bbc97f72214173d0a8654b084e8bc07e00827
1 #include "bcdisplayinfo.h"
2 #include "bchash.h"
3 #include "edl.inc"
4 #include "filexml.h"
5 #include "language.h"
6 #include "overlayframe.h"
7 #include "picon_png.h"
8 #include "vframe.h"
9 #include "irissquare.h"
12 #include <stdint.h>
13 #include <string.h>
16 REGISTER_PLUGIN(IrisSquareMain)
22 IrisSquareIn::IrisSquareIn(IrisSquareMain *plugin, 
23         IrisSquareWindow *window,
24         int x,
25         int y)
26  : BC_Radial(x, 
27                 y, 
28                 plugin->direction == 0, 
29                 _("In"))
31         this->plugin = plugin;
32         this->window = window;
35 int IrisSquareIn::handle_event()
37         update(1);
38         plugin->direction = 0;
39         window->out->update(0);
40         plugin->send_configure_change();
41         return 0;
44 IrisSquareOut::IrisSquareOut(IrisSquareMain *plugin, 
45         IrisSquareWindow *window,
46         int x,
47         int y)
48  : BC_Radial(x, 
49                 y, 
50                 plugin->direction == 1, 
51                 _("Out"))
53         this->plugin = plugin;
54         this->window = window;
57 int IrisSquareOut::handle_event()
59         update(1);
60         plugin->direction = 1;
61         window->in->update(0);
62         plugin->send_configure_change();
63         return 0;
73 IrisSquareWindow::IrisSquareWindow(IrisSquareMain *plugin, int x, int y)
74  : BC_Window(plugin->gui_string, 
75         x, 
76         y, 
77         320, 
78         50, 
79         320, 
80         50, 
81         0, 
82         0,
83         1)
85         this->plugin = plugin;
89 int IrisSquareWindow::close_event()
91         set_done(1);
92         return 1;
95 void IrisSquareWindow::create_objects()
97         int x = 10, y = 10;
98         add_subwindow(new BC_Title(x, y, _("Direction:")));
99         x += 100;
100         add_subwindow(in = new IrisSquareIn(plugin, 
101                 this,
102                 x,
103                 y));
104         x += 100;
105         add_subwindow(out = new IrisSquareOut(plugin, 
106                 this,
107                 x,
108                 y));
109         show_window();
110         flush();
116 PLUGIN_THREAD_OBJECT(IrisSquareMain, IrisSquareThread, IrisSquareWindow)
123 IrisSquareMain::IrisSquareMain(PluginServer *server)
124  : PluginVClient(server)
126         direction = 0;
127         PLUGIN_CONSTRUCTOR_MACRO
130 IrisSquareMain::~IrisSquareMain()
132         PLUGIN_DESTRUCTOR_MACRO
135 char* IrisSquareMain::plugin_title() { return N_("IrisSquare"); }
136 int IrisSquareMain::is_video() { return 1; }
137 int IrisSquareMain::is_transition() { return 1; }
138 int IrisSquareMain::uses_gui() { return 1; }
140 SHOW_GUI_MACRO(IrisSquareMain, IrisSquareThread);
141 SET_STRING_MACRO(IrisSquareMain)
142 RAISE_WINDOW_MACRO(IrisSquareMain)
145 VFrame* IrisSquareMain::new_picon()
147         return new VFrame(picon_png);
150 int IrisSquareMain::load_defaults()
152         char directory[BCTEXTLEN];
153 // set the default directory
154         sprintf(directory, "%sirissquare.rc", BCASTDIR);
156 // load the defaults
157         defaults = new BC_Hash(directory);
158         defaults->load();
160         direction = defaults->get("DIRECTION", direction);
161         return 0;
164 int IrisSquareMain::save_defaults()
166         defaults->update("DIRECTION", direction);
167         defaults->save();
168         return 0;
171 void IrisSquareMain::save_data(KeyFrame *keyframe)
173         FileXML output;
174         output.set_shared_string(keyframe->data, MESSAGESIZE);
175         output.tag.set_title("IRISSQUARE");
176         output.tag.set_property("DIRECTION", direction);
177         output.append_tag();
178         output.terminate_string();
181 void IrisSquareMain::read_data(KeyFrame *keyframe)
183         FileXML input;
185         input.set_shared_string(keyframe->data, strlen(keyframe->data));
187         while(!input.read_tag())
188         {
189                 if(input.tag.title_is("IRISSQUARE"))
190                 {
191                         direction = input.tag.get_property("DIRECTION", direction);
192                 }
193         }
196 void IrisSquareMain::load_configuration()
198         read_data(get_prev_keyframe(get_source_position()));
206 #define IRISSQUARE(type, components) \
207 { \
208         if(direction == 0) \
209         { \
210                 int x1 = w / 2 - w / 2 *  \
211                         PluginClient::get_source_position() /  \
212                         PluginClient::get_total_len(); \
213                 int x2 = w / 2 + w / 2 *  \
214                         PluginClient::get_source_position() /  \
215                         PluginClient::get_total_len(); \
216                 int y1 = h / 2 - h / 2 *  \
217                         PluginClient::get_source_position() /  \
218                         PluginClient::get_total_len(); \
219                 int y2 = h / 2 + h / 2 *  \
220                         PluginClient::get_source_position() /  \
221                         PluginClient::get_total_len(); \
222                 for(int j = y1; j < y2; j++) \
223                 { \
224                         type *in_row = (type*)incoming->get_rows()[j]; \
225                         type *out_row = (type*)outgoing->get_rows()[j]; \
227                         for(int k = x1; k < x2; k++) \
228                         { \
229                                 out_row[k * components + 0] = in_row[k * components + 0]; \
230                                 out_row[k * components + 1] = in_row[k * components + 1]; \
231                                 out_row[k * components + 2] = in_row[k * components + 2]; \
232                                 if(components == 4) out_row[k * components + 3] = in_row[k * components + 3]; \
233                         } \
234                 } \
235         } \
236         else \
237         { \
238                 int x1 = w / 2 *  \
239                         PluginClient::get_source_position() /  \
240                         PluginClient::get_total_len(); \
241                 int x2 = w - w / 2 *  \
242                         PluginClient::get_source_position() /  \
243                         PluginClient::get_total_len(); \
244                 int y1 = h / 2 *  \
245                         PluginClient::get_source_position() /  \
246                         PluginClient::get_total_len(); \
247                 int y2 = h - h / 2 *  \
248                         PluginClient::get_source_position() /  \
249                         PluginClient::get_total_len(); \
250                 for(int j = 0; j < y1; j++) \
251                 { \
252                         type *in_row = (type*)incoming->get_rows()[j]; \
253                         type *out_row = (type*)outgoing->get_rows()[j]; \
255                         for(int k = 0; k < w; 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                 } \
263                 for(int j = y1; j < y2; j++) \
264                 { \
265                         type *in_row = (type*)incoming->get_rows()[j]; \
266                         type *out_row = (type*)outgoing->get_rows()[j]; \
268                         for(int k = 0; k < x1; k++) \
269                         { \
270                                 out_row[k * components + 0] = in_row[k * components + 0]; \
271                                 out_row[k * components + 1] = in_row[k * components + 1]; \
272                                 out_row[k * components + 2] = in_row[k * components + 2]; \
273                                 if(components == 4) out_row[k * components + 3] = in_row[k * components + 3]; \
274                         } \
275                         for(int k = x2; 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                 for(int j = y2; j < h; j++) \
284                 { \
285                         type *in_row = (type*)incoming->get_rows()[j]; \
286                         type *out_row = (type*)outgoing->get_rows()[j]; \
288                         for(int k = 0; k < w; k++) \
289                         { \
290                                 out_row[k * components + 0] = in_row[k * components + 0]; \
291                                 out_row[k * components + 1] = in_row[k * components + 1]; \
292                                 out_row[k * components + 2] = in_row[k * components + 2]; \
293                                 if(components == 4) out_row[k * components + 3] = in_row[k * components + 3]; \
294                         } \
295                 } \
296         } \
303 int IrisSquareMain::process_realtime(VFrame *incoming, VFrame *outgoing)
305         load_configuration();
307         int w = incoming->get_w();
308         int h = incoming->get_h();
311         switch(incoming->get_color_model())
312         {
313                 case BC_RGB_FLOAT:
314                         IRISSQUARE(float, 3);
315                         break;
316                 case BC_RGB888:
317                 case BC_YUV888:
318                         IRISSQUARE(unsigned char, 3)
319                         break;
320                 case BC_RGBA_FLOAT:
321                         IRISSQUARE(float, 4);
322                         break;
323                 case BC_RGBA8888:
324                 case BC_YUVA8888:
325                         IRISSQUARE(unsigned char, 4)
326                         break;
327                 case BC_RGB161616:
328                 case BC_YUV161616:
329                         IRISSQUARE(uint16_t, 3)
330                         break;
331                 case BC_RGBA16161616:
332                 case BC_YUVA16161616:
333                         IRISSQUARE(uint16_t, 4)
334                         break;
335         }
336         return 0;