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 "picture_frame.h"
24 #include "exceptions.h"
25 #include "argb_frame.h"
30 using namespace boost;
31 using namespace libdcp;
33 /** Make a picture frame from a 2D (monoscopic) asset.
34 * @param mxf_path Path to the asset's MXF file.
35 * @param n Frame within the asset, not taking EntryPoint into account.
37 MonoPictureFrame::MonoPictureFrame (string mxf_path, int n)
39 ASDCP::JP2K::MXFReader reader;
40 if (ASDCP_FAILURE (reader.OpenRead (mxf_path.c_str()))) {
41 throw FileError ("could not open MXF file for reading", mxf_path);
44 /* XXX: unfortunate guesswork on this buffer size */
45 _buffer = new ASDCP::JP2K::FrameBuffer (4 * Kumu::Megabyte);
47 if (ASDCP_FAILURE (reader.ReadFrame (n, *_buffer))) {
48 throw DCPReadError ("could not read video frame");
52 MonoPictureFrame::~MonoPictureFrame ()
57 /** @return An ARGB representation of this frame. This is ARGB in the
58 * Cairo sense, so that each pixel takes up 4 bytes; the first byte
59 * is blue, second green, third red and fourth alpha (always 255).
62 MonoPictureFrame::argb_frame () const
64 opj_image_t* xyz_frame = decompress_j2k (const_cast<uint8_t*> (_buffer->RoData()), _buffer->Size());
65 assert (xyz_frame->numcomps == 3);
66 shared_ptr<ARGBFrame> f = xyz_to_rgb (xyz_frame);
67 opj_image_destroy (xyz_frame);
71 /** Make a picture frame from a 3D (stereoscopic) asset.
72 * @param mxf_path Path to the asset's MXF file.
73 * @param n Frame within the asset, not taking EntryPoint into account.
75 StereoPictureFrame::StereoPictureFrame (string mxf_path, int n)
77 ASDCP::JP2K::MXFSReader reader;
78 if (ASDCP_FAILURE (reader.OpenRead (mxf_path.c_str()))) {
79 throw FileError ("could not open MXF file for reading", mxf_path);
82 /* XXX: unfortunate guesswork on this buffer size */
83 _buffer = new ASDCP::JP2K::SFrameBuffer (4 * Kumu::Megabyte);
85 if (ASDCP_FAILURE (reader.ReadFrame (n, *_buffer))) {
86 throw DCPReadError ("could not read video frame");
90 StereoPictureFrame::~StereoPictureFrame ()
95 /** @return An ARGB representation of one of the eyes (left or right)
96 * of this frame. This is ARGB in the Cairo sense, so that each
97 * pixel takes up 4 bytes; the first byte is blue, second green,
98 * third red and fourth alpha (always 255).
100 * @param eye Eye to return (EYE_LEFT or EYE_RIGHT).
102 shared_ptr<ARGBFrame>
103 StereoPictureFrame::argb_frame (Eye eye) const
105 opj_image_t* xyz_frame = 0;
108 xyz_frame = decompress_j2k (const_cast<uint8_t*> (_buffer->Left.RoData()), _buffer->Left.Size());
111 xyz_frame = decompress_j2k (const_cast<uint8_t*> (_buffer->Right.RoData()), _buffer->Right.Size());
115 assert (xyz_frame->numcomps == 3);
116 shared_ptr<ARGBFrame> f = xyz_to_rgb (xyz_frame);
117 opj_image_destroy (xyz_frame);