2 Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic 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 DCP-o-matic 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 DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
21 #include "image_content.h"
22 #include "image_decoder.h"
23 #include "video_decoder.h"
25 #include "ffmpeg_image_proxy.h"
26 #include "j2k_image_proxy.h"
28 #include "exceptions.h"
29 #include "video_content.h"
30 #include <boost/filesystem.hpp>
36 using boost::shared_ptr;
38 using namespace dcpomatic;
40 ImageDecoder::ImageDecoder (shared_ptr<const Film> film, shared_ptr<const ImageContent> c)
43 , _frame_video_position (0)
45 video.reset (new VideoDecoder (this, c));
51 if (_frame_video_position >= _image_content->video->length()) {
55 if (!_image_content->still() || !_image) {
56 /* Either we need an image or we are using moving images, so load one */
57 boost::filesystem::path path = _image_content->path (_image_content->still() ? 0 : _frame_video_position);
58 if (valid_j2k_file (path)) {
60 if (_image_content->video->colour_conversion()) {
61 /* We have a specified colour conversion: assume the image is RGB */
62 pf = AV_PIX_FMT_RGB48LE;
64 /* No specified colour conversion: assume the image is XYZ */
65 pf = AV_PIX_FMT_XYZ12LE;
67 /* We can't extract image size from a JPEG2000 codestream without decoding it,
68 so pass in the image content's size here.
70 _image.reset (new J2KImageProxy (path, _image_content->video->size(), pf));
72 _image.reset (new FFmpegImageProxy (path));
76 video->emit (film(), _image, _frame_video_position);
77 ++_frame_video_position;
82 ImageDecoder::seek (ContentTime time, bool accurate)
84 Decoder::seek (time, accurate);
85 _frame_video_position = time.frames_round (_image_content->active_video_frame_rate(film()));