edl plugin names eng, fix segv for opengl brender, renderfarm rework strategy, perf...
[goodguy/history.git] / cinelerra-5.1 / plugins / dissolve / dissolve.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 "dissolve.h"
23 #include "edl.inc"
24 #include "language.h"
25 #include "overlayframe.h"
26 #include "vframe.h"
27
28 #include <string.h>
29
30 PluginClient* new_plugin(PluginServer *server)
31 {
32         return new DissolveMain(server);
33 }
34
35
36
37
38
39 DissolveMain::DissolveMain(PluginServer *server)
40  : PluginVClient(server)
41 {
42         overlayer = 0;
43 }
44
45 DissolveMain::~DissolveMain()
46 {
47         delete overlayer;
48 }
49
50 const char* DissolveMain::plugin_title() { return N_("Dissolve"); }
51 int DissolveMain::is_video() { return 1; }
52 int DissolveMain::is_transition() { return 1; }
53 int DissolveMain::uses_gui() { return 0; }
54
55
56
57 int DissolveMain::process_realtime(VFrame *incoming, VFrame *outgoing)
58 {
59         fade = (float)PluginClient::get_source_position() /
60                         PluginClient::get_total_len();
61
62 // Use hardware
63         if(get_use_opengl())
64         {
65                 run_opengl();
66                 return 0;
67         }
68
69 // Use software
70         if(!overlayer) overlayer = new OverlayFrame(get_project_smp() + 1);
71
72         overlayer->overlay(outgoing, incoming,
73                 0, 0, incoming->get_w(), incoming->get_h(),
74                 0, 0, incoming->get_w(), incoming->get_h(),
75                 fade, TRANSFER_SRC, NEAREST_NEIGHBOR);
76
77         return 0;
78 }
79
80 int DissolveMain::handle_opengl()
81 {
82 #ifdef HAVE_GL
83         static const char *blend_dissolve =
84                 "uniform float fade;\n"
85                 "uniform sampler2D src_tex;\n"
86                 "uniform sampler2D dst_tex;\n"
87                 "uniform vec2 dst_tex_dimensions;\n"
88                 "uniform vec3 chroma_offset;\n"
89                 "void main()\n"
90                 "{\n"
91                 "       vec4 result_color;\n"
92                 "       vec4 dst_color = texture2D(dst_tex, gl_FragCoord.xy / dst_tex_dimensions);\n"
93                 "       vec4 src_color = texture2D(src_tex, gl_TexCoord[0].st);\n"
94                 "       src_color.rgb -= chroma_offset;\n"
95                 "       dst_color.rgb -= chroma_offset;\n"
96                 "       result_color = mix(dst_color, src_color, fade);\n"
97                 "       result_color.rgb += chroma_offset;\n"
98                 "       gl_FragColor = result_color;\n"
99                 "}\n";
100
101 // Read images from RAM
102         VFrame *src = get_input();
103         src->to_texture();
104         VFrame *dst = get_output();
105         dst->to_texture();
106         dst->enable_opengl();
107         dst->init_screen();
108         src->bind_texture(0);
109         dst->bind_texture(1);
110
111         unsigned int shader = VFrame::make_shader(0, blend_dissolve, 0);
112         if( shader > 0 ) {
113                 glUseProgram(shader);
114                 glUniform1f(glGetUniformLocation(shader, "fade"), fade);
115                 glUniform1i(glGetUniformLocation(shader, "src_tex"), 0);
116                 glUniform1i(glGetUniformLocation(shader, "dst_tex"), 1);
117                 if(BC_CModels::is_yuv(dst->get_color_model()))
118                         glUniform3f(glGetUniformLocation(shader, "chroma_offset"), 0.0, 0.5, 0.5);
119                 else
120                         glUniform3f(glGetUniformLocation(shader, "chroma_offset"), 0.0, 0.0, 0.0);
121                 glUniform2f(glGetUniformLocation(shader, "dst_tex_dimensions"),
122                         (float)dst->get_texture_w(),
123                         (float)dst->get_texture_h());
124         }
125         glDisable(GL_BLEND);
126         src->draw_texture();
127         glUseProgram(0);
128
129         glDisable(GL_BLEND);
130         glActiveTexture(GL_TEXTURE1);
131         glDisable(GL_TEXTURE_2D);
132         glActiveTexture(GL_TEXTURE0);
133         glDisable(GL_TEXTURE_2D);
134
135         dst->set_opengl_state(VFrame::SCREEN);
136 #endif
137         return 0;
138 }
139
140
141