asdcp headers moved into subdirectory.
[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     In addition, as a special exception, the copyright holders give
20     permission to link the code of portions of this program with the
21     OpenSSL library under certain conditions as described in each
22     individual source file, and distribute linked combinations
23     including the two.
24
25     You must obey the GNU General Public License in all respects
26     for all of the code used other than OpenSSL.  If you modify
27     file(s) with this exception, you may extend this exception to your
28     version of the file(s), but you are not obligated to do so.  If you
29     do not wish to do so, delete this exception statement from your
30     version.  If you delete this exception statement from all source
31     files in the program, then also delete it here.
32 */
33
34 #include "stereo_picture_frame.h"
35 #include "exceptions.h"
36 #include "util.h"
37 #include "rgb_xyz.h"
38 #include "colour_conversion.h"
39 #include "compose.hpp"
40 #include "j2k.h"
41 #include <asdcp/AS_DCP.h>
42 #include <asdcp/KM_fileio.h>
43
44 using std::string;
45 using boost::shared_ptr;
46 using namespace dcp;
47
48 /** Make a picture frame from a 3D (stereoscopic) asset.
49  *  @param reader Reader for the MXF file.
50  *  @param n Frame within the asset, not taking EntryPoint into account.
51  */
52 StereoPictureFrame::StereoPictureFrame (ASDCP::JP2K::MXFSReader* reader, int n, ASDCP::AESDecContext* c)
53 {
54         /* XXX: unfortunate guesswork on this buffer size */
55         _buffer = new ASDCP::JP2K::SFrameBuffer (4 * Kumu::Megabyte);
56
57         if (ASDCP_FAILURE (reader->ReadFrame (n, *_buffer, c))) {
58                 boost::throw_exception (DCPReadError (String::compose ("could not read video frame %1 of %2", n)));
59         }
60 }
61
62 StereoPictureFrame::StereoPictureFrame ()
63 {
64         _buffer = new ASDCP::JP2K::SFrameBuffer (4 * Kumu::Megabyte);
65 }
66
67 StereoPictureFrame::~StereoPictureFrame ()
68 {
69         delete _buffer;
70 }
71
72 /** @param eye Eye to return (EYE_LEFT or EYE_RIGHT).
73  *  @param reduce a factor by which to reduce the resolution
74  *  of the image, expressed as a power of two (pass 0 for no
75  *  reduction).
76  */
77 shared_ptr<OpenJPEGImage>
78 StereoPictureFrame::xyz_image (Eye eye, int reduce) const
79 {
80         switch (eye) {
81         case LEFT:
82                 return decompress_j2k (const_cast<uint8_t*> (_buffer->Left.RoData()), _buffer->Left.Size(), reduce);
83         case RIGHT:
84                 return decompress_j2k (const_cast<uint8_t*> (_buffer->Right.RoData()), _buffer->Right.Size(), reduce);
85         }
86
87         return shared_ptr<OpenJPEGImage> ();
88 }
89
90 uint8_t const *
91 StereoPictureFrame::left_j2k_data () const
92 {
93         return _buffer->Left.RoData ();
94 }
95
96 uint8_t*
97 StereoPictureFrame::left_j2k_data ()
98 {
99         return _buffer->Left.Data ();
100 }
101
102 int
103 StereoPictureFrame::left_j2k_size () const
104 {
105         return _buffer->Left.Size ();
106 }
107
108 uint8_t const *
109 StereoPictureFrame::right_j2k_data () const
110 {
111         return _buffer->Right.RoData ();
112 }
113
114 uint8_t*
115 StereoPictureFrame::right_j2k_data ()
116 {
117         return _buffer->Right.Data ();
118 }
119
120 int
121 StereoPictureFrame::right_j2k_size () const
122 {
123         return _buffer->Right.Size ();
124 }