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 <libcxml/cxml.h>
21 #include "image_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"
32 #include "image_filename_sorter.cc"
36 using boost::shared_ptr;
38 ImageContent::ImageContent (shared_ptr<const Film> film, boost::filesystem::path p)
42 bool have_j2k = false;
43 if (boost::filesystem::is_regular_file (p) && valid_image_file (p)) {
45 if (valid_j2k_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 ());
52 if (valid_j2k_file (i->path ())) {
59 throw FileError (_("No valid image files were found in the folder."), p);
62 sort (_paths.begin(), _paths.end(), ImageFilenameSorter ());
66 /* We default to no colour conversion if we have JPEG2000 files */
67 unset_colour_conversion (false);
72 ImageContent::ImageContent (shared_ptr<const Film> film, cxml::ConstNodePtr node, int version)
73 : Content (film, node)
74 , VideoContent (film, node, version)
80 ImageContent::summary () const
82 string s = path_summary () + " ";
83 /* Get the string() here so that the name does not have quotes around it */
87 s += _("[moving images]");
94 ImageContent::technical_summary () const
96 string s = Content::technical_summary() + " - "
97 + VideoContent::technical_summary() + " - ";
109 ImageContent::as_xml (xmlpp::Node* node) const
111 node->add_child("Type")->add_child_text ("Image");
112 Content::as_xml (node);
113 VideoContent::as_xml (node);
117 ImageContent::examine (shared_ptr<Job> job)
119 Content::examine (job);
121 shared_ptr<const Film> film = _film.lock ();
122 DCPOMATIC_ASSERT (film);
124 shared_ptr<ImageExaminer> examiner (new ImageExaminer (film, shared_from_this(), job));
125 take_from_video_examiner (examiner);
129 ImageContent::set_video_length (Frame len)
132 boost::mutex::scoped_lock lm (_mutex);
136 signal_changed (ContentProperty::LENGTH);
140 ImageContent::full_length () const
142 shared_ptr<const Film> film = _film.lock ();
143 DCPOMATIC_ASSERT (film);
144 FrameRateChange const frc (video_frame_rate(), film->video_frame_rate());
145 return DCPTime::from_frames (rint (video_length_after_3d_combine() * frc.factor ()), film->video_frame_rate ());
149 ImageContent::identifier () const
152 s << VideoContent::identifier ();
153 s << "_" << video_length();
158 ImageContent::still () const
160 return number_of_paths() == 1;
164 ImageContent::set_video_frame_rate (float r)
167 boost::mutex::scoped_lock lm (_mutex);
168 if (_video_frame_rate == r) {
172 _video_frame_rate = r;
175 signal_changed (VideoContentProperty::VIDEO_FRAME_RATE);
179 ImageContent::set_default_colour_conversion ()
181 bool const s = still ();
183 boost::mutex::scoped_lock lm (_mutex);
186 _colour_conversion = PresetColourConversion::from_id ("srgb").conversion;
188 _colour_conversion = PresetColourConversion::from_id ("rec709").conversion;