Make MovingImageContent use Content::_paths rather than its own _files list.
authorCarl Hetherington <cth@carlh.net>
Fri, 22 Nov 2013 15:49:54 +0000 (15:49 +0000)
committerCarl Hetherington <cth@carlh.net>
Fri, 22 Nov 2013 15:49:54 +0000 (15:49 +0000)
src/lib/content.cc
src/lib/content.h
src/lib/moving_image_content.cc
src/lib/moving_image_content.h
src/lib/moving_image_decoder.cc
src/lib/moving_image_examiner.cc
src/lib/moving_image_examiner.h
src/lib/video_content.cc
src/lib/video_content.h

index c8f836d18d5dc8edcc8920f7d75963aa9d54d282..4e54533ed29189c5b9500c3404ddc0cf843b62f0 100644 (file)
@@ -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)
index ad3e8ff4518b0d7bef7b52dedf1876c6164ca5fe..5d8100e5db825e021dfd1ca7a09b6909ce830ef6 100644 (file)
@@ -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;
index dd486b0a7943c85899ec5b928edc08bcac2090d1..23d18240b97dcfe5f1911ea7fb1dd4928a01a00b 100644 (file)
@@ -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
index 1a64750fe5692f8ae9f1212a0f338b190359adc9..f6a7778be1769241c42dc170f3542bb937a06fe5 100644 (file)
@@ -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
index 0960960634c8442d08bb19e8f998f9a0c55af8c3..4bfc7c1306d2cecbc69d35428cb9104bffd32b0a 100644 (file)
@@ -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;
index 87246832d4752533eb7692f16c5b7cf0c9a6e85d..029c441041784fdf72adc011dda9b288a047abfe 100644 (file)
@@ -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 ()));
index db6845ee515de07de94f1a1990bb64e88bb10c80..4c2cfa003fb183f192bcee712798c053f110a0a6 100644 (file)
@@ -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;
 };
index d0eab4dbf93f870344b7c34228ed14d7813ad26d..743e6eb18661f3ed88b0c4939bf36e725ff064fe 100644 (file)
@@ -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)
index 106adf959cf4ff43f3cd039acd15dd493a633533..0fc6d4e7aa6645ba8b0b03a4f5c1a5542321d46b 100644 (file)
@@ -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>);