r105: This commit was manufactured by cvs2svn to create tag
[cinelerra_cv/mob.git] / hvirtual / plugins / irissquare / irissquare.C
blobb836ba136fbd0720041a3778f631365f3b66ed7c
1 #include "bcdisplayinfo.h"
2 #include "defaults.h"
3 #include "edl.inc"
4 #include "filexml.h"
5 #include "overlayframe.h"
6 #include "picon_png.h"
7 #include "vframe.h"
8 #include "irissquare.h"
11 #include <stdint.h>
12 #include <string.h>
14 #include <libintl.h>
15 #define _(String) gettext(String)
16 #define gettext_noop(String) String
17 #define N_(String) gettext_noop (String)
20 REGISTER_PLUGIN(IrisSquareMain)
26 IrisSquareIn::IrisSquareIn(IrisSquareMain *plugin, 
27         IrisSquareWindow *window,
28         int x,
29         int y)
30  : BC_Radial(x, 
31                 y, 
32                 plugin->direction == 0, 
33                 _("In"))
35         this->plugin = plugin;
36         this->window = window;
39 int IrisSquareIn::handle_event()
41         update(1);
42         plugin->direction = 0;
43         window->out->update(0);
44         plugin->send_configure_change();
45         return 0;
48 IrisSquareOut::IrisSquareOut(IrisSquareMain *plugin, 
49         IrisSquareWindow *window,
50         int x,
51         int y)
52  : BC_Radial(x, 
53                 y, 
54                 plugin->direction == 1, 
55                 _("Out"))
57         this->plugin = plugin;
58         this->window = window;
61 int IrisSquareOut::handle_event()
63         update(1);
64         plugin->direction = 1;
65         window->in->update(0);
66         plugin->send_configure_change();
67         return 0;
77 IrisSquareWindow::IrisSquareWindow(IrisSquareMain *plugin, int x, int y)
78  : BC_Window(plugin->gui_string, 
79         x, 
80         y, 
81         320, 
82         50, 
83         320, 
84         50, 
85         0, 
86         0,
87         1)
89         this->plugin = plugin;
93 int IrisSquareWindow::close_event()
95         set_done(1);
96         return 1;
99 void IrisSquareWindow::create_objects()
101         int x = 10, y = 10;
102         add_subwindow(new BC_Title(x, y, _("Direction:")));
103         x += 100;
104         add_subwindow(in = new IrisSquareIn(plugin, 
105                 this,
106                 x,
107                 y));
108         x += 100;
109         add_subwindow(out = new IrisSquareOut(plugin, 
110                 this,
111                 x,
112                 y));
113         show_window();
114         flush();
120 PLUGIN_THREAD_OBJECT(IrisSquareMain, IrisSquareThread, IrisSquareWindow)
127 IrisSquareMain::IrisSquareMain(PluginServer *server)
128  : PluginVClient(server)
130         direction = 0;
131         PLUGIN_CONSTRUCTOR_MACRO
134 IrisSquareMain::~IrisSquareMain()
136         PLUGIN_DESTRUCTOR_MACRO
139 char* IrisSquareMain::plugin_title() { return _("IrisSquare"); }
140 int IrisSquareMain::is_video() { return 1; }
141 int IrisSquareMain::is_transition() { return 1; }
142 int IrisSquareMain::uses_gui() { return 1; }
143 SHOW_GUI_MACRO(IrisSquareMain, IrisSquareThread);
144 SET_STRING_MACRO(IrisSquareMain)
145 RAISE_WINDOW_MACRO(IrisSquareMain)
148 VFrame* IrisSquareMain::new_picon()
150         return new VFrame(picon_png);
153 int IrisSquareMain::load_defaults()
155         char directory[BCTEXTLEN];
156 // set the default directory
157         sprintf(directory, "%sirissquare.rc", BCASTDIR);
159 // load the defaults
160         defaults = new Defaults(directory);
161         defaults->load();
163         direction = defaults->get("DIRECTION", direction);
164         return 0;
167 int IrisSquareMain::save_defaults()
169         defaults->update("DIRECTION", direction);
170         defaults->save();
171         return 0;
174 void IrisSquareMain::save_data(KeyFrame *keyframe)
176         FileXML output;
177         output.set_shared_string(keyframe->data, MESSAGESIZE);
178         output.tag.set_title("IRISSQUARE");
179         output.tag.set_property("DIRECTION", direction);
180         output.append_tag();
181         output.terminate_string();
184 void IrisSquareMain::read_data(KeyFrame *keyframe)
186         FileXML input;
188         input.set_shared_string(keyframe->data, strlen(keyframe->data));
190         while(!input.read_tag())
191         {
192                 if(input.tag.title_is("IRISSQUARE"))
193                 {
194                         direction = input.tag.get_property("DIRECTION", direction);
195                 }
196         }
199 void IrisSquareMain::load_configuration()
201         read_data(get_prev_keyframe(get_source_position()));
209 #define IRISSQUARE(type, components) \
210 { \
211         if(direction == 0) \
212         { \
213                 int x1 = w / 2 - w / 2 *  \
214                         PluginClient::get_source_position() /  \
215                         PluginClient::get_total_len(); \
216                 int x2 = w / 2 + w / 2 *  \
217                         PluginClient::get_source_position() /  \
218                         PluginClient::get_total_len(); \
219                 int y1 = h / 2 - h / 2 *  \
220                         PluginClient::get_source_position() /  \
221                         PluginClient::get_total_len(); \
222                 int y2 = h / 2 + h / 2 *  \
223                         PluginClient::get_source_position() /  \
224                         PluginClient::get_total_len(); \
225                 for(int j = y1; j < y2; j++) \
226                 { \
227                         type *in_row = (type*)incoming->get_rows()[j]; \
228                         type *out_row = (type*)outgoing->get_rows()[j]; \
230                         for(int k = x1; k < x2; k++) \
231                         { \
232                                 out_row[k * components + 0] = in_row[k * components + 0]; \
233                                 out_row[k * components + 1] = in_row[k * components + 1]; \
234                                 out_row[k * components + 2] = in_row[k * components + 2]; \
235                                 if(components == 4) out_row[k * components + 3] = in_row[k * components + 3]; \
236                         } \
237                 } \
238         } \
239         else \
240         { \
241                 int x1 = w / 2 *  \
242                         PluginClient::get_source_position() /  \
243                         PluginClient::get_total_len(); \
244                 int x2 = w - w / 2 *  \
245                         PluginClient::get_source_position() /  \
246                         PluginClient::get_total_len(); \
247                 int y1 = h / 2 *  \
248                         PluginClient::get_source_position() /  \
249                         PluginClient::get_total_len(); \
250                 int y2 = h - h / 2 *  \
251                         PluginClient::get_source_position() /  \
252                         PluginClient::get_total_len(); \
253                 for(int j = 0; j < y1; j++) \
254                 { \
255                         type *in_row = (type*)incoming->get_rows()[j]; \
256                         type *out_row = (type*)outgoing->get_rows()[j]; \
258                         for(int k = 0; k < w; k++) \
259                         { \
260                                 out_row[k * components + 0] = in_row[k * components + 0]; \
261                                 out_row[k * components + 1] = in_row[k * components + 1]; \
262                                 out_row[k * components + 2] = in_row[k * components + 2]; \
263                                 if(components == 4) out_row[k * components + 3] = in_row[k * components + 3]; \
264                         } \
265                 } \
266                 for(int j = y1; j < y2; j++) \
267                 { \
268                         type *in_row = (type*)incoming->get_rows()[j]; \
269                         type *out_row = (type*)outgoing->get_rows()[j]; \
271                         for(int k = 0; k < x1; k++) \
272                         { \
273                                 out_row[k * components + 0] = in_row[k * components + 0]; \
274                                 out_row[k * components + 1] = in_row[k * components + 1]; \
275                                 out_row[k * components + 2] = in_row[k * components + 2]; \
276                                 if(components == 4) out_row[k * components + 3] = in_row[k * components + 3]; \
277                         } \
278                         for(int k = x2; k < w; k++) \
279                         { \
280                                 out_row[k * components + 0] = in_row[k * components + 0]; \
281                                 out_row[k * components + 1] = in_row[k * components + 1]; \
282                                 out_row[k * components + 2] = in_row[k * components + 2]; \
283                                 if(components == 4) out_row[k * components + 3] = in_row[k * components + 3]; \
284                         } \
285                 } \
286                 for(int j = y2; j < h; j++) \
287                 { \
288                         type *in_row = (type*)incoming->get_rows()[j]; \
289                         type *out_row = (type*)outgoing->get_rows()[j]; \
291                         for(int k = 0; k < w; k++) \
292                         { \
293                                 out_row[k * components + 0] = in_row[k * components + 0]; \
294                                 out_row[k * components + 1] = in_row[k * components + 1]; \
295                                 out_row[k * components + 2] = in_row[k * components + 2]; \
296                                 if(components == 4) out_row[k * components + 3] = in_row[k * components + 3]; \
297                         } \
298                 } \
299         } \
306 int IrisSquareMain::process_realtime(VFrame *incoming, VFrame *outgoing)
308         load_configuration();
310         int w = incoming->get_w();
311         int h = incoming->get_h();
314         switch(incoming->get_color_model())
315         {
316                 case BC_RGB888:
317                 case BC_YUV888:
318                         IRISSQUARE(unsigned char, 3)
319                         break;
320                 case BC_RGBA8888:
321                 case BC_YUVA8888:
322                         IRISSQUARE(unsigned char, 4)
323                         break;
324                 case BC_RGB161616:
325                 case BC_YUV161616:
326                         IRISSQUARE(uint16_t, 3)
327                         break;
328                 case BC_RGBA16161616:
329                 case BC_YUVA16161616:
330                         IRISSQUARE(uint16_t, 4)
331                         break;
332         }
333         return 0;