2 Copyright (C) 2013-2018 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 "video_content.h"
23 #include "image_examiner.h"
24 #include "compose.hpp"
27 #include "frame_rate_change.h"
28 #include "exceptions.h"
29 #include "image_filename_sorter.h"
30 #include <libcxml/cxml.h>
31 #include <libxml++/libxml++.h>
40 using std::shared_ptr;
41 using namespace dcpomatic;
43 ImageContent::ImageContent (boost::filesystem::path p)
45 video.reset (new VideoContent (this));
47 if (boost::filesystem::is_regular_file (p) && valid_image_file (p)) {
53 set_default_colour_conversion ();
57 ImageContent::ImageContent (cxml::ConstNodePtr node, int version)
60 video = VideoContent::from_xml (this, node, version);
64 ImageContent::summary () const
66 string s = path_summary () + " ";
67 /* Get the string() here so that the name does not have quotes around it */
71 s += _("[moving images]");
78 ImageContent::technical_summary () const
80 string s = Content::technical_summary() + " - "
81 + video->technical_summary() + " - ";
93 ImageContent::as_xml (xmlpp::Node* node, bool with_paths) const
95 node->add_child("Type")->add_child_text ("Image");
96 Content::as_xml (node, with_paths);
104 ImageContent::examine (shared_ptr<const Film> film, shared_ptr<Job> job)
107 job->sub (_("Scanning image files"));
108 vector<boost::filesystem::path> paths;
110 for (boost::filesystem::directory_iterator i(*_path_to_scan); i != boost::filesystem::directory_iterator(); ++i) {
111 if (boost::filesystem::is_regular_file (i->path()) && valid_image_file (i->path())) {
112 paths.push_back (i->path());
115 if ((n % 1000) == 0) {
116 job->set_progress_unknown ();
121 throw FileError (_("No valid image files were found in the folder."), *_path_to_scan);
124 sort (paths.begin(), paths.end(), ImageFilenameSorter());
128 Content::examine (film, job);
130 shared_ptr<ImageExaminer> examiner (new ImageExaminer (film, shared_from_this(), job));
131 video->take_from_examiner (examiner);
132 set_default_colour_conversion ();
136 ImageContent::full_length (shared_ptr<const Film> film) const
138 FrameRateChange const frc (film, shared_from_this());
139 return DCPTime::from_frames (llrint(video->length_after_3d_combine() * frc.factor()), film->video_frame_rate());
143 ImageContent::approximate_length () const
145 return DCPTime::from_frames (video->length_after_3d_combine(), 24);
149 ImageContent::identifier () const
152 snprintf (buffer, sizeof(buffer), "%s_%s_%" PRId64, Content::identifier().c_str(), video->identifier().c_str(), video->length());
157 ImageContent::still () const
159 return number_of_paths() == 1;
163 ImageContent::set_default_colour_conversion ()
165 for (auto i: paths()) {
166 if (valid_j2k_file (i)) {
167 /* We default to no colour conversion if we have JPEG2000 files */
168 video->unset_colour_conversion ();
173 bool const s = still ();
175 boost::mutex::scoped_lock lm (_mutex);
178 video->set_colour_conversion (PresetColourConversion::from_id ("srgb").conversion);
180 video->set_colour_conversion (PresetColourConversion::from_id ("rec709").conversion);
185 ImageContent::add_properties (shared_ptr<const Film> film, list<UserProperty>& p) const
187 Content::add_properties (film, p);
188 video->add_properties (p);