No-op; fix GPL address and use the explicit-program-name version.
[dcpomatic.git] / src / lib / image_content.cc
1 /*
2     Copyright (C) 2013-2015 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
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.
10
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.
15
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/>.
18
19 */
20
21 #include "image_content.h"
22 #include "video_content.h"
23 #include "image_examiner.h"
24 #include "compose.hpp"
25 #include "film.h"
26 #include "job.h"
27 #include "frame_rate_change.h"
28 #include "exceptions.h"
29 #include "safe_stringstream.h"
30 #include "image_filename_sorter.h"
31 #include <libcxml/cxml.h>
32 #include <libxml++/libxml++.h>
33 #include <boost/foreach.hpp>
34 #include <iostream>
35
36 #include "i18n.h"
37
38 using std::string;
39 using std::cout;
40 using boost::shared_ptr;
41
42 ImageContent::ImageContent (shared_ptr<const Film> film, boost::filesystem::path p)
43         : Content (film)
44 {
45         video.reset (new VideoContent (this));
46
47         if (boost::filesystem::is_regular_file (p) && valid_image_file (p)) {
48                 _paths.push_back (p);
49         } else {
50                 for (boost::filesystem::directory_iterator i(p); i != boost::filesystem::directory_iterator(); ++i) {
51                         if (boost::filesystem::is_regular_file (i->path()) && valid_image_file (i->path())) {
52                                 _paths.push_back (i->path ());
53                         }
54                 }
55
56                 if (_paths.empty()) {
57                         throw FileError (_("No valid image files were found in the folder."), p);
58                 }
59
60                 sort (_paths.begin(), _paths.end(), ImageFilenameSorter ());
61         }
62
63         set_default_colour_conversion ();
64 }
65
66
67 ImageContent::ImageContent (shared_ptr<const Film> film, cxml::ConstNodePtr node, int version)
68         : Content (film, node)
69 {
70         video = VideoContent::from_xml (this, node, version);
71 }
72
73 string
74 ImageContent::summary () const
75 {
76         string s = path_summary () + " ";
77         /* Get the string() here so that the name does not have quotes around it */
78         if (still ()) {
79                 s += _("[still]");
80         } else {
81                 s += _("[moving images]");
82         }
83
84         return s;
85 }
86
87 string
88 ImageContent::technical_summary () const
89 {
90         string s = Content::technical_summary() + " - "
91                 + video->technical_summary() + " - ";
92
93         if (still ()) {
94                 s += _("still");
95         } else {
96                 s += _("moving");
97         }
98
99         return s;
100 }
101
102 void
103 ImageContent::as_xml (xmlpp::Node* node) const
104 {
105         node->add_child("Type")->add_child_text ("Image");
106         Content::as_xml (node);
107
108         if (video) {
109                 video->as_xml (node);
110         }
111 }
112
113 void
114 ImageContent::examine (shared_ptr<Job> job)
115 {
116         Content::examine (job);
117
118         shared_ptr<const Film> film = _film.lock ();
119         DCPOMATIC_ASSERT (film);
120
121         shared_ptr<ImageExaminer> examiner (new ImageExaminer (film, shared_from_this(), job));
122         video->take_from_examiner (examiner);
123         set_default_colour_conversion ();
124 }
125
126 DCPTime
127 ImageContent::full_length () const
128 {
129         shared_ptr<const Film> film = _film.lock ();
130         DCPOMATIC_ASSERT (film);
131         FrameRateChange const frc (active_video_frame_rate(), film->video_frame_rate());
132         return DCPTime::from_frames (llrint (video->length_after_3d_combine() * frc.factor ()), film->video_frame_rate ());
133 }
134
135 string
136 ImageContent::identifier () const
137 {
138         SafeStringStream s;
139         s << Content::identifier();
140         s << "_" << video->identifier ();
141         s << "_" << video->length();
142         return s.str ();
143 }
144
145 bool
146 ImageContent::still () const
147 {
148         return number_of_paths() == 1;
149 }
150
151 void
152 ImageContent::set_default_colour_conversion ()
153 {
154         BOOST_FOREACH (boost::filesystem::path i, _paths) {
155                 if (valid_j2k_file (i)) {
156                         /* We default to no colour conversion if we have JPEG2000 files */
157                         video->unset_colour_conversion ();
158                         return;
159                 }
160         }
161
162         bool const s = still ();
163
164         boost::mutex::scoped_lock lm (_mutex);
165
166         if (s) {
167                 video->set_colour_conversion (PresetColourConversion::from_id ("srgb").conversion);
168         } else {
169                 video->set_colour_conversion (PresetColourConversion::from_id ("rec709").conversion);
170         }
171 }