f45b53e8f5d13f3dd3eecd14bfd44a12fb788d4e from master; ignore ._ files.
[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 "compose.hpp"
24 #include "film.h"
25 #include "job.h"
26 #include "frame_rate_change.h"
27 #include "exceptions.h"
28 #include "safe_stringstream.h"
29
30 #include "i18n.h"
31
32 #include "image_filename_sorter.cc"
33
34 using std::string;
35 using std::cout;
36 using boost::shared_ptr;
37
38 ImageContent::ImageContent (shared_ptr<const Film> f, boost::filesystem::path p)
39         : Content (f)
40         , VideoContent (f)
41 {
42         bool have_j2k = false;
43         if (boost::filesystem::is_regular_file (p) && valid_image_file (p)) {
44                 _paths.push_back (p);
45                 if (valid_j2k_file (p)) {
46                         have_j2k = true;
47                 }
48         } else {
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 ())) {
53                                         have_j2k = true;
54                                 }
55                         }
56                 }
57
58                 if (_paths.empty()) {
59                         throw FileError (_("No valid image files were found in the folder."), p);
60                 }
61                                 
62                 sort (_paths.begin(), _paths.end(), ImageFilenameSorter ());
63         }
64
65         if (have_j2k) {
66                 /* We default to no colour conversion if we have JPEG2000 files */
67                 unset_colour_conversion (false);
68         }
69 }
70
71
72 ImageContent::ImageContent (shared_ptr<const Film> f, cxml::ConstNodePtr node, int version)
73         : Content (f, node)
74         , VideoContent (f, node, version)
75 {
76         
77 }
78
79 string
80 ImageContent::summary () const
81 {
82         string s = path_summary () + " ";
83         /* Get the string() here so that the name does not have quotes around it */
84         if (still ()) {
85                 s += _("[still]");
86         } else {
87                 s += _("[moving images]");
88         }
89
90         return s;
91 }
92
93 string
94 ImageContent::technical_summary () const
95 {
96         string s = Content::technical_summary() + " - "
97                 + VideoContent::technical_summary() + " - ";
98
99         if (still ()) {
100                 s += _("still");
101         } else {
102                 s += _("moving");
103         }
104
105         return s;
106 }
107
108 void
109 ImageContent::as_xml (xmlpp::Node* node) const
110 {
111         node->add_child("Type")->add_child_text ("Image");
112         Content::as_xml (node);
113         VideoContent::as_xml (node);
114 }
115
116 void
117 ImageContent::examine (shared_ptr<Job> job)
118 {
119         Content::examine (job);
120
121         shared_ptr<const Film> film = _film.lock ();
122         DCPOMATIC_ASSERT (film);
123         
124         shared_ptr<ImageExaminer> examiner (new ImageExaminer (film, shared_from_this(), job));
125         take_from_video_examiner (examiner);
126 }
127
128 void
129 ImageContent::set_video_length (ContentTime len)
130 {
131         {
132                 boost::mutex::scoped_lock lm (_mutex);
133                 _video_length = len;
134         }
135
136         signal_changed (ContentProperty::LENGTH);
137 }
138
139 DCPTime
140 ImageContent::full_length () const
141 {
142         shared_ptr<const Film> film = _film.lock ();
143         DCPOMATIC_ASSERT (film);
144         return DCPTime (video_length_after_3d_combine(), FrameRateChange (video_frame_rate(), film->video_frame_rate()));
145 }
146
147 string
148 ImageContent::identifier () const
149 {
150         SafeStringStream s;
151         s << VideoContent::identifier ();
152         s << "_" << video_length().get();
153         return s.str ();
154 }
155
156 bool
157 ImageContent::still () const
158 {
159         return number_of_paths() == 1;
160 }
161
162 void
163 ImageContent::set_video_frame_rate (float r)
164 {
165         {
166                 boost::mutex::scoped_lock lm (_mutex);
167                 if (_video_frame_rate == r) {
168                         return;
169                 }
170                 
171                 _video_frame_rate = r;
172         }
173         
174         signal_changed (VideoContentProperty::VIDEO_FRAME_RATE);
175 }
176