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 /** @file src/mono_picture_frame.cc
21 * @brief MonoPictureFrame class.
24 #include "mono_picture_frame.h"
25 #include "exceptions.h"
28 #include "colour_conversion.h"
29 #include "KM_fileio.h"
36 using boost::shared_ptr;
37 using boost::optional;
40 /** Make a picture frame from a JPEG2000 file.
41 * @param path Path to JPEG2000 file.
43 MonoPictureFrame::MonoPictureFrame (boost::filesystem::path path)
45 boost::uintmax_t const size = boost::filesystem::file_size (path);
46 _buffer = new ASDCP::JP2K::FrameBuffer (size);
47 FILE* f = fopen_boost (path, "r");
49 boost::throw_exception (FileError ("could not open JPEG2000 file", path, errno));
52 fread (j2k_data(), 1, size, f);
58 /** Make a picture frame from a 2D (monoscopic) asset.
59 * @param mxf_path Path to the asset's MXF file.
60 * @param n Frame within the asset, not taking EntryPoint into account.
61 * @param c Context for decryption, or 0.
63 MonoPictureFrame::MonoPictureFrame (boost::filesystem::path mxf_path, int n, ASDCP::AESDecContext* c)
65 ASDCP::JP2K::MXFReader reader;
66 Kumu::Result_t r = reader.OpenRead (mxf_path.string().c_str());
67 if (ASDCP_FAILURE (r)) {
68 boost::throw_exception (FileError ("could not open MXF file for reading", mxf_path, r));
71 /* XXX: unfortunate guesswork on this buffer size */
72 _buffer = new ASDCP::JP2K::FrameBuffer (4 * Kumu::Megabyte);
74 if (ASDCP_FAILURE (reader.ReadFrame (n, *_buffer, c))) {
75 boost::throw_exception (DCPReadError ("could not read video frame"));
79 MonoPictureFrame::MonoPictureFrame ()
81 _buffer = new ASDCP::JP2K::FrameBuffer (4 * Kumu::Megabyte);
84 /** MonoPictureFrame destructor */
85 MonoPictureFrame::~MonoPictureFrame ()
90 /** @return Pointer to JPEG2000 data */
92 MonoPictureFrame::j2k_data () const
94 return _buffer->RoData ();
97 /** @return Pointer to JPEG2000 data */
99 MonoPictureFrame::j2k_data ()
101 return _buffer->Data ();
104 /** @return Size of JPEG2000 data in bytes */
106 MonoPictureFrame::j2k_size () const
108 return _buffer->Size ();
111 /** @param reduce a factor by which to reduce the resolution
112 * of the image, expressed as a power of two (pass 0 for no
116 MonoPictureFrame::xyz_image (int reduce) const
118 return decompress_j2k (const_cast<uint8_t*> (_buffer->RoData()), _buffer->Size(), reduce);