diff options
| author | Carl Hetherington <cth@carlh.net> | 2013-11-22 15:49:54 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2013-11-22 15:49:54 +0000 |
| commit | af474db6af17d468b42fbae8bd4c3e80dcfd0588 (patch) | |
| tree | e7cf2ccb4d14d7121a9a65f5989e4bc66275737d /src | |
| parent | 68808da4a0f8c60ac93cd0bbc3ea776d16503a6a (diff) | |
Make MovingImageContent use Content::_paths rather than its own _files list.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/content.cc | 10 | ||||
| -rw-r--r-- | src/lib/content.h | 14 | ||||
| -rw-r--r-- | src/lib/moving_image_content.cc | 22 | ||||
| -rw-r--r-- | src/lib/moving_image_content.h | 7 | ||||
| -rw-r--r-- | src/lib/moving_image_decoder.cc | 15 | ||||
| -rw-r--r-- | src/lib/moving_image_examiner.cc | 39 | ||||
| -rw-r--r-- | src/lib/moving_image_examiner.h | 5 | ||||
| -rw-r--r-- | src/lib/video_content.cc | 10 | ||||
| -rw-r--r-- | src/lib/video_content.h | 1 |
9 files changed, 63 insertions, 60 deletions
diff --git a/src/lib/content.cc b/src/lib/content.cc index c8f836d18..4e54533ed 100644 --- a/src/lib/content.cc +++ b/src/lib/content.cc @@ -37,6 +37,16 @@ int const ContentProperty::LENGTH = 402; int const ContentProperty::TRIM_START = 403; int const ContentProperty::TRIM_END = 404; +Content::Content (shared_ptr<const Film> f) + : _film (f) + , _position (0) + , _trim_start (0) + , _trim_end (0) + , _change_signals_frequent (false) +{ + +} + Content::Content (shared_ptr<const Film> f, Time p) : _film (f) , _position (p) diff --git a/src/lib/content.h b/src/lib/content.h index ad3e8ff45..5d8100e5d 100644 --- a/src/lib/content.h +++ b/src/lib/content.h @@ -48,6 +48,7 @@ public: class Content : public boost::enable_shared_from_this<Content>, public boost::noncopyable { public: + Content (boost::shared_ptr<const Film>); Content (boost::shared_ptr<const Film>, Time); Content (boost::shared_ptr<const Film>, boost::filesystem::path); Content (boost::shared_ptr<const Film>, boost::shared_ptr<const cxml::Node>); @@ -70,6 +71,16 @@ public: return _paths.front (); } + size_t number_of_paths () const { + boost::mutex::scoped_lock lm (_mutex); + return _paths.size (); + } + + boost::filesystem::path path (size_t i) const { + boost::mutex::scoped_lock lm (_mutex); + return _paths[i]; + } + bool path_valid () const; /** @return MD5 digest of the content's file(s) */ @@ -126,9 +137,10 @@ protected: */ mutable boost::mutex _mutex; -private: /** Paths of our data files */ std::vector<boost::filesystem::path> _paths; + +private: std::string _digest; Time _position; Time _trim_start; diff --git a/src/lib/moving_image_content.cc b/src/lib/moving_image_content.cc index dd486b0a7..23d18240b 100644 --- a/src/lib/moving_image_content.cc +++ b/src/lib/moving_image_content.cc @@ -35,20 +35,23 @@ using std::vector; using boost::shared_ptr; MovingImageContent::MovingImageContent (shared_ptr<const Film> f, boost::filesystem::path p) - : Content (f, p) - , VideoContent (f, p) + : Content (f) + , VideoContent (f) { + for (boost::filesystem::directory_iterator i(p); i != boost::filesystem::directory_iterator(); ++i) { + if (boost::filesystem::is_regular_file (i->path()) && valid_image_file (i->path())) { + _paths.push_back (i->path ()); + } + } + sort (_paths.begin(), _paths.end()); } MovingImageContent::MovingImageContent (shared_ptr<const Film> f, shared_ptr<const cxml::Node> node) : Content (f, node) , VideoContent (f, node) { - list<cxml::NodePtr> c = node->node_children ("File"); - for (list<cxml::NodePtr>::const_iterator i = c.begin(); i != c.end(); ++i) { - _files.push_back ((*i)->content ()); - } + } string @@ -72,10 +75,6 @@ MovingImageContent::as_xml (xmlpp::Node* node) const node->add_child("Type")->add_child_text ("MovingImage"); Content::as_xml (node); VideoContent::as_xml (node); - - for (vector<boost::filesystem::path>::const_iterator i = _files.begin(); i != _files.end(); ++i) { - node->add_child("File")->add_child_text (i->filename().string()); - } } void @@ -92,8 +91,7 @@ MovingImageContent::examine (shared_ptr<Job> job) take_from_video_examiner (examiner); - _video_length = examiner->files().size (); - _files = examiner->files (); + _video_length = number_of_paths (); } Time diff --git a/src/lib/moving_image_content.h b/src/lib/moving_image_content.h index 1a64750fe..f6a7778be 100644 --- a/src/lib/moving_image_content.h +++ b/src/lib/moving_image_content.h @@ -45,13 +45,6 @@ public: Time full_length () const; std::string identifier () const; - - std::vector<boost::filesystem::path> const & files () const { - return _files; - } - -private: - std::vector<boost::filesystem::path> _files; }; #endif diff --git a/src/lib/moving_image_decoder.cc b/src/lib/moving_image_decoder.cc index 096096063..4bfc7c130 100644 --- a/src/lib/moving_image_decoder.cc +++ b/src/lib/moving_image_decoder.cc @@ -47,24 +47,23 @@ MovingImageDecoder::pass () return; } - boost::filesystem::path path = _moving_image_content->path (); - path /= _moving_image_content->files()[_video_position]; - - Magick::Image* magick_image = new Magick::Image (path.string()); + Magick::Image* magick_image = new Magick::Image (_moving_image_content->path(_video_position).string ()); libdcp::Size size (magick_image->columns(), magick_image->rows()); - shared_ptr<Image> image (new Image (PIX_FMT_RGB24, size, false)); + shared_ptr<Image> image (new Image (PIX_FMT_RGB24, size, true)); using namespace MagickCore; uint8_t* p = image->data()[0]; for (int y = 0; y < size.height; ++y) { + uint8_t* q = p; for (int x = 0; x < size.width; ++x) { Magick::Color c = magick_image->pixelColor (x, y); - *p++ = c.redQuantum() * 255 / QuantumRange; - *p++ = c.greenQuantum() * 255 / QuantumRange; - *p++ = c.blueQuantum() * 255 / QuantumRange; + *q++ = c.redQuantum() * 255 / QuantumRange; + *q++ = c.greenQuantum() * 255 / QuantumRange; + *q++ = c.blueQuantum() * 255 / QuantumRange; } + p += image->stride()[0]; } delete magick_image; diff --git a/src/lib/moving_image_examiner.cc b/src/lib/moving_image_examiner.cc index 87246832d..029c44104 100644 --- a/src/lib/moving_image_examiner.cc +++ b/src/lib/moving_image_examiner.cc @@ -40,39 +40,24 @@ MovingImageExaminer::MovingImageExaminer (shared_ptr<const Film> film, shared_pt , _video_length (0) { list<unsigned int> frames; - unsigned int files = 0; - - for (boost::filesystem::directory_iterator i(content->path()); i != boost::filesystem::directory_iterator(); ++i) { - if (boost::filesystem::is_regular_file (i->path ())) { - ++files; - } - } + size_t const N = content->number_of_paths (); int j = 0; - for (boost::filesystem::directory_iterator i(content->path()); i != boost::filesystem::directory_iterator(); ++i) { - if (!boost::filesystem::is_regular_file (i->path ())) { - continue; + for (size_t i = 0; i < N; ++i) { + boost::filesystem::path const p = content->path (i); + frames.push_back (lexical_cast<int> (p.stem().string())); + + if (!_video_size) { + using namespace MagickCore; + Magick::Image* image = new Magick::Image (p.string()); + _video_size = libdcp::Size (image->columns(), image->rows()); + delete image; } - - if (valid_image_file (i->path ())) { - int n = lexical_cast<int> (i->path().stem().string()); - frames.push_back (n); - _files.push_back (i->path().filename ()); - - if (!_video_size) { - using namespace MagickCore; - Magick::Image* image = new Magick::Image (i->path().string()); - _video_size = libdcp::Size (image->columns(), image->rows()); - delete image; - } - } - - job->set_progress (float (j) / files); - ++j; + + job->set_progress (float (i) / N); } frames.sort (); - sort (_files.begin(), _files.end ()); if (frames.size() < 2) { throw StringError (String::compose (_("only %1 file(s) found in moving image directory"), frames.size ())); diff --git a/src/lib/moving_image_examiner.h b/src/lib/moving_image_examiner.h index db6845ee5..4c2cfa003 100644 --- a/src/lib/moving_image_examiner.h +++ b/src/lib/moving_image_examiner.h @@ -35,13 +35,8 @@ public: libdcp::Size video_size () const; VideoContent::Frame video_length () const; - std::vector<boost::filesystem::path> const & files () const { - return _files; - } - private: boost::weak_ptr<const Film> _film; boost::optional<libdcp::Size> _video_size; VideoContent::Frame _video_length; - std::vector<boost::filesystem::path> _files; }; diff --git a/src/lib/video_content.cc b/src/lib/video_content.cc index d0eab4dbf..743e6eb18 100644 --- a/src/lib/video_content.cc +++ b/src/lib/video_content.cc @@ -46,6 +46,16 @@ using boost::shared_ptr; using boost::lexical_cast; using boost::optional; +VideoContent::VideoContent (shared_ptr<const Film> f) + : Content (f) + , _video_length (0) + , _video_frame_rate (0) + , _video_frame_type (VIDEO_FRAME_TYPE_2D) + , _ratio (Ratio::from_id ("185")) +{ + setup_default_colour_conversion (); +} + VideoContent::VideoContent (shared_ptr<const Film> f, Time s, VideoContent::Frame len) : Content (f, s) , _video_length (len) diff --git a/src/lib/video_content.h b/src/lib/video_content.h index 106adf959..0fc6d4e7a 100644 --- a/src/lib/video_content.h +++ b/src/lib/video_content.h @@ -42,6 +42,7 @@ class VideoContent : public virtual Content public: typedef int Frame; + VideoContent (boost::shared_ptr<const Film>); VideoContent (boost::shared_ptr<const Film>, Time, VideoContent::Frame); VideoContent (boost::shared_ptr<const Film>, boost::filesystem::path); VideoContent (boost::shared_ptr<const Film>, boost::shared_ptr<const cxml::Node>); |
