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
24 #include "overlayframe.h"
30 REGISTER_PLUGIN(FlashMain)
36 FlashMain::FlashMain(PluginServer *server)
37 : PluginVClient(server)
41 FlashMain::~FlashMain()
45 const char* FlashMain::plugin_title() { return N_("Flash"); }
46 int FlashMain::is_video() { return 1; }
47 int FlashMain::is_transition() { return 1; }
48 int FlashMain::uses_gui() { return 0; }
52 #define FLASH(type, temp_type, components, max, chroma_offset) \
54 float round_factor = (sizeof(type) < 4) ? 0.5 : 0; \
55 temp_type foreground = (temp_type)(fraction * max + round_factor); \
56 temp_type chroma_foreground = foreground; \
57 if(chroma_offset) chroma_foreground = foreground * chroma_offset / max; \
58 temp_type transparency = max - foreground; \
60 for(int i = 0; i < h; i++) \
62 type *in_row = (type*)incoming->get_rows()[i]; \
63 type *out_row = (type*)outgoing->get_rows()[i]; \
66 for(int j = 0; j < w; j++) \
68 *out_row = foreground + transparency * *out_row / max; \
70 *out_row = chroma_foreground + transparency * *out_row / max; \
72 *out_row = chroma_foreground + transparency * *out_row / max; \
76 *out_row = foreground + transparency * *out_row / max; \
83 for(int j = 0; j < w; j++) \
85 *out_row = foreground + transparency * *in_row / max; \
88 *out_row = chroma_foreground + transparency * *in_row / max; \
91 *out_row = chroma_foreground + transparency * *in_row / max; \
96 *out_row = foreground + transparency * *in_row / max; \
105 int FlashMain::process_realtime(VFrame *incoming, VFrame *outgoing)
107 int half = PluginClient::get_total_len() / 2;
108 int position = half - labs(PluginClient::get_source_position() - half);
109 fraction = (float)position / half;
110 is_before = PluginClient::get_source_position() < half;
111 int w = incoming->get_w();
112 int h = incoming->get_h();
121 switch(incoming->get_color_model())
124 FLASH(unsigned char, int, 3, 0xff, 0x0);
127 FLASH(float, float, 3, 1.0, 0x0);
130 FLASH(unsigned char, int, 4, 0xff, 0x0);
133 FLASH(float, float, 4, 1.0, 0x0);
136 FLASH(unsigned char, int, 3, 0xff, 0x80);
139 FLASH(unsigned char, int, 4, 0xff, 0x80);
142 FLASH(uint16_t, int, 3, 0xffff, 0x0);
144 case BC_RGBA16161616:
145 FLASH(uint16_t, int, 4, 0xffff, 0x0);
148 FLASH(uint16_t, int, 3, 0xffff, 0x8000);
150 case BC_YUVA16161616:
151 FLASH(uint16_t, int, 4, 0xffff, 0x8000);
160 int FlashMain::handle_opengl()
164 // printf("FlashMain::handle_opengl %d %d %d %d\n",
165 // get_input()->get_opengl_state(),
166 // get_input()->get_opengl_state(),
167 // get_output()->get_w(),
168 // get_output()->get_h());
171 // Read images from RAM
172 get_output()->to_texture();
174 // Create output pbuffer
175 get_output()->enable_opengl();
176 VFrame::init_screen(get_output()->get_w(), get_output()->get_h());
178 // Enable output texture
179 get_output()->bind_texture(0);
180 get_output()->draw_texture();
184 // Read images from RAM
185 get_input()->to_texture();
187 // Create output pbuffer
188 get_output()->enable_opengl();
189 VFrame::init_screen(get_output()->get_w(), get_output()->get_h());
191 // Enable output texture
192 get_input()->bind_texture(0);
193 // Draw input texture on output pbuffer
194 get_output()->draw_texture();
197 get_output()->set_opengl_state(VFrame::SCREEN);
199 // Draw flash overlay
200 glDisable(GL_TEXTURE_2D);
203 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
204 if(BC_CModels::is_yuv(get_output()->get_color_model()))
205 glColor4f(1.0, 0.5, 0.5, fraction);
207 glColor4f(1.0, 1.0, 1.0, fraction);
210 glVertex3f(0.0, 0.0, 0.0);
211 glVertex3f(get_output()->get_w(), 0.0, 0.0);
212 glVertex3f(get_output()->get_w(), -get_output()->get_h(), 0.0);
213 glVertex3f(0.0, -get_output()->get_h(), 0.0);
217 glColor4f(1.0, 1.0, 1.0, 1.0);