2 Copyright (C) 2013-2015 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 "image_content.h"
21 #include "image_examiner.h"
22 #include "compose.hpp"
25 #include "frame_rate_change.h"
26 #include "exceptions.h"
27 #include "safe_stringstream.h"
28 #include <libcxml/cxml.h>
29 #include <libxml++/libxml++.h>
30 #include <boost/foreach.hpp>
35 #include "image_filename_sorter.cc"
39 using boost::shared_ptr;
41 ImageContent::ImageContent (shared_ptr<const Film> film, boost::filesystem::path p)
45 if (boost::filesystem::is_regular_file (p) && valid_image_file (p)) {
48 for (boost::filesystem::directory_iterator i(p); i != boost::filesystem::directory_iterator(); ++i) {
49 if (boost::filesystem::is_regular_file (i->path()) && valid_image_file (i->path())) {
50 _paths.push_back (i->path ());
55 throw FileError (_("No valid image files were found in the folder."), p);
58 sort (_paths.begin(), _paths.end(), ImageFilenameSorter ());
63 ImageContent::ImageContent (shared_ptr<const Film> film, cxml::ConstNodePtr node, int version)
64 : Content (film, node)
65 , VideoContent (film, node, version)
71 ImageContent::summary () const
73 string s = path_summary () + " ";
74 /* Get the string() here so that the name does not have quotes around it */
78 s += _("[moving images]");
85 ImageContent::technical_summary () const
87 string s = Content::technical_summary() + " - "
88 + VideoContent::technical_summary() + " - ";
100 ImageContent::as_xml (xmlpp::Node* node) const
102 node->add_child("Type")->add_child_text ("Image");
103 Content::as_xml (node);
104 VideoContent::as_xml (node);
108 ImageContent::examine (shared_ptr<Job> job)
110 Content::examine (job);
112 shared_ptr<const Film> film = _film.lock ();
113 DCPOMATIC_ASSERT (film);
115 shared_ptr<ImageExaminer> examiner (new ImageExaminer (film, shared_from_this(), job));
116 take_from_video_examiner (examiner);
120 ImageContent::set_video_length (Frame len)
123 boost::mutex::scoped_lock lm (_mutex);
127 signal_changed (ContentProperty::LENGTH);
131 ImageContent::full_length () const
133 shared_ptr<const Film> film = _film.lock ();
134 DCPOMATIC_ASSERT (film);
135 FrameRateChange const frc (video_frame_rate(), film->video_frame_rate());
136 return DCPTime::from_frames (llrint (video_length_after_3d_combine() * frc.factor ()), film->video_frame_rate ());
140 ImageContent::identifier () const
143 s << VideoContent::identifier ();
144 s << "_" << video_length();
149 ImageContent::still () const
151 return number_of_paths() == 1;
155 ImageContent::set_video_frame_rate (float r)
158 boost::mutex::scoped_lock lm (_mutex);
159 if (_video_frame_rate == r) {
163 _video_frame_rate = r;
166 signal_changed (VideoContentProperty::VIDEO_FRAME_RATE);
170 ImageContent::set_default_colour_conversion ()
172 BOOST_FOREACH (boost::filesystem::path i, _paths) {
173 if (valid_j2k_file (i)) {
174 /* We default to no colour conversion if we have JPEG2000 files */
175 unset_colour_conversion ();
180 bool const s = still ();
182 boost::mutex::scoped_lock lm (_mutex);
185 _colour_conversion = PresetColourConversion::from_id ("srgb").conversion;
187 _colour_conversion = PresetColourConversion::from_id ("rec709").conversion;