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 int color_model = frame->get_color_model();
137 int need_alpha = BC_CModels::has_alpha(color_model);
139 read_frame(frame, 0, start_position,
140 frame_rate, get_use_opengl());
142 int w = frame->get_w();
143 int h = frame->get_h();
146 #define MAIN_LOOP(type, components, is_yuv, max) do { \
147 if( components == 4 ) { \
148 for( int y=0; y<h; ++y ) { \
149 type *row = (type*)frame->get_rows()[y]; \
150 for( int x=0; x<w; ++x ) { \
156 else if( is_yuv ) { \
157 type ofs = (max+1)/2; \
158 for( int y=0; y<h; ++y ) { \
159 type *row = (type*)frame->get_rows()[y]; \
160 for( int x=0; x<w; ++x ) { \
161 row[0] = row[0] * a; \
162 row[1] = (row[1]-ofs) * a + ofs; \
163 row[2] = (row[2]-ofs) * a + ofs; \
169 for( int y=0; y<h; ++y ) { \
170 type *row = (type*)frame->get_rows()[y]; \
171 for( int x=0; x<w; ++x ) { \
182 switch( frame->get_color_model() ) {
183 case BC_RGB888: MAIN_LOOP(uint8_t, 3, 0, 0xff); break;
184 case BC_RGB_FLOAT: MAIN_LOOP(float, 3, 0, 1.0 ); break;
185 case BC_YUV888: MAIN_LOOP(uint8_t, 3, 1, 0xff); break;
186 case BC_RGBA8888: MAIN_LOOP(uint8_t, 4, 0, 0xff); break;
187 case BC_RGBA_FLOAT: MAIN_LOOP(float, 4, 0, 1.0 ); break;
188 case BC_YUVA8888: MAIN_LOOP(uint8_t, 4, 1, 0xff); break;
195 void AlphaMain::update_gui()
197 if( !thread ) return;
198 AlphaWindow *window = (AlphaWindow*)thread->window;
199 if( !window ) return;
200 if( !load_configuration() ) return;
201 window->lock_window("AlphaMain::update_gui");
203 window->unlock_window();
207 void AlphaMain::save_data(KeyFrame *keyframe)
210 output.set_shared_output(keyframe->xbuf);
211 output.tag.set_title("ALPHA");
212 output.tag.set_property("A", config.a);
214 output.terminate_string();
217 void AlphaMain::read_data(KeyFrame *keyframe)
220 input.set_shared_input(keyframe->xbuf);
223 while( !(result = input.read_tag()) ) {
224 if( input.tag.title_is("ALPHA") ) {
225 config.a = input.tag.get_property("A", config.a);