4 * Copyright (C) 2008-2019 Adam Williams <broadcast at earthling dot net>
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.
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.
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
31 REGISTER_PLUGIN(AlphaMain)
34 AlphaConfig::AlphaConfig()
39 int AlphaConfig::equivalent(AlphaConfig &that)
44 void AlphaConfig::copy_from(AlphaConfig &that)
49 void AlphaConfig::interpolate(AlphaConfig &prev, AlphaConfig &next,
50 long prev_frame, long next_frame, long current_frame)
52 double next_scale = (double)(current_frame - prev_frame) / (next_frame - prev_frame);
53 double prev_scale = (double)(next_frame - current_frame) / (next_frame - prev_frame);
55 a = (prev.a * prev_scale + next.a * next_scale);
59 AlphaSlider::AlphaSlider(AlphaWindow *window, AlphaMain *plugin,
61 : BC_FSlider(x, y, 0, w, w, 0.f, 1.f, plugin->config.a)
63 this->window = window;
64 this->plugin = plugin;
67 AlphaSlider::~AlphaSlider()
71 int AlphaSlider::handle_event()
73 plugin->config.a = get_value();
74 plugin->send_configure_change();
78 #define ALPHA_W xS(400)
79 #define ALPHA_H yS(60)
81 AlphaWindow::AlphaWindow(AlphaMain *plugin)
82 : PluginClientWindow(plugin, ALPHA_W, ALPHA_H, ALPHA_W, ALPHA_H, 0)
84 this->plugin = plugin;
87 AlphaWindow::~AlphaWindow()
91 void AlphaWindow::create_objects()
93 int x = xS(10), y = yS(10);
95 add_subwindow(title = new BC_Title(x, y, _("Alpha:")));
96 y += title->get_h() + yS(5);
97 add_subwindow(alpha_slider = new AlphaSlider(this, plugin, x, y, xS(380)));
101 void AlphaWindow::update()
103 float alpha = plugin->config.a;
104 alpha_slider->update(alpha);
108 AlphaMain::AlphaMain(PluginServer *server)
109 : PluginVClient(server)
113 AlphaMain::~AlphaMain()
117 const char* AlphaMain::plugin_title() { return N_("Alpha"); }
118 int AlphaMain::is_realtime() { return 1; }
120 NEW_WINDOW_MACRO(AlphaMain, AlphaWindow)
122 LOAD_CONFIGURATION_MACRO(AlphaMain, AlphaConfig)
124 int AlphaMain::is_synthesis()
130 int AlphaMain::process_buffer(VFrame *frame,
131 int64_t start_position,
134 load_configuration();
136 read_frame(frame, 0, start_position, frame_rate, get_use_opengl());
137 int w = frame->get_w(), h = frame->get_h();
139 #define MAIN_LOOP(type, components, is_yuv, max) do { \
140 if( components == 4 ) { \
141 for( int y=0; y<h; ++y ) { \
142 type *row = (type*)frame->get_rows()[y]; \
143 for( int x=0; x<w; ++x ) { \
149 else if( is_yuv ) { \
150 type ofs = (max+1)/2; \
151 for( int y=0; y<h; ++y ) { \
152 type *row = (type*)frame->get_rows()[y]; \
153 for( int x=0; x<w; ++x ) { \
154 row[0] = row[0] * a; \
155 row[1] = (row[1]-ofs) * a + ofs; \
156 row[2] = (row[2]-ofs) * a + ofs; \
162 for( int y=0; y<h; ++y ) { \
163 type *row = (type*)frame->get_rows()[y]; \
164 for( int x=0; x<w; ++x ) { \
175 switch( frame->get_color_model() ) {
176 case BC_RGB888: MAIN_LOOP(uint8_t, 3, 0, 0xff); break;
177 case BC_RGB_FLOAT: MAIN_LOOP(float, 3, 0, 1.0 ); break;
178 case BC_YUV888: MAIN_LOOP(uint8_t, 3, 1, 0xff); break;
179 case BC_RGBA8888: MAIN_LOOP(uint8_t, 4, 0, 0xff); break;
180 case BC_RGBA_FLOAT: MAIN_LOOP(float, 4, 0, 1.0 ); break;
181 case BC_YUVA8888: MAIN_LOOP(uint8_t, 4, 1, 0xff); break;
188 void AlphaMain::update_gui()
190 if( !thread ) return;
191 AlphaWindow *window = (AlphaWindow*)thread->window;
192 if( !window ) return;
193 if( !load_configuration() ) return;
194 window->lock_window("AlphaMain::update_gui");
196 window->unlock_window();
200 void AlphaMain::save_data(KeyFrame *keyframe)
203 output.set_shared_output(keyframe->xbuf);
204 output.tag.set_title("ALPHA");
205 output.tag.set_property("A", config.a);
207 output.terminate_string();
210 void AlphaMain::read_data(KeyFrame *keyframe)
213 input.set_shared_input(keyframe->xbuf);
216 while( !(result = input.read_tag()) ) {
217 if( input.tag.title_is("ALPHA") ) {
218 config.a = input.tag.get_property("A", config.a);