fixup cut/paste bugs in de.po, fix segv in tz/ntsc lookup, add debian
[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 _("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         const char *shader_stack[] = { 0, 0, 0 };
112         int current_shader = 0;
113         shader_stack[current_shader++] = blend_dissolve;
114
115         unsigned int shader_id = VFrame::make_shader(0,
116                 shader_stack[0], shader_stack[1], shader_stack[2], 0);
117
118         glUseProgram(shader_id);
119         glUniform1f(glGetUniformLocation(shader_id, "fade"), fade);
120         glUniform1i(glGetUniformLocation(shader_id, "src_tex"), 0);
121         glUniform1i(glGetUniformLocation(shader_id, "dst_tex"), 1);
122         if(BC_CModels::is_yuv(dst->get_color_model()))
123                 glUniform3f(glGetUniformLocation(shader_id, "chroma_offset"), 0.0, 0.5, 0.5);
124         else
125                 glUniform3f(glGetUniformLocation(shader_id, "chroma_offset"), 0.0, 0.0, 0.0);
126         glUniform2f(glGetUniformLocation(shader_id, "dst_tex_dimensions"),
127                 (float)dst->get_texture_w(),
128                 (float)dst->get_texture_h());
129
130         glDisable(GL_BLEND);
131         src->draw_texture();
132         glUseProgram(0);
133
134         glDisable(GL_BLEND);
135         glActiveTexture(GL_TEXTURE1);
136         glDisable(GL_TEXTURE_2D);
137         glActiveTexture(GL_TEXTURE0);
138         glDisable(GL_TEXTURE_2D);
139
140         dst->set_opengl_state(VFrame::SCREEN);
141 #endif
142         return 0;
143 }
144
145
146