Merge master.
[dcpomatic.git] / src / lib / image_content.cc
1 /*
2     Copyright (C) 2013-2014 Carl Hetherington <cth@carlh.net>
3
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.
8
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.
13
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.
17
18 */
19
20 #include <libcxml/cxml.h>
21 #include "image_content.h"
22 #include "image_examiner.h"
23 #include "config.h"
24 #include "compose.hpp"
25 #include "film.h"
26 #include "job.h"
27
28 #include "i18n.h"
29
30 using std::string;
31 using std::cout;
32 using std::stringstream;
33 using boost::shared_ptr;
34
35 ImageContent::ImageContent (shared_ptr<const Film> f, boost::filesystem::path p)
36         : Content (f)
37         , VideoContent (f)
38 {
39         if (boost::filesystem::is_regular_file (p)) {
40                 _paths.push_back (p);
41         } else {
42                 for (boost::filesystem::directory_iterator i(p); i != boost::filesystem::directory_iterator(); ++i) {
43                         if (boost::filesystem::is_regular_file (i->path()) && valid_image_file (i->path())) {
44                                 _paths.push_back (i->path ());
45                         }
46                 }
47                 
48                 sort (_paths.begin(), _paths.end());
49         }
50 }
51
52
53 ImageContent::ImageContent (shared_ptr<const Film> f, shared_ptr<const cxml::Node> node, int version)
54         : Content (f, node)
55         , VideoContent (f, node, version)
56 {
57         
58 }
59
60 string
61 ImageContent::summary () const
62 {
63         string s = path_summary () + " ";
64         /* Get the string() here so that the name does not have quotes around it */
65         if (still ()) {
66                 s += _("[still]");
67         } else {
68                 s += _("[moving images]");
69         }
70
71         return s;
72 }
73
74 string
75 ImageContent::technical_summary () const
76 {
77         string s = Content::technical_summary() + " - "
78                 + VideoContent::technical_summary() + " - ";
79
80         if (still ()) {
81                 s += _("still");
82         } else {
83                 s += _("moving");
84         }
85
86         return s;
87 }
88
89 void
90 ImageContent::as_xml (xmlpp::Node* node) const
91 {
92         node->add_child("Type")->add_child_text ("Image");
93         Content::as_xml (node);
94         VideoContent::as_xml (node);
95 }
96
97 void
98 ImageContent::examine (shared_ptr<Job> job)
99 {
100         job->sub (_("Computing digest"));
101         Content::examine (job);
102
103         shared_ptr<const Film> film = _film.lock ();
104         assert (film);
105         
106         shared_ptr<ImageExaminer> examiner (new ImageExaminer (film, shared_from_this(), job));
107
108         take_from_video_examiner (examiner);
109         set_video_length (examiner->video_length ());
110 }
111
112 void
113 ImageContent::set_video_length (ContentTime len)
114 {
115         {
116                 boost::mutex::scoped_lock lm (_mutex);
117                 _video_length = len;
118         }
119
120         signal_changed (ContentProperty::LENGTH);
121 }
122
123 DCPTime
124 ImageContent::full_length () const
125 {
126         shared_ptr<const Film> film = _film.lock ();
127         assert (film);
128         return DCPTime (video_length_after_3d_combine(), FrameRateChange (video_frame_rate(), film->video_frame_rate()));
129 }
130
131 string
132 ImageContent::identifier () const
133 {
134         stringstream s;
135         s << VideoContent::identifier ();
136         s << "_" << video_length().get();
137         return s.str ();
138 }
139
140 bool
141 ImageContent::still () const
142 {
143         return number_of_paths() == 1;
144 }
145
146 void
147 ImageContent::set_video_frame_rate (float r)
148 {
149         {
150                 boost::mutex::scoped_lock lm (_mutex);
151                 if (_video_frame_rate == r) {
152                         return;
153                 }
154                 
155                 _video_frame_rate = r;
156         }
157         
158         signal_changed (VideoContentProperty::VIDEO_FRAME_RATE);
159 }
160