2 Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
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.
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.
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.
20 #include "stereo_picture_frame.h"
21 #include "exceptions.h"
24 #include "colour_conversion.h"
26 #include "KM_fileio.h"
27 #include "compose.hpp"
33 using boost::shared_ptr;
36 /** Make a picture frame from a 3D (stereoscopic) asset.
37 * @param mxf_path Path to the asset's MXF file.
38 * @param n Frame within the asset, not taking EntryPoint into account.
40 StereoPictureFrame::StereoPictureFrame (boost::filesystem::path mxf_path, int n)
42 ASDCP::JP2K::MXFSReader reader;
43 Kumu::Result_t r = reader.OpenRead (mxf_path.string().c_str());
44 if (ASDCP_FAILURE (r)) {
45 boost::throw_exception (FileError ("could not open MXF file for reading", mxf_path, r));
48 /* XXX: unfortunate guesswork on this buffer size */
49 _buffer = new ASDCP::JP2K::SFrameBuffer (4 * Kumu::Megabyte);
51 if (ASDCP_FAILURE (reader.ReadFrame (n, *_buffer))) {
52 boost::throw_exception (DCPReadError (String::compose ("could not read video frame %1 of %2", n, mxf_path.string())));
56 StereoPictureFrame::StereoPictureFrame ()
58 _buffer = new ASDCP::JP2K::SFrameBuffer (4 * Kumu::Megabyte);
61 StereoPictureFrame::~StereoPictureFrame ()
66 /** @param eye Eye to return (EYE_LEFT or EYE_RIGHT).
67 * @param reduce a factor by which to reduce the resolution
68 * of the image, expressed as a power of two (pass 0 for no
72 StereoPictureFrame::xyz_image (Eye eye, int reduce) const
76 return decompress_j2k (const_cast<uint8_t*> (_buffer->Left.RoData()), _buffer->Left.Size(), reduce);
78 return decompress_j2k (const_cast<uint8_t*> (_buffer->Right.RoData()), _buffer->Right.Size(), reduce);
81 return shared_ptr<XYZImage> ();
85 StereoPictureFrame::left_j2k_data () const
87 return _buffer->Left.RoData ();
91 StereoPictureFrame::left_j2k_data ()
93 return _buffer->Left.Data ();
97 StereoPictureFrame::left_j2k_size () const
99 return _buffer->Left.Size ();
103 StereoPictureFrame::right_j2k_data () const
105 return _buffer->Right.RoData ();
109 StereoPictureFrame::right_j2k_data ()
111 return _buffer->Right.Data ();
115 StereoPictureFrame::right_j2k_size () const
117 return _buffer->Right.Size ();