X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fimage_decoder.cc;h=5de0c8582facb1aca80ed8d03479bdf2928331d4;hb=9c5a7319d807063c22d6bc165ee414ce82e26965;hp=9e90b5bc8317cccd5d46b4c36912fd6872653337;hpb=a5b59faff75265d3256ad0dbd9f0c69e51e31ce4;p=dcpomatic.git diff --git a/src/lib/image_decoder.cc b/src/lib/image_decoder.cc index 9e90b5bc8..5de0c8582 100644 --- a/src/lib/image_decoder.cc +++ b/src/lib/image_decoder.cc @@ -30,13 +30,11 @@ using std::cout; using boost::shared_ptr; -using libdcp::Size; +using dcp::Size; -ImageDecoder::ImageDecoder (shared_ptr f, shared_ptr c) - : Decoder (f) - , VideoDecoder (f, c) +ImageDecoder::ImageDecoder (shared_ptr c) + : VideoDecoder (c) , _image_content (c) - , _video_position (0) { } @@ -44,18 +42,27 @@ ImageDecoder::ImageDecoder (shared_ptr f, shared_ptr= _image_content->video_length ()) { + 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 * TIME_HZ / _video_content->video_frame_rate ()); + video (_image, _video_position); ++_video_position; return false; } - Magick::Image* magick_image = new Magick::Image (_image_content->path (_image_content->still() ? 0 : _video_position).string ()); - libdcp::Size size (magick_image->columns(), magick_image->rows()); + Magick::Image* magick_image = 0; + + boost::filesystem::path const path = _image_content->path (_image_content->still() ? 0 : _video_position); + + try { + magick_image = new Magick::Image (path.string ()); + } catch (...) { + throw OpenFileError (path); + } + + dcp::Size size (magick_image->columns(), magick_image->rows()); _image.reset (new Image (PIX_FMT_RGB24, size, true)); @@ -75,7 +82,7 @@ ImageDecoder::pass () delete magick_image; - video (_image, false, _video_position * TIME_HZ / _video_content->video_frame_rate ()); + video (_image, _video_position); ++_video_position; return false; @@ -84,7 +91,6 @@ ImageDecoder::pass () void ImageDecoder::seek (ContentTime time, bool accurate) { - Decoder::seek (time, accurate); - - _video_position = rint (time * _video_content->video_frame_rate() / TIME_HZ); + VideoDecoder::seek (time, accurate); + _video_position = time.frames (_image_content->video_frame_rate ()); }