Fixed initialisation of tf in file_open(). Without setting the memory to 0,
[cinelerra_cv/mob.git] / plugins / dissolve / dissolve.C
blobe016efdbf45fbc6975c8ed449db118ddd0e0ee83
1 #include "dissolve.h"
2 #include "edl.inc"
3 #include "language.h"
4 #include "overlayframe.h"
5 #include "picon_png.h"
6 #include "vframe.h"
8 #include <string.h>
10 PluginClient* new_plugin(PluginServer *server)
12         return new DissolveMain(server);
19 DissolveMain::DissolveMain(PluginServer *server)
20  : PluginVClient(server)
22         overlayer = 0;
25 DissolveMain::~DissolveMain()
27         delete overlayer;
30 char* DissolveMain::plugin_title() { return N_("Dissolve"); }
31 int DissolveMain::is_video() { return 1; }
32 int DissolveMain::is_transition() { return 1; }
33 int DissolveMain::uses_gui() { return 0; }
35 NEW_PICON_MACRO(DissolveMain)
38 int DissolveMain::process_realtime(VFrame *incoming, VFrame *outgoing)
40         fade = (float)PluginClient::get_source_position() / 
41                         PluginClient::get_total_len();
43 // Use hardware
44         if(get_use_opengl())
45         {
46                 run_opengl();
47                 return 0;
48         }
50 // Use software
51         if(!overlayer) overlayer = new OverlayFrame(get_project_smp() + 1);
54 // There is a problem when dissolving from a big picture to a small picture.
55 // In order to make it dissolve correctly, we have to manually decrese alpha of big picture.
56         switch (outgoing->get_color_model())
57         {
58                 case BC_RGBA8888:
59                 case BC_YUVA8888:
60                 {
61                         uint8_t** data_rows = (uint8_t **)outgoing->get_rows();
62                         int w = outgoing->get_w();
63                         int h = outgoing->get_h(); 
64                         for(int i = 0; i < h; i++) 
65                         { 
66                                 uint8_t* alpha_chan = data_rows[i] + 3; 
67                                 for(int j = 0; j < w; j++) 
68                                 {
69                                         *alpha_chan = (uint8_t) (*alpha_chan * (1-fade));
70                                         alpha_chan+=4;
71                                 } 
72                         }
73                         break;
74                 }
75                 case BC_YUVA16161616:
76                 {
77                         uint16_t** data_rows = (uint16_t **)outgoing->get_rows();
78                         int w = outgoing->get_w();
79                         int h = outgoing->get_h(); 
80                         for(int i = 0; i < h; i++) 
81                         { 
82                                 uint16_t* alpha_chan = data_rows[i] + 3; // 3 since this is uint16_t
83                                 for(int j = 0; j < w; j++) 
84                                 {
85                                         *alpha_chan = (uint16_t)(*alpha_chan * (1-fade));
86                                         alpha_chan += 8;
87                                 } 
88                         }
89                         break;
90                 }
91                 case BC_RGBA_FLOAT:
92                 {
93                         float** data_rows = (float **)outgoing->get_rows();
94                         int w = outgoing->get_w();
95                         int h = outgoing->get_h(); 
96                         for(int i = 0; i < h; i++) 
97                         { 
98                                 float* alpha_chan = data_rows[i] + 3; // 3 since this is floats 
99                                 for(int j = 0; j < w; j++) 
100                                 {
101                                         *alpha_chan = *alpha_chan * (1-fade);
102                                         alpha_chan += sizeof(float);
103                                 } 
104                         }
105                         break;
106                 }
107                 default:
108                         break;
109         }
112         overlayer->overlay(outgoing, 
113                 incoming, 
114                 0, 
115                 0, 
116                 incoming->get_w(),
117                 incoming->get_h(),
118                 0,
119                 0,
120                 incoming->get_w(),
121                 incoming->get_h(),
122                 fade,
123                 TRANSFER_NORMAL,
124                 NEAREST_NEIGHBOR);
126         return 0;
129 int DissolveMain::handle_opengl()
131 #ifdef HAVE_GL
133 // Read images from RAM
134         get_input()->to_texture();
135         get_output()->to_texture();
137 // Create output pbuffer
138         get_output()->enable_opengl();
140         VFrame::init_screen(get_output()->get_w(), get_output()->get_h());
142 // Enable output texture
143         get_output()->bind_texture(0);
144 // Draw output texture
145         glDisable(GL_BLEND);
146         glColor4f(1, 1, 1, 1);
147         get_output()->draw_texture();
149 // Draw input texture
150         get_input()->bind_texture(0);
151         glEnable(GL_BLEND);
152         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
153         glColor4f(1, 1, 1, fade);
154         get_input()->draw_texture();
157         glDisable(GL_BLEND);
158         get_output()->set_opengl_state(VFrame::SCREEN);
161 #endif