#include <iostream>
#include <boost/filesystem.hpp>
#include <Magick++.h>
+#include "imagemagick_content.h"
#include "imagemagick_decoder.h"
#include "image.h"
#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)
+ImageMagickDecoder::ImageMagickDecoder (shared_ptr<const Film> f, shared_ptr<const ImageMagickContent> c)
+ : Decoder (f)
+ , VideoDecoder (f)
+ , _imagemagick_content (c)
+ , _position (0)
{
- if (boost::filesystem::is_directory (_film->content_path())) {
- for (
- boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator (_film->content_path());
- i != boost::filesystem::directory_iterator();
- ++i) {
-
- if (still_image_file (i->path().string())) {
- _files.push_back (i->path().string());
- }
- }
- } else {
- _files.push_back (_film->content_path ());
- }
-
- _iter = _files.begin ();
+
}
-Size
+libdcp::Size
ImageMagickDecoder::native_size () const
{
- if (_files.empty ()) {
- 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());
+ Magick::Image* image = new Magick::Image (_imagemagick_content->file().string());
+ libdcp::Size const s = libdcp::Size (image->columns(), image->rows());
delete image;
return s;
}
+int
+ImageMagickDecoder::video_length () const
+{
+ return _imagemagick_content->video_length ();
+}
+
bool
ImageMagickDecoder::pass ()
{
- if (_iter == _files.end()) {
+ if (_position < 0 || _position >= _imagemagick_content->video_length ()) {
return true;
}
-
- using namespace MagickCore;
- Magick::Image* magick_image = new Magick::Image (_film->content_path ());
+ if (have_last_video ()) {
+ repeat_last_video (double (_position) / 24);
+ _position++;
+ return false;
+ }
+
+ Magick::Image* magick_image = new Magick::Image (_imagemagick_content->file().string ());
- Size size = native_size ();
- shared_ptr<CompactImage> image (new CompactImage (PIX_FMT_RGB24, size));
+ libdcp::Size size = native_size ();
+ shared_ptr<Image> image (new SimpleImage (PIX_FMT_RGB24, size, false));
+ using namespace MagickCore;
+
uint8_t* p = image->data()[0];
for (int y = 0; y < size.height; ++y) {
for (int x = 0; x < size.width; ++x) {
}
delete magick_image;
+
+ image = image->crop (_film->crop(), true);
- emit_video (image);
+ emit_video (image, double (_position) / 24);
- ++_iter;
+ ++_position;
return false;
}
return PIX_FMT_RGB24;
}
+bool
+ImageMagickDecoder::seek_to_last ()
+{
+ if (_position > 0) {
+ --_position;
+ }
+
+ return false;
+}
+
+bool
+ImageMagickDecoder::seek (double t)
+{
+ int const f = t * _imagemagick_content->video_frame_rate ();
+
+ if (f >= _imagemagick_content->video_length()) {
+ _position = 0;
+ return true;
+ }
+
+ _position = f;
+ return false;
+}