Try to fix the filter / AVFrame ownership.
[dcpomatic.git] / src / lib / imagemagick_decoder.cc
index bad1fb81314e182ccbc831d19462e33e5cc3fb51..5ce22c29622a403c33425a5ce6e8e9a5f3e26de5 100644 (file)
 #include "film.h"
 #include "exceptions.h"
 
+#include "i18n.h"
+
 using std::cout;
 using boost::shared_ptr;
+using libdcp::Size;
 
 ImageMagickDecoder::ImageMagickDecoder (
-       boost::shared_ptr<Film> f, boost::shared_ptr<const DecodeOptions> o, Job* j)
-       : Decoder (f, o, j)
-       , VideoDecoder (f, o, j)
+       boost::shared_ptr<Film> f, DecodeOptions o)
+       : Decoder (f, o)
+       , VideoDecoder (f, o)
 {
        if (boost::filesystem::is_directory (_film->content_path())) {
                for (
@@ -50,17 +53,17 @@ ImageMagickDecoder::ImageMagickDecoder (
        _iter = _files.begin ();
 }
 
-Size
+libdcp::Size
 ImageMagickDecoder::native_size () const
 {
        if (_files.empty ()) {
-               throw DecodeError ("no still image files found");
+               throw DecodeError (_("no still image files found"));
        }
 
        /* Look at the first file and assume its size holds for all */
        using namespace MagickCore;
        Magick::Image* image = new Magick::Image (_film->content_path ());
-       Size const s = Size (image->columns(), image->rows());
+       libdcp::Size const s = libdcp::Size (image->columns(), image->rows());
        delete image;
 
        return s;
@@ -70,17 +73,17 @@ bool
 ImageMagickDecoder::pass ()
 {
        if (_iter == _files.end()) {
-               if (!_film->dcp_length() || video_frame() >= _film->dcp_length().get()) {
+               if (video_frame() >= _film->still_duration_in_frames()) {
                        return true;
                }
 
-               repeat_last_video ();
+               emit_video (_image, true, double (video_frame()) / frames_per_second());
                return false;
        }
        
        Magick::Image* magick_image = new Magick::Image (_film->content_path ());
        
-       Size size = native_size ();
+       libdcp::Size size = native_size ();
        shared_ptr<Image> image (new SimpleImage (PIX_FMT_RGB24, size, false));
 
        using namespace MagickCore;
@@ -97,9 +100,9 @@ ImageMagickDecoder::pass ()
 
        delete magick_image;
 
-       image = image->crop (_film->crop(), false);
-       
-       emit_video (image, 0);
+       _image = image->crop (_film->crop(), true);
+
+       emit_video (_image, false, double (video_frame()) / frames_per_second());
 
        ++_iter;
        return false;
@@ -147,3 +150,9 @@ ImageMagickDecoder::film_changed (Film::Property p)
                OutputChanged ();
        }
 }
+
+float
+ImageMagickDecoder::frames_per_second () const
+{
+       return _film->source_frame_rate ();
+}