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 "video_content.h"
22 #include "image_examiner.h"
23 #include "compose.hpp"
26 #include "frame_rate_change.h"
27 #include "exceptions.h"
28 #include "safe_stringstream.h"
29 #include "image_filename_sorter.h"
30 #include <libcxml/cxml.h>
31 #include <libxml++/libxml++.h>
32 #include <boost/foreach.hpp>
39 using boost::shared_ptr;
41 ImageContent::ImageContent (shared_ptr<const Film> film, boost::filesystem::path p)
44 video.reset (new VideoContent (this, film));
46 if (boost::filesystem::is_regular_file (p) && valid_image_file (p)) {
49 for (boost::filesystem::directory_iterator i(p); i != boost::filesystem::directory_iterator(); ++i) {
50 if (boost::filesystem::is_regular_file (i->path()) && valid_image_file (i->path())) {
51 _paths.push_back (i->path ());
56 throw FileError (_("No valid image files were found in the folder."), p);
59 sort (_paths.begin(), _paths.end(), ImageFilenameSorter ());
62 set_default_colour_conversion ();
66 ImageContent::ImageContent (shared_ptr<const Film> film, cxml::ConstNodePtr node, int version)
67 : Content (film, node)
69 video = VideoContent::from_xml (this, film, node, version);
73 ImageContent::summary () const
75 string s = path_summary () + " ";
76 /* Get the string() here so that the name does not have quotes around it */
80 s += _("[moving images]");
87 ImageContent::technical_summary () const
89 string s = Content::technical_summary() + " - "
90 + video->technical_summary() + " - ";
102 ImageContent::as_xml (xmlpp::Node* node) const
104 node->add_child("Type")->add_child_text ("Image");
105 Content::as_xml (node);
106 video->as_xml (node);
110 ImageContent::examine (shared_ptr<Job> job)
112 Content::examine (job);
114 shared_ptr<const Film> film = _film.lock ();
115 DCPOMATIC_ASSERT (film);
117 shared_ptr<ImageExaminer> examiner (new ImageExaminer (film, shared_from_this(), job));
118 video->take_from_examiner (examiner);
119 set_default_colour_conversion ();
123 ImageContent::full_length () const
125 shared_ptr<const Film> film = _film.lock ();
126 DCPOMATIC_ASSERT (film);
127 FrameRateChange const frc (active_video_frame_rate(), film->video_frame_rate());
128 return DCPTime::from_frames (llrint (video->length_after_3d_combine() * frc.factor ()), film->video_frame_rate ());
132 ImageContent::identifier () const
135 s << Content::identifier();
136 s << "_" << video->identifier ();
137 s << "_" << video->length();
142 ImageContent::still () const
144 return number_of_paths() == 1;
148 ImageContent::set_default_colour_conversion ()
150 BOOST_FOREACH (boost::filesystem::path i, _paths) {
151 if (valid_j2k_file (i)) {
152 /* We default to no colour conversion if we have JPEG2000 files */
153 video->unset_colour_conversion ();
158 bool const s = still ();
160 boost::mutex::scoped_lock lm (_mutex);
163 video->set_colour_conversion (PresetColourConversion::from_id ("srgb").conversion);
165 video->set_colour_conversion (PresetColourConversion::from_id ("rec709").conversion);