]> git.sesse.net Git - mlt/blob - src/modules/opengl/mlt_movit_input.cpp
f4b29022eb894f2508c24fff72ca99571458634c
[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         // XXX: this is crashing when a producer is closed
38         // on Windows when using melt with qglsl.
39 //      delete input;
40 }
41
42 std::string MltInput::output_fragment_shader()
43 {
44         assert(input);
45         return input->output_fragment_shader();
46 }
47
48 void MltInput::set_gl_state(GLuint glsl_program_num, const std::string& prefix, unsigned *sampler_num)
49 {
50         assert(input);
51         input->set_gl_state(glsl_program_num, prefix, sampler_num);
52 }
53
54 Effect::AlphaHandling MltInput::alpha_handling() const
55 {
56         assert(input);
57         return input->alpha_handling();
58 }
59
60 void MltInput::finalize()
61 {
62         assert(input);
63         bool ok = input->set_int("output_linear_gamma", output_linear_gamma);
64         ok |= input->set_int("needs_mipmaps", needs_mipmaps);
65         assert(ok);
66         input->finalize();
67 }
68
69 bool MltInput::can_output_linear_gamma() const
70 {
71         assert(input);
72         return input->can_output_linear_gamma();
73 }
74
75 Colorspace MltInput::get_color_space() const
76 {
77         assert(input);
78         return input->get_color_space();
79 }
80 GammaCurve MltInput::get_gamma_curve() const
81 {
82         assert(input);
83         return input->get_gamma_curve();
84 }
85
86 void MltInput::useFlatInput(EffectChain* chain, MovitPixelFormat pix_fmt, unsigned width, unsigned height)
87 {
88         if (!input) {
89                 m_width = width;
90                 m_height = height;
91                 ImageFormat image_format;
92                 image_format.color_space = COLORSPACE_sRGB;
93                 image_format.gamma_curve = GAMMA_sRGB;
94                 input = new FlatInput(image_format, pix_fmt, GL_UNSIGNED_BYTE, width, height);
95                 chain->add_output(image_format, OUTPUT_ALPHA_FORMAT_POSTMULTIPLIED);
96                 chain->set_dither_bits(8);
97         }
98 }
99
100 void MltInput::useYCbCrInput(EffectChain* chain, const ImageFormat& image_format, const YCbCrFormat& ycbcr_format, unsigned width, unsigned height)
101 {
102         if (!input) {
103                 m_width = width;
104                 m_height = height;
105                 input = new YCbCrInput(image_format, ycbcr_format, width, height);
106                 ImageFormat output_format;
107                 output_format.color_space = COLORSPACE_sRGB;
108                 output_format.gamma_curve = GAMMA_sRGB;
109                 chain->add_output(output_format, OUTPUT_ALPHA_FORMAT_POSTMULTIPLIED);
110                 chain->set_dither_bits(8);
111                 isRGB = false;
112                 m_ycbcr_format = ycbcr_format;
113         }
114 }
115
116 void MltInput::useFBOInput(EffectChain *chain, GLuint texture)
117 {
118         if (!input) {
119                 FBOInput* fboInput = new FBOInput(m_width, m_height);
120                 input = fboInput;
121                 fboInput->set_texture(texture);
122         }
123 }
124
125 void MltInput::set_pixel_data(const unsigned char* data)
126 {
127         assert(input);
128         if (isRGB) {
129                 FlatInput* flat = (FlatInput*) input;
130                 flat->set_pixel_data(data);
131         } else {
132                 YCbCrInput* ycbcr = (YCbCrInput*) input;
133                 ycbcr->set_pixel_data(0, data);
134                 ycbcr->set_pixel_data(1, &data[m_width * m_height]);
135                 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)]);
136         }
137 }