edl plugin names eng, fix segv for opengl brender, renderfarm rework strategy, perf...
[goodguy/history.git] / cinelerra-5.1 / plugins / flash / flash.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 "flash.h"
23 #include "edl.inc"
24 #include "overlayframe.h"
25 #include "language.h"
26 #include "vframe.h"
27 #include <stdint.h>
28
29
30 REGISTER_PLUGIN(FlashMain)
31
32
33
34
35
36 FlashMain::FlashMain(PluginServer *server)
37  : PluginVClient(server)
38 {
39 }
40
41 FlashMain::~FlashMain()
42 {
43 }
44
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; }
49
50
51
52 #define FLASH(type, temp_type, components, max, chroma_offset) \
53 { \
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; \
59  \
60         for(int i = 0; i < h; i++) \
61         { \
62                 type *in_row = (type*)incoming->get_rows()[i]; \
63                 type *out_row = (type*)outgoing->get_rows()[i]; \
64                 if(is_before) \
65                 { \
66                         for(int j = 0; j < w; j++) \
67                         { \
68                                 *out_row = foreground + transparency * *out_row / max; \
69                                 out_row++; \
70                                 *out_row = chroma_foreground + transparency * *out_row / max; \
71                                 out_row++; \
72                                 *out_row = chroma_foreground + transparency * *out_row / max; \
73                                 out_row++; \
74                                 if(components == 4) \
75                                 { \
76                                         *out_row = foreground + transparency * *out_row / max; \
77                                         out_row++; \
78                                 } \
79                         } \
80                 } \
81                 else \
82                 { \
83                         for(int j = 0; j < w; j++) \
84                         { \
85                                 *out_row = foreground + transparency * *in_row / max; \
86                                 out_row++; \
87                                 in_row++; \
88                                 *out_row = chroma_foreground + transparency * *in_row / max; \
89                                 out_row++; \
90                                 in_row++; \
91                                 *out_row = chroma_foreground + transparency * *in_row / max; \
92                                 out_row++; \
93                                 in_row++; \
94                                 if(components == 4) \
95                                 { \
96                                         *out_row = foreground + transparency * *in_row / max; \
97                                         out_row++; \
98                                         in_row++; \
99                                 } \
100                         } \
101                 } \
102         } \
103 }
104
105 int FlashMain::process_realtime(VFrame *incoming, VFrame *outgoing)
106 {
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();
113
114 // Use hardware
115         if(get_use_opengl())
116         {
117                 run_opengl();
118                 return 0;
119         }
120
121         switch(incoming->get_color_model())
122         {
123                 case BC_RGB888:
124                         FLASH(unsigned char, int, 3, 0xff, 0x0);
125                         break;
126                 case BC_RGB_FLOAT:
127                         FLASH(float, float, 3, 1.0, 0x0);
128                         break;
129                 case BC_RGBA8888:
130                         FLASH(unsigned char, int, 4, 0xff, 0x0);
131                         break;
132                 case BC_RGBA_FLOAT:
133                         FLASH(float, float, 4, 1.0, 0x0);
134                         break;
135                 case BC_YUV888:
136                         FLASH(unsigned char, int, 3, 0xff, 0x80);
137                         break;
138                 case BC_YUVA8888:
139                         FLASH(unsigned char, int, 4, 0xff, 0x80);
140                         break;
141                 case BC_RGB161616:
142                         FLASH(uint16_t, int, 3, 0xffff, 0x0);
143                         break;
144                 case BC_RGBA16161616:
145                         FLASH(uint16_t, int, 4, 0xffff, 0x0);
146                         break;
147                 case BC_YUV161616:
148                         FLASH(uint16_t, int, 3, 0xffff, 0x8000);
149                         break;
150                 case BC_YUVA16161616:
151                         FLASH(uint16_t, int, 4, 0xffff, 0x8000);
152                         break;
153         }
154
155         return 0;
156 }
157
158
159
160 int FlashMain::handle_opengl()
161 {
162 #ifdef HAVE_GL
163
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());
169         if(is_before)
170         {
171 // Read images from RAM
172                 get_output()->to_texture();
173
174 // Create output pbuffer
175                 get_output()->enable_opengl();
176                 VFrame::init_screen(get_output()->get_w(), get_output()->get_h());
177
178 // Enable output texture
179                 get_output()->bind_texture(0);
180                 get_output()->draw_texture();
181         }
182         else
183         {
184 // Read images from RAM
185                 get_input()->to_texture();
186
187 // Create output pbuffer
188                 get_output()->enable_opengl();
189                 VFrame::init_screen(get_output()->get_w(), get_output()->get_h());
190
191 // Enable output texture
192                 get_input()->bind_texture(0);
193 // Draw input texture on output pbuffer
194                 get_output()->draw_texture();
195         }
196
197         get_output()->set_opengl_state(VFrame::SCREEN);
198
199 // Draw flash overlay
200         glDisable(GL_TEXTURE_2D);
201
202         glEnable(GL_BLEND);
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);
206         else
207                 glColor4f(1.0, 1.0, 1.0, fraction);
208
209         glBegin(GL_QUADS);
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);
214         glEnd();
215         glDisable(GL_BLEND);
216
217         glColor4f(1.0, 1.0, 1.0, 1.0);
218
219         return 1;
220 #endif
221
222         return 0;
223 }
224
225
226
227