Remove some unnecessary includes.
[libdcp.git] / src / stereo_picture_frame.cc
1 /*
2     Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include "stereo_picture_frame.h"
21 #include "exceptions.h"
22 #include "util.h"
23 #include "rgb_xyz.h"
24 #include "colour_conversion.h"
25 #include "AS_DCP.h"
26 #include "KM_fileio.h"
27 #include "compose.hpp"
28 #include "j2k.h"
29
30 using std::string;
31 using boost::shared_ptr;
32 using namespace dcp;
33
34 /** Make a picture frame from a 3D (stereoscopic) asset.
35  *  @param mxf_path Path to the asset's MXF file.
36  *  @param n Frame within the asset, not taking EntryPoint into account.
37  */
38 StereoPictureFrame::StereoPictureFrame (boost::filesystem::path path, int n)
39 {
40         ASDCP::JP2K::MXFSReader reader;
41         Kumu::Result_t r = reader.OpenRead (path.string().c_str());
42         if (ASDCP_FAILURE (r)) {
43                 boost::throw_exception (FileError ("could not open MXF file for reading", path, r));
44         }
45
46         /* XXX: unfortunate guesswork on this buffer size */
47         _buffer = new ASDCP::JP2K::SFrameBuffer (4 * Kumu::Megabyte);
48
49         if (ASDCP_FAILURE (reader.ReadFrame (n, *_buffer))) {
50                 boost::throw_exception (DCPReadError (String::compose ("could not read video frame %1 of %2", n, path.string())));
51         }
52 }
53
54 StereoPictureFrame::StereoPictureFrame ()
55 {
56         _buffer = new ASDCP::JP2K::SFrameBuffer (4 * Kumu::Megabyte);
57 }
58
59 StereoPictureFrame::~StereoPictureFrame ()
60 {
61         delete _buffer;
62 }
63
64 /** @param eye Eye to return (EYE_LEFT or EYE_RIGHT).
65  *  @param reduce a factor by which to reduce the resolution
66  *  of the image, expressed as a power of two (pass 0 for no
67  *  reduction).
68  */
69 shared_ptr<OpenJPEGImage>
70 StereoPictureFrame::xyz_image (Eye eye, int reduce) const
71 {
72         switch (eye) {
73         case LEFT:
74                 return decompress_j2k (const_cast<uint8_t*> (_buffer->Left.RoData()), _buffer->Left.Size(), reduce);
75         case RIGHT:
76                 return decompress_j2k (const_cast<uint8_t*> (_buffer->Right.RoData()), _buffer->Right.Size(), reduce);
77         }
78
79         return shared_ptr<OpenJPEGImage> ();
80 }
81
82 uint8_t const *
83 StereoPictureFrame::left_j2k_data () const
84 {
85         return _buffer->Left.RoData ();
86 }
87
88 uint8_t*
89 StereoPictureFrame::left_j2k_data ()
90 {
91         return _buffer->Left.Data ();
92 }
93
94 int
95 StereoPictureFrame::left_j2k_size () const
96 {
97         return _buffer->Left.Size ();
98 }
99
100 uint8_t const *
101 StereoPictureFrame::right_j2k_data () const
102 {
103         return _buffer->Right.RoData ();
104 }
105
106 uint8_t*
107 StereoPictureFrame::right_j2k_data ()
108 {
109         return _buffer->Right.Data ();
110 }
111
112 int
113 StereoPictureFrame::right_j2k_size () const
114 {
115         return _buffer->Right.Size ();
116 }