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