Merge CV, ver=5.1; ops/methods from HV, and interface from CV where possible
[goodguy/history.git] / cinelerra-5.1 / plugins / reframe / reframe.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 "language.h"
25 #include "mainprogress.h"
26 #include "reframe.h"
27
28
29
30
31
32 REGISTER_PLUGIN(ReFrame)
33
34
35
36
37
38
39
40
41
42
43 ReFrame::ReFrame(PluginServer *server)
44  : PluginVClient(server)
45 {
46         current_position = 0;
47 }
48
49 ReFrame::~ReFrame()
50 {
51 }
52
53 const char* ReFrame::plugin_title() { return _("Reframe"); }
54
55
56
57 int ReFrame::load_defaults()
58 {
59         char directory[1024];
60
61 // set the default directory
62         sprintf(directory, "%sreframe.rc", BCASTDIR);
63
64 // load the defaults
65
66         defaults = new BC_Hash(directory);
67
68         defaults->load();
69
70         scale = defaults->get("SCALE", (double)1);
71         return 0;
72 }
73
74 int ReFrame::save_defaults()
75 {
76         defaults->update("SCALE", scale);
77         defaults->save();
78         return 0;
79 }
80
81 int ReFrame::get_parameters()
82 {
83         BC_DisplayInfo info;
84         ReFrameWindow window(this, info.get_abs_cursor_x(), info.get_abs_cursor_y());
85         window.create_objects();
86         int result = window.run_window();
87         
88         return result;
89 }
90
91
92 int ReFrame::start_loop()
93 {
94         if(PluginClient::interactive)
95         {
96                 char string[BCTEXTLEN];
97                 sprintf(string, "%s...", plugin_title());
98                 progress = start_progress(string, 
99                         (PluginClient::end - PluginClient::start));
100         }
101
102         current_position = 0;
103         return 0;
104 }
105
106 int ReFrame::stop_loop()
107 {
108         if(PluginClient::interactive)
109         {
110                 progress->stop_progress();
111                 delete progress;
112         }
113         return 0;
114 }
115
116
117 int ReFrame::process_loop(VFrame *buffer)
118 {
119         int result = 0;
120         
121         int64_t input_offset = Units::to_int64((double)current_position * 
122                 scale + 
123                 PluginClient::start);
124
125         read_frame(buffer, input_offset);
126
127         current_position++;
128         input_offset = Units::to_int64((double)current_position * 
129                 scale + 
130                 PluginClient::start);
131
132         if(PluginClient::interactive) 
133                 result = progress->update(input_offset - PluginClient::start);
134
135         if(input_offset >= PluginClient::end) result = 1;
136
137         return result;
138 }
139
140
141
142
143
144
145
146
147
148
149
150
151 ReFrameOutput::ReFrameOutput(ReFrame *plugin, int x, int y)
152  : BC_TextBox(x, y, 150, 1, (float)plugin->scale)
153 {
154         this->plugin = plugin;
155 }
156
157 int ReFrameOutput::handle_event()
158 {
159         plugin->scale = atof(get_text());
160         return 1;
161 }
162
163
164
165 ReFrameWindow::ReFrameWindow(ReFrame *plugin, int x, int y)
166  : BC_Window(plugin->plugin_title(), 
167         x, 
168         y, 
169         230, 
170         160, 
171         230, 
172         160, 
173         0, 
174         0,
175         1)
176 {
177         this->plugin = plugin;
178 }
179
180 ReFrameWindow::~ReFrameWindow()
181 {
182 }
183
184
185 void ReFrameWindow::create_objects()
186 {
187         int x = 10, y = 10;
188         lock_window("ReFrameWindow::create_objects");
189         add_subwindow(new BC_Title(x, y, _("Scale factor:")));
190         y += 20;
191         add_subwindow(new ReFrameOutput(plugin, x, y));
192         add_subwindow(new BC_OKButton(this));
193         add_subwindow(new BC_CancelButton(this));
194         show_window();
195         unlock_window();
196 }
197
198 int ReFrameWindow::close_event()
199 {
200         set_done(0);
201         return 1;
202 }
203
204