]> git.sesse.net Git - mlt/blob - src/modules/opengl/mlt_movit_input.cpp
Add the new opengl module (opengl branch).
[mlt] / src / modules / opengl / mlt_movit_input.cpp
1 /*
2  * mlt_movit_input.cpp
3  * Copyright (C) 2013 Dan Dennedy <dan@dennedy.org>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software Foundation,
17  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 #include "mlt_movit_input.h"
21 #include "fbo_input.h"
22
23 MltInput::MltInput(unsigned width, unsigned height)
24         : m_width(width)
25         , m_height(height)
26         , output_linear_gamma(false)
27         , needs_mipmaps(false)
28         , input(0)
29         , isRGB(true)
30 {
31         register_int("output_linear_gamma", &output_linear_gamma);
32         register_int("needs_mipmaps", &needs_mipmaps);
33 }
34
35 MltInput::~MltInput()
36 {
37         delete input;
38 }
39
40 std::string MltInput::output_fragment_shader()
41 {
42         assert(input);
43         return input->output_fragment_shader();
44 }
45
46 void MltInput::set_gl_state(GLuint glsl_program_num, const std::string& prefix, unsigned *sampler_num)
47 {
48         assert(input);
49         input->set_gl_state(glsl_program_num, prefix, sampler_num);
50 }
51
52 Effect::AlphaHandling MltInput::alpha_handling() const
53 {
54         assert(input);
55         return input->alpha_handling();
56 }
57
58 void MltInput::finalize()
59 {
60         assert(input);
61         bool ok = input->set_int("output_linear_gamma", output_linear_gamma);
62         ok |= input->set_int("needs_mipmaps", needs_mipmaps);
63         assert(ok);
64         input->finalize();
65 }
66
67 bool MltInput::can_output_linear_gamma() const
68 {
69         assert(input);
70         return input->can_output_linear_gamma();
71 }
72
73 Colorspace MltInput::get_color_space() const
74 {
75         assert(input);
76         return input->get_color_space();
77 }
78 GammaCurve MltInput::get_gamma_curve() const
79 {
80         assert(input);
81         return input->get_gamma_curve();
82 }
83
84 void MltInput::useFlatInput(EffectChain* chain, MovitPixelFormat pix_fmt, unsigned width, unsigned height)
85 {
86         if (!input) {
87                 m_width = width;
88                 m_height = height;
89                 ImageFormat image_format;
90                 image_format.color_space = COLORSPACE_sRGB;
91                 image_format.gamma_curve = GAMMA_sRGB;
92                 input = new FlatInput(image_format, pix_fmt, GL_UNSIGNED_BYTE, width, height);
93                 chain->add_output(image_format, OUTPUT_ALPHA_FORMAT_POSTMULTIPLIED);
94                 chain->set_dither_bits(8);
95         }
96 }
97
98 void MltInput::useYCbCrInput(EffectChain* chain, const ImageFormat& image_format, const YCbCrFormat& ycbcr_format, unsigned width, unsigned height)
99 {
100         if (!input) {
101                 m_width = width;
102                 m_height = height;
103                 input = new YCbCrInput(image_format, ycbcr_format, width, height);
104                 ImageFormat output_format;
105                 output_format.color_space = COLORSPACE_sRGB;
106                 output_format.gamma_curve = GAMMA_sRGB;
107                 chain->add_output(output_format, OUTPUT_ALPHA_FORMAT_POSTMULTIPLIED);
108                 chain->set_dither_bits(8);
109                 isRGB = false;
110                 m_ycbcr_format = ycbcr_format;
111         }
112 }
113
114 void MltInput::useFBOInput(EffectChain *chain, GLuint texture)
115 {
116         if (!input) {
117                 FBOInput* fboInput = new FBOInput(m_width, m_height);
118                 input = fboInput;
119                 fboInput->set_texture(texture);
120         }
121 }
122
123 void MltInput::set_pixel_data(const unsigned char* data)
124 {
125         assert(input);
126         if (isRGB) {
127                 FlatInput* flat = (FlatInput*) input;
128                 flat->set_pixel_data(data);
129         } else {
130                 YCbCrInput* ycbcr = (YCbCrInput*) input;
131                 ycbcr->set_pixel_data(0, data);
132                 ycbcr->set_pixel_data(1, &data[m_width * m_height]);
133                 ycbcr->set_pixel_data(2, &data[m_width * m_height + (m_width / m_ycbcr_format.chroma_subsampling_x * m_height / m_ycbcr_format.chroma_subsampling_y)]);
134         }
135 }