]> git.sesse.net Git - mlt/blob - src/modules/opengl/mlt_movit_input.cpp
89a2d84dbe5c65944c8180a6774c92c89ea775f8
[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 using namespace movit;
23
24 MltInput::MltInput()
25         : input(0)
26         , isRGB(true)
27 {
28 }
29
30 MltInput::~MltInput()
31 {
32 }
33
34 void MltInput::useFlatInput(MovitPixelFormat pix_fmt, unsigned width, unsigned height)
35 {
36         if (!input) {
37                 m_width = width;
38                 m_height = height;
39                 ImageFormat image_format;
40                 image_format.color_space = COLORSPACE_sRGB;
41                 image_format.gamma_curve = GAMMA_sRGB;
42                 input = new FlatInput(image_format, pix_fmt, GL_UNSIGNED_BYTE, width, height);
43         }
44 }
45
46 void MltInput::useYCbCrInput(const ImageFormat& image_format, const YCbCrFormat& ycbcr_format, unsigned width, unsigned height)
47 {
48         if (!input) {
49                 m_width = width;
50                 m_height = height;
51                 input = new YCbCrInput(image_format, ycbcr_format, width, height);
52                 isRGB = false;
53                 m_ycbcr_format = ycbcr_format;
54         }
55 }
56
57 void MltInput::set_pixel_data(const unsigned char* data)
58 {
59         assert(input);
60         if (isRGB) {
61                 FlatInput* flat = (FlatInput*) input;
62                 flat->set_pixel_data(data);
63         } else {
64                 YCbCrInput* ycbcr = (YCbCrInput*) input;
65                 ycbcr->set_pixel_data(0, data);
66                 ycbcr->set_pixel_data(1, &data[m_width * m_height]);
67                 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)]);
68         }
69 }
70
71 void MltInput::invalidate_pixel_data()
72 {
73         assert(input);
74         if (isRGB) {
75                 FlatInput* flat = (FlatInput*) input;
76                 flat->invalidate_pixel_data();
77         } else {
78                 YCbCrInput* ycbcr = (YCbCrInput*) input;
79                 ycbcr->invalidate_pixel_data();
80         }
81 }