]> git.sesse.net Git - mlt/blob - src/modules/opengl/mlt_movit_input.cpp
4339ac30e88a3f4db3e2b19d47244f057bdd2339
[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
22 MltInput::MltInput(unsigned width, unsigned height)
23         : m_width(width)
24         , m_height(height)
25         , output_linear_gamma(false)
26         , needs_mipmaps(false)
27         , input(0)
28         , isRGB(true)
29 {
30         register_int("output_linear_gamma", &output_linear_gamma);
31         register_int("needs_mipmaps", &needs_mipmaps);
32 }
33
34 MltInput::~MltInput()
35 {
36         // XXX: this is crashing when a producer is closed
37         // on Windows when using melt with qglsl.
38 //      delete input;
39 }
40
41 std::string MltInput::output_fragment_shader()
42 {
43         assert(input);
44         return input->output_fragment_shader();
45 }
46
47 void MltInput::set_gl_state(GLuint glsl_program_num, const std::string& prefix, unsigned *sampler_num)
48 {
49         assert(input);
50         input->set_gl_state(glsl_program_num, prefix, sampler_num);
51 }
52
53 Effect::AlphaHandling MltInput::alpha_handling() const
54 {
55         assert(input);
56         return input->alpha_handling();
57 }
58
59 void MltInput::finalize()
60 {
61         assert(input);
62         bool ok = input->set_int("output_linear_gamma", output_linear_gamma);
63         ok |= input->set_int("needs_mipmaps", needs_mipmaps);
64         assert(ok);
65         input->finalize();
66 }
67
68 bool MltInput::can_output_linear_gamma() const
69 {
70         assert(input);
71         return input->can_output_linear_gamma();
72 }
73
74 Colorspace MltInput::get_color_space() const
75 {
76         assert(input);
77         return input->get_color_space();
78 }
79 GammaCurve MltInput::get_gamma_curve() const
80 {
81         assert(input);
82         return input->get_gamma_curve();
83 }
84
85 void MltInput::useFlatInput(MovitPixelFormat pix_fmt, unsigned width, unsigned height)
86 {
87         if (!input) {
88                 m_width = width;
89                 m_height = height;
90                 ImageFormat image_format;
91                 image_format.color_space = COLORSPACE_sRGB;
92                 image_format.gamma_curve = GAMMA_sRGB;
93                 input = new FlatInput(image_format, pix_fmt, GL_UNSIGNED_BYTE, width, height);
94         }
95 }
96
97 void MltInput::useYCbCrInput(const ImageFormat& image_format, const YCbCrFormat& ycbcr_format, unsigned width, unsigned height)
98 {
99         if (!input) {
100                 m_width = width;
101                 m_height = height;
102                 input = new YCbCrInput(image_format, ycbcr_format, width, height);
103                 isRGB = false;
104                 m_ycbcr_format = ycbcr_format;
105         }
106 }
107
108 void MltInput::set_pixel_data(const unsigned char* data)
109 {
110         assert(input);
111         if (isRGB) {
112                 FlatInput* flat = (FlatInput*) input;
113                 flat->set_pixel_data(data);
114         } else {
115                 YCbCrInput* ycbcr = (YCbCrInput*) input;
116                 ycbcr->set_pixel_data(0, data);
117                 ycbcr->set_pixel_data(1, &data[m_width * m_height]);
118                 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)]);
119         }
120 }