#include "image_content.h"
#include "image_decoder.h"
#include "image.h"
-#include "image_proxy.h"
+#include "magick_image_proxy.h"
+#include "j2k_image_proxy.h"
#include "film.h"
#include "exceptions.h"
using std::cout;
using boost::shared_ptr;
-using libdcp::Size;
+using dcp::Size;
-ImageDecoder::ImageDecoder (shared_ptr<const Film> f, shared_ptr<const ImageContent> c)
- : Decoder (f)
- , VideoDecoder (f, c)
+ImageDecoder::ImageDecoder (shared_ptr<const ImageContent> c)
+ : VideoDecoder (c)
, _image_content (c)
+ , _video_position (0)
{
}
-void
+bool
ImageDecoder::pass ()
{
- if (_video_position >= _image_content->video_length ()) {
- return;
+ if (_video_position >= _image_content->video_length().frames (_image_content->video_frame_rate ())) {
+ return true;
}
- if (_image && _image_content->still ()) {
- video (_image, true, _video_position);
- return;
+ if (!_image_content->still() || !_image) {
+ /* Either we need an image or we are using moving images, so load one */
+ 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));
+ }
}
-
- _image.reset (new MagickImageProxy (_image_content->path (_image_content->still() ? 0 : _video_position)));
- video (_image, false, _video_position);
+
+ video (_image, _video_position);
+ ++_video_position;
+ return false;
}
void
-ImageDecoder::seek (VideoContent::Frame frame, bool)
-{
- _video_position = frame;
-}
-
-bool
-ImageDecoder::done () const
+ImageDecoder::seek (ContentTime time, bool accurate)
{
- return _video_position >= _image_content->video_length ();
+ VideoDecoder::seek (time, accurate);
+ _video_position = time.frames (_image_content->video_frame_rate ());
}