4 * Copyright (C) 2008 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
25 #include "overlayframe.h"
30 PluginClient* new_plugin(PluginServer *server)
32 return new DissolveMain(server);
39 DissolveMain::DissolveMain(PluginServer *server)
40 : PluginVClient(server)
45 DissolveMain::~DissolveMain()
50 const char* DissolveMain::plugin_title() { return _("Dissolve"); }
51 int DissolveMain::is_video() { return 1; }
52 int DissolveMain::is_transition() { return 1; }
53 int DissolveMain::uses_gui() { return 0; }
57 int DissolveMain::process_realtime(VFrame *incoming, VFrame *outgoing)
59 fade = (float)PluginClient::get_source_position() /
60 PluginClient::get_total_len();
70 if(!overlayer) overlayer = new OverlayFrame(get_project_smp() + 1);
73 // There is a problem when dissolving from a big picture to a small picture.
74 // In order to make it dissolve correctly, we have to manually decrese alpha of big picture.
75 switch (outgoing->get_color_model())
80 uint8_t** data_rows = (uint8_t **)outgoing->get_rows();
81 int w = outgoing->get_w();
82 int h = outgoing->get_h();
83 for(int i = 0; i < h; i++)
85 uint8_t* alpha_chan = data_rows[i] + 3;
86 for(int j = 0; j < w; j++)
88 *alpha_chan = (uint8_t) (*alpha_chan * (1-fade));
96 uint16_t** data_rows = (uint16_t **)outgoing->get_rows();
97 int w = outgoing->get_w();
98 int h = outgoing->get_h();
99 for(int i = 0; i < h; i++)
101 uint16_t* alpha_chan = data_rows[i] + 3; // 3 since this is uint16_t
102 for(int j = 0; j < w; j++)
104 *alpha_chan = (uint16_t)(*alpha_chan * (1-fade));
112 float** data_rows = (float **)outgoing->get_rows();
113 int w = outgoing->get_w();
114 int h = outgoing->get_h();
115 for(int i = 0; i < h; i++)
117 float* alpha_chan = data_rows[i] + 3; // 3 since this is floats
118 for(int j = 0; j < w; j++)
120 *alpha_chan = *alpha_chan * (1-fade);
121 alpha_chan += sizeof(float);
131 overlayer->overlay(outgoing,
148 int DissolveMain::handle_opengl()
152 // Read images from RAM
153 get_input()->to_texture();
154 get_output()->to_texture();
156 // Create output pbuffer
157 get_output()->enable_opengl();
159 VFrame::init_screen(get_output()->get_w(), get_output()->get_h());
161 // Enable output texture
162 get_output()->bind_texture(0);
163 // Draw output texture
165 glColor4f(1, 1, 1, 1);
166 get_output()->draw_texture();
168 // Draw input texture
169 get_input()->bind_texture(0);
171 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
172 glColor4f(1, 1, 1, fade);
173 get_input()->draw_texture();
177 get_output()->set_opengl_state(VFrame::SCREEN);