r105: This commit was manufactured by cvs2svn to create tag
[cinelerra_cv/mob.git] / hvirtual / plugins / freezeframe / freezeframe.C
blob681fa27558d9b7da462c54ec67cc74ae1b0f81d3
1 #include "bcdisplayinfo.h"
2 #include "defaults.h"
3 #include "filexml.h"
4 #include "freezeframe.h"
5 #include "picon_png.h"
9 #include <string.h>
11 #include <libintl.h>
12 #define _(String) gettext(String)
13 #define gettext_noop(String) String
14 #define N_(String) gettext_noop (String)
16 REGISTER_PLUGIN(FreezeFrameMain)
22 FreezeFrameConfig::FreezeFrameConfig()
24         enabled = 0;
25         line_double = 0;
28 void FreezeFrameConfig::copy_from(FreezeFrameConfig &that)
30         enabled = that.enabled;
31         line_double = that.line_double;
34 int FreezeFrameConfig::equivalent(FreezeFrameConfig &that)
36         return enabled == that.enabled &&
37                 line_double == that.line_double;
40 void FreezeFrameConfig::interpolate(FreezeFrameConfig &prev, 
41         FreezeFrameConfig &next, 
42         long prev_frame, 
43         long next_frame, 
44         long current_frame)
46         this->enabled = prev.enabled;
47         this->line_double = prev.line_double;
59 FreezeFrameWindow::FreezeFrameWindow(FreezeFrameMain *client, int x, int y)
60  : BC_Window(client->get_gui_string(),
61         x,
62         y,
63         200,
64         100,
65         200,
66         100,
67         0,
68         0,
69         1)
71         this->client = client; 
74 FreezeFrameWindow::~FreezeFrameWindow()
78 int FreezeFrameWindow::create_objects()
80         int x = 10, y = 10;
81         add_tool(enabled = new FreezeFrameToggle(client, 
82                 &client->config.enabled,
83                 x, 
84                 y,
85                 _("Enabled")));
86         y += 30;
87         add_tool(line_double = new FreezeFrameToggle(client, 
88                 &client->config.line_double,
89                 x, 
90                 y,
91                 _("Line double")));
92         show_window();
93         flush();
94         return 0;
97 WINDOW_CLOSE_EVENT(FreezeFrameWindow)
102 PLUGIN_THREAD_OBJECT(FreezeFrameMain, FreezeFrameThread, FreezeFrameWindow)
108 FreezeFrameToggle::FreezeFrameToggle(FreezeFrameMain *client, 
109         int *value, 
110         int x, 
111         int y,
112         char *text)
113  : BC_CheckBox(x, y, *value, text)
115         this->client = client;
116         this->value = value;
118 FreezeFrameToggle::~FreezeFrameToggle()
121 int FreezeFrameToggle::handle_event()
123         *value = get_value();
124         client->send_configure_change();
125         return 1;
139 FreezeFrameMain::FreezeFrameMain(PluginServer *server)
140  : PluginVClient(server)
142         PLUGIN_CONSTRUCTOR_MACRO
143         first_frame = 0;
146 FreezeFrameMain::~FreezeFrameMain()
148         PLUGIN_DESTRUCTOR_MACRO
149         if(first_frame) delete first_frame;
152 char* FreezeFrameMain::plugin_title() { return _("Freeze Frame"); }
154 int FreezeFrameMain::is_synthesis()
156         return 1;
159 int FreezeFrameMain::is_realtime() { return 1; }
161 SHOW_GUI_MACRO(FreezeFrameMain, FreezeFrameThread)
163 RAISE_WINDOW_MACRO(FreezeFrameMain)
165 SET_STRING_MACRO(FreezeFrameMain)
167 NEW_PICON_MACRO(FreezeFrameMain)
169 LOAD_CONFIGURATION_MACRO(FreezeFrameMain, FreezeFrameConfig)
171 void FreezeFrameMain::update_gui()
173         if(thread)
174         {
175                 load_configuration();
176                 thread->window->lock_window();
177                 thread->window->enabled->update(config.enabled);
178                 thread->window->line_double->update(config.line_double);
179                 thread->window->unlock_window();
180         }
183 void FreezeFrameMain::save_data(KeyFrame *keyframe)
185         FileXML output;
187 // cause data to be stored directly in text
188         output.set_shared_string(keyframe->data, MESSAGESIZE);
189         output.tag.set_title("FREEZEFRAME");
190         output.append_tag();
191         if(config.enabled)
192         {
193                 output.tag.set_title("ENABLED");
194                 output.append_tag();
195         }
196         if(config.line_double)
197         {
198                 output.tag.set_title("LINE_DOUBLE");
199                 output.append_tag();
200         }
201         output.terminate_string();
202 // data is now in *text
205 void FreezeFrameMain::read_data(KeyFrame *keyframe)
207         FileXML input;
209         input.set_shared_string(keyframe->data, strlen(keyframe->data));
211         int result = 0;
212         config.enabled = 0;
213         config.line_double = 0;
215         while(!result)
216         {
217                 result = input.read_tag();
219                 if(!result)
220                 {
221                         if(input.tag.title_is("ENABLED"))
222                         {
223                                 config.enabled = 1;
224                         }
225                         if(input.tag.title_is("LINE_DOUBLE"))
226                         {
227                                 config.line_double = 1;
228                         }
229                 }
230         }
233 int FreezeFrameMain::load_defaults()
235         char directory[BCTEXTLEN], string[BCTEXTLEN];
236 // set the default directory
237         sprintf(directory, "%sfreezeframe.rc", BCASTDIR);
239 // load the defaults
240         defaults = new Defaults(directory);
241         defaults->load();
243         config.enabled = defaults->get("ENABLED", config.enabled);
244         config.line_double = defaults->get("LINE_DOUBLE", config.line_double);
245         return 0;
248 int FreezeFrameMain::save_defaults()
250         defaults->update("ENABLED", config.enabled);
251         defaults->update("LINE_DOUBLE", config.line_double);
252         defaults->save();
253         return 0;
261 int FreezeFrameMain::process_realtime(VFrame *input_ptr, VFrame *output_ptr)
263         load_configuration();
264         KeyFrame *prev_keyframe;
265         int new_keyframe;
266         prev_keyframe = get_prev_keyframe(get_source_position());
267         new_keyframe = (prev_keyframe->position == get_source_position());
269         if(!first_frame && config.enabled || new_keyframe)
270         {
271                 if(!first_frame)
272                         first_frame = new VFrame(0, 
273                                 input_ptr->get_w(), 
274                                 input_ptr->get_h(),
275                                 input_ptr->get_color_model());
276                 first_frame->copy_from(input_ptr);
277                 output_ptr->copy_from(input_ptr);
278         }
279         else
280         if(!first_frame && !config.enabled)
281         {
282                 output_ptr->copy_from(input_ptr);
283         }
284         else
285         if(first_frame && !config.enabled)
286         {
287                 delete first_frame;
288                 first_frame = 0;
289                 output_ptr->copy_from(input_ptr);
290         }
291         else
292         if(first_frame && config.enabled)
293         {
294                 output_ptr->copy_from(first_frame);
295         }
298         if(config.line_double && config.enabled)
299         {
300                 for(int i = 0; i < output_ptr->get_h() - 1; i += 2)
301                 {
302                         memcpy(output_ptr->get_rows()[i + 1], 
303                                 output_ptr->get_rows()[i], 
304                                 output_ptr->get_bytes_per_line());
305                 }
306         }
310         return 0;