Still more licence fixups.
[libdcp.git] / src / stereo_picture_frame.cc
1 /*
2     Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
3
4     This file is part of libdcp.
5
6     libdcp is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     libdcp is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with libdcp.  If not, see <http://www.gnu.org/licenses/>.
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 reader Reader for the MXF file.
36  *  @param n Frame within the asset, not taking EntryPoint into account.
37  */
38 StereoPictureFrame::StereoPictureFrame (ASDCP::JP2K::MXFSReader* reader, int n, ASDCP::AESDecContext* c)
39 {
40         /* XXX: unfortunate guesswork on this buffer size */
41         _buffer = new ASDCP::JP2K::SFrameBuffer (4 * Kumu::Megabyte);
42
43         if (ASDCP_FAILURE (reader->ReadFrame (n, *_buffer, c))) {
44                 boost::throw_exception (DCPReadError (String::compose ("could not read video frame %1 of %2", n)));
45         }
46 }
47
48 StereoPictureFrame::StereoPictureFrame ()
49 {
50         _buffer = new ASDCP::JP2K::SFrameBuffer (4 * Kumu::Megabyte);
51 }
52
53 StereoPictureFrame::~StereoPictureFrame ()
54 {
55         delete _buffer;
56 }
57
58 /** @param eye Eye to return (EYE_LEFT or EYE_RIGHT).
59  *  @param reduce a factor by which to reduce the resolution
60  *  of the image, expressed as a power of two (pass 0 for no
61  *  reduction).
62  */
63 shared_ptr<OpenJPEGImage>
64 StereoPictureFrame::xyz_image (Eye eye, int reduce) const
65 {
66         switch (eye) {
67         case LEFT:
68                 return decompress_j2k (const_cast<uint8_t*> (_buffer->Left.RoData()), _buffer->Left.Size(), reduce);
69         case RIGHT:
70                 return decompress_j2k (const_cast<uint8_t*> (_buffer->Right.RoData()), _buffer->Right.Size(), reduce);
71         }
72
73         return shared_ptr<OpenJPEGImage> ();
74 }
75
76 uint8_t const *
77 StereoPictureFrame::left_j2k_data () const
78 {
79         return _buffer->Left.RoData ();
80 }
81
82 uint8_t*
83 StereoPictureFrame::left_j2k_data ()
84 {
85         return _buffer->Left.Data ();
86 }
87
88 int
89 StereoPictureFrame::left_j2k_size () const
90 {
91         return _buffer->Left.Size ();
92 }
93
94 uint8_t const *
95 StereoPictureFrame::right_j2k_data () const
96 {
97         return _buffer->Right.RoData ();
98 }
99
100 uint8_t*
101 StereoPictureFrame::right_j2k_data ()
102 {
103         return _buffer->Right.Data ();
104 }
105
106 int
107 StereoPictureFrame::right_j2k_size () const
108 {
109         return _buffer->Right.Size ();
110 }