Don't bother decoding video frames when we're seeking around trying to find subtitles.
[dcpomatic.git] / src / lib / image_decoder.cc
index 8702c1a33b18692dbc43b89c9e60ab416ef9e50e..250c8f845b6c2f10141aac2c3c46dd2e7fe55dbd 100644 (file)
@@ -24,6 +24,7 @@
 #include "image_decoder.h"
 #include "image.h"
 #include "magick_image_proxy.h"
+#include "j2k_image_proxy.h"
 #include "film.h"
 #include "exceptions.h"
 
@@ -36,12 +37,13 @@ using dcp::Size;
 ImageDecoder::ImageDecoder (shared_ptr<const ImageContent> c)
        : VideoDecoder (c)
        , _image_content (c)
+       , _video_position (0)
 {
 
 }
 
 bool
-ImageDecoder::pass ()
+ImageDecoder::pass (PassReason)
 {
        if (_video_position >= _image_content->video_length().frames (_image_content->video_frame_rate ())) {
                return true;
@@ -49,7 +51,15 @@ ImageDecoder::pass ()
 
        if (!_image_content->still() || !_image) {
                /* Either we need an image or we are using moving images, so load one */
-               _image.reset (new MagickImageProxy (_image_content->path (_image_content->still() ? 0 : _video_position), _image_content->film()->log ()));
+               boost::filesystem::path path = _image_content->path (_image_content->still() ? 0 : _video_position);
+               if (valid_j2k_file (path)) {
+                       /* We can't extract image size from a JPEG2000 codestream without decoding it,
+                          so pass in the image content's size here.
+                       */
+                       _image.reset (new J2KImageProxy (path, _image_content->video_size ()));
+               } else {
+                       _image.reset (new MagickImageProxy (path));
+               }
        }
                
        video (_image, _video_position);