2 Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
4 This file is part of libdcp.
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.
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.
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/>.
20 #include "stereo_picture_frame.h"
21 #include "exceptions.h"
24 #include "colour_conversion.h"
26 #include "KM_fileio.h"
27 #include "compose.hpp"
31 using boost::shared_ptr;
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.
38 StereoPictureFrame::StereoPictureFrame (ASDCP::JP2K::MXFSReader* reader, int n, ASDCP::AESDecContext* c)
40 /* XXX: unfortunate guesswork on this buffer size */
41 _buffer = new ASDCP::JP2K::SFrameBuffer (4 * Kumu::Megabyte);
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)));
48 StereoPictureFrame::StereoPictureFrame ()
50 _buffer = new ASDCP::JP2K::SFrameBuffer (4 * Kumu::Megabyte);
53 StereoPictureFrame::~StereoPictureFrame ()
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
63 shared_ptr<OpenJPEGImage>
64 StereoPictureFrame::xyz_image (Eye eye, int reduce) const
68 return decompress_j2k (const_cast<uint8_t*> (_buffer->Left.RoData()), _buffer->Left.Size(), reduce);
70 return decompress_j2k (const_cast<uint8_t*> (_buffer->Right.RoData()), _buffer->Right.Size(), reduce);
73 return shared_ptr<OpenJPEGImage> ();
77 StereoPictureFrame::left_j2k_data () const
79 return _buffer->Left.RoData ();
83 StereoPictureFrame::left_j2k_data ()
85 return _buffer->Left.Data ();
89 StereoPictureFrame::left_j2k_size () const
91 return _buffer->Left.Size ();
95 StereoPictureFrame::right_j2k_data () const
97 return _buffer->Right.RoData ();
101 StereoPictureFrame::right_j2k_data ()
103 return _buffer->Right.Data ();
107 StereoPictureFrame::right_j2k_size () const
109 return _buffer->Right.Size ();