2 Copyright (C) 2012 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.
22 #include "KM_fileio.h"
23 #include "stereo_picture_frame.h"
24 #include "exceptions.h"
25 #include "argb_frame.h"
28 #include "gamma_lut.h"
34 using boost::shared_ptr;
35 using namespace libdcp;
37 /** Make a picture frame from a 3D (stereoscopic) asset.
38 * @param mxf_path Path to the asset's MXF file.
39 * @param n Frame within the asset, not taking EntryPoint into account.
41 StereoPictureFrame::StereoPictureFrame (boost::filesystem::path mxf_path, int n)
43 ASDCP::JP2K::MXFSReader reader;
44 if (ASDCP_FAILURE (reader.OpenRead (mxf_path.string().c_str()))) {
45 boost::throw_exception (FileError ("could not open MXF file for reading", mxf_path));
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 ("could not read video frame"));
56 StereoPictureFrame::~StereoPictureFrame ()
61 /** @param reduce a factor by which to reduce the resolution
62 * of the image, expressed as a power of two (pass 0 for no
65 * @param eye Eye to return (EYE_LEFT or EYE_RIGHT).
67 * @return An ARGB representation of one of the eyes (left or right)
68 * of this frame. This is ARGB in the Cairo sense, so that each
69 * pixel takes up 4 bytes; the first byte is blue, second green,
70 * third red and fourth alpha (always 255).
74 StereoPictureFrame::argb_frame (Eye eye, int reduce, float srgb_gamma) const
76 shared_ptr<XYZFrame> xyz_frame;
79 xyz_frame = decompress_j2k (const_cast<uint8_t*> (_buffer->Left.RoData()), _buffer->Left.Size(), reduce);
82 xyz_frame = decompress_j2k (const_cast<uint8_t*> (_buffer->Right.RoData()), _buffer->Right.Size(), reduce);
86 return xyz_to_rgb (xyz_frame, GammaLUT::cache.get (12, DCI_GAMMA), GammaLUT::cache.get (12, 1 / srgb_gamma));
90 StereoPictureFrame::left_j2k_data () const
92 return _buffer->Left.RoData ();
96 StereoPictureFrame::left_j2k_size () const
98 return _buffer->Left.Size ();
102 StereoPictureFrame::right_j2k_data () const
104 return _buffer->Right.RoData ();
108 StereoPictureFrame::right_j2k_size () const
110 return _buffer->Right.Size ();