Merge master.
[dcpomatic.git] / src / lib / image_examiner.cc
index 2d150583a1186570e222fd4f15557a01097d487d..75ccb6a3e91fd3e21207ce26872f69f187b95170 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2013-2014 Carl Hetherington <cth@carlh.net>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -18,7 +18,6 @@
 */
 
 #include <iostream>
-#include <boost/lexical_cast.hpp>
 #include <Magick++.h>
 #include "image_content.h"
 #include "image_examiner.h"
@@ -33,53 +32,26 @@ using std::cout;
 using std::list;
 using std::sort;
 using boost::shared_ptr;
-using boost::lexical_cast;
-using boost::bad_lexical_cast;
 
-ImageExaminer::ImageExaminer (shared_ptr<const Film> film, shared_ptr<const ImageContent> content, shared_ptr<Job> job)
+ImageExaminer::ImageExaminer (shared_ptr<const Film> film, shared_ptr<const ImageContent> content, shared_ptr<Job>)
        : _film (film)
        , _image_content (content)
-       , _video_length (0)
 {
-       list<unsigned int> frames;
-       size_t const N = content->number_of_paths ();
-
-       for (size_t i = 0; i < N; ++i) {
-               boost::filesystem::path const p = content->path (i);
-               try {
-                       frames.push_back (lexical_cast<int> (p.stem().string()));
-               } catch (bad_lexical_cast &) {
-                       /* We couldn't turn that filename into a number; never mind */
-               }
-               
-               if (!_video_size) {
-                       using namespace MagickCore;
-                       Magick::Image* image = new Magick::Image (p.string());
-                       _video_size = libdcp::Size (image->columns(), image->rows());
-                       delete image;
-               }
-       
-               job->set_progress (float (i) / N);
-       }
-
-       frames.sort ();
-       
-       if (N > 1 && frames.front() != 0 && frames.front() != 1) {
-               throw StringError (String::compose (_("first frame in moving image directory is number %1"), frames.front ()));
-       }
-
-       if (N > 1 && frames.back() != frames.size() && frames.back() != (frames.size() - 1)) {
-               throw StringError (String::compose (_("there are %1 images in the directory but the last one is number %2"), frames.size(), frames.back ()));
-       }
+#ifdef DCPOMATIC_IMAGE_MAGICK  
+       using namespace MagickCore;
+#endif 
+       Magick::Image* image = new Magick::Image (content->path(0).string());
+       _video_size = dcp::Size (image->columns(), image->rows());
+       delete image;
 
        if (content->still ()) {
-               _video_length = Config::instance()->default_still_length() * video_frame_rate();
+               _video_length = ContentTime::from_seconds (Config::instance()->default_still_length());
        } else {
-               _video_length = _image_content->number_of_paths ();
+               _video_length = ContentTime::from_frames (_image_content->number_of_paths (), video_frame_rate ());
        }
 }
 
-libdcp::Size
+dcp::Size
 ImageExaminer::video_size () const
 {
        return _video_size.get ();