From ef4cd174472dc1c4694d4451dc60b9292c60666b Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Fri, 22 Nov 2013 18:42:46 +0000 Subject: Merge still/moving image classes. --- src/lib/content.cc | 1 + src/lib/content_factory.cc | 11 ++- src/lib/image_content.cc | 143 +++++++++++++++++++++++++++++++++++++++ src/lib/image_content.h | 52 ++++++++++++++ src/lib/image_decoder.cc | 89 ++++++++++++++++++++++++ src/lib/image_decoder.h | 47 +++++++++++++ src/lib/image_examiner.cc | 97 ++++++++++++++++++++++++++ src/lib/image_examiner.h | 44 ++++++++++++ src/lib/moving_image.h | 35 ---------- src/lib/moving_image_content.cc | 114 ------------------------------- src/lib/moving_image_content.h | 50 -------------- src/lib/moving_image_decoder.cc | 84 ----------------------- src/lib/moving_image_decoder.h | 40 ----------- src/lib/moving_image_examiner.cc | 94 ------------------------- src/lib/moving_image_examiner.h | 42 ------------ src/lib/player.cc | 36 +++------- src/lib/playlist.cc | 3 +- src/lib/still_image.h | 40 ----------- src/lib/still_image_content.cc | 113 ------------------------------- src/lib/still_image_content.h | 52 -------------- src/lib/still_image_decoder.cc | 89 ------------------------ src/lib/still_image_decoder.h | 44 ------------ src/lib/still_image_examiner.cc | 63 ----------------- src/lib/still_image_examiner.h | 41 ----------- src/lib/wscript | 9 +-- 25 files changed, 492 insertions(+), 941 deletions(-) create mode 100644 src/lib/image_content.cc create mode 100644 src/lib/image_content.h create mode 100644 src/lib/image_decoder.cc create mode 100644 src/lib/image_decoder.h create mode 100644 src/lib/image_examiner.cc create mode 100644 src/lib/image_examiner.h delete mode 100644 src/lib/moving_image.h delete mode 100644 src/lib/moving_image_content.cc delete mode 100644 src/lib/moving_image_content.h delete mode 100644 src/lib/moving_image_decoder.cc delete mode 100644 src/lib/moving_image_decoder.h delete mode 100644 src/lib/moving_image_examiner.cc delete mode 100644 src/lib/moving_image_examiner.h delete mode 100644 src/lib/still_image.h delete mode 100644 src/lib/still_image_content.cc delete mode 100644 src/lib/still_image_content.h delete mode 100644 src/lib/still_image_decoder.cc delete mode 100644 src/lib/still_image_decoder.h delete mode 100644 src/lib/still_image_examiner.cc delete mode 100644 src/lib/still_image_examiner.h (limited to 'src/lib') diff --git a/src/lib/content.cc b/src/lib/content.cc index 4e54533ed..a565edb52 100644 --- a/src/lib/content.cc +++ b/src/lib/content.cc @@ -28,6 +28,7 @@ using std::string; using std::stringstream; using std::set; +using std::cout; using boost::shared_ptr; using boost::lexical_cast; diff --git a/src/lib/content_factory.cc b/src/lib/content_factory.cc index ed9a9e769..e800628c1 100644 --- a/src/lib/content_factory.cc +++ b/src/lib/content_factory.cc @@ -19,8 +19,7 @@ #include #include "ffmpeg_content.h" -#include "still_image_content.h" -#include "moving_image_content.h" +#include "image_content.h" #include "sndfile_content.h" #include "util.h" @@ -36,10 +35,8 @@ content_factory (shared_ptr film, cxml::NodePtr node) if (type == "FFmpeg") { content.reset (new FFmpegContent (film, node)); - } else if (type == "StillImage") { - content.reset (new StillImageContent (film, node)); - } else if (type == "MovingImage") { - content.reset (new MovingImageContent (film, node)); + } else if (type == "Image") { + content.reset (new ImageContent (film, node)); } else if (type == "Sndfile") { content.reset (new SndfileContent (film, node)); } @@ -53,7 +50,7 @@ content_factory (shared_ptr film, boost::filesystem::path path) shared_ptr content; if (valid_image_file (path)) { - content.reset (new StillImageContent (film, path)); + content.reset (new ImageContent (film, path)); } else if (SndfileContent::valid_file (path)) { content.reset (new SndfileContent (film, path)); } else { diff --git a/src/lib/image_content.cc b/src/lib/image_content.cc new file mode 100644 index 000000000..9259242a0 --- /dev/null +++ b/src/lib/image_content.cc @@ -0,0 +1,143 @@ +/* + Copyright (C) 2013 Carl Hetherington + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include +#include "image_content.h" +#include "image_examiner.h" +#include "config.h" +#include "compose.hpp" +#include "film.h" +#include "job.h" + +#include "i18n.h" + +using std::string; +using std::cout; +using std::stringstream; +using boost::shared_ptr; + +ImageContent::ImageContent (shared_ptr f, boost::filesystem::path p) + : Content (f) + , VideoContent (f) +{ + if (boost::filesystem::is_regular_file (p)) { + _paths.push_back (p); + } else { + for (boost::filesystem::directory_iterator i(p); i != boost::filesystem::directory_iterator(); ++i) { + if (boost::filesystem::is_regular_file (i->path()) && valid_image_file (i->path())) { + _paths.push_back (i->path ()); + } + } + + sort (_paths.begin(), _paths.end()); + } +} + + +ImageContent::ImageContent (shared_ptr f, shared_ptr node) + : Content (f, node) + , VideoContent (f, node) +{ + +} + +string +ImageContent::summary () const +{ + /* Get the string() here so that the name does not have quotes around it */ + if (still ()) { + return String::compose (_("%1 [still]"), path().filename().string()); + } + + return String::compose (_("%1 [moving images]"), path().filename().string()); +} + +string +ImageContent::technical_summary () const +{ + string s = Content::technical_summary() + " - " + + VideoContent::technical_summary() + " - "; + + if (still ()) { + s += _("still"); + } else { + s += _("moving"); + } + + return s; +} + +void +ImageContent::as_xml (xmlpp::Node* node) const +{ + node->add_child("Type")->add_child_text ("Image"); + Content::as_xml (node); + VideoContent::as_xml (node); +} + +void +ImageContent::examine (shared_ptr job) +{ + job->sub (_("Computing digest")); + Content::examine (job); + + shared_ptr film = _film.lock (); + assert (film); + + shared_ptr examiner (new ImageExaminer (film, shared_from_this(), job)); + + take_from_video_examiner (examiner); + set_video_length (examiner->video_length ()); +} + +void +ImageContent::set_video_length (VideoContent::Frame len) +{ + { + boost::mutex::scoped_lock lm (_mutex); + _video_length = len; + } + + signal_changed (ContentProperty::LENGTH); +} + +Time +ImageContent::full_length () const +{ + shared_ptr film = _film.lock (); + assert (film); + + FrameRateConversion frc (video_frame_rate(), film->video_frame_rate ()); + return video_length() * frc.factor() * TIME_HZ / video_frame_rate(); +} + +string +ImageContent::identifier () const +{ + stringstream s; + s << VideoContent::identifier (); + s << "_" << video_length(); + return s.str (); +} + +bool +ImageContent::still () const +{ + return number_of_paths() == 1; +} diff --git a/src/lib/image_content.h b/src/lib/image_content.h new file mode 100644 index 000000000..3da782725 --- /dev/null +++ b/src/lib/image_content.h @@ -0,0 +1,52 @@ +/* + Copyright (C) 2013 Carl Hetherington + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#ifndef DCPOMATIC_IMAGE_CONTENT_H +#define DCPOMATIC_IMAGE_CONTENT_H + +#include +#include "video_content.h" + +namespace cxml { + class Node; +} + +class ImageContent : public VideoContent +{ +public: + ImageContent (boost::shared_ptr, boost::filesystem::path); + ImageContent (boost::shared_ptr, boost::shared_ptr); + + boost::shared_ptr shared_from_this () { + return boost::dynamic_pointer_cast (Content::shared_from_this ()); + }; + + void examine (boost::shared_ptr); + std::string summary () const; + std::string technical_summary () const; + void as_xml (xmlpp::Node *) const; + Time full_length () const; + + std::string identifier () const; + + void set_video_length (VideoContent::Frame); + bool still () const; +}; + +#endif diff --git a/src/lib/image_decoder.cc b/src/lib/image_decoder.cc new file mode 100644 index 000000000..498ff2e25 --- /dev/null +++ b/src/lib/image_decoder.cc @@ -0,0 +1,89 @@ +/* + Copyright (C) 2012-2013 Carl Hetherington + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include +#include +#include +#include "image_content.h" +#include "image_decoder.h" +#include "image.h" +#include "film.h" +#include "exceptions.h" + +#include "i18n.h" + +using std::cout; +using boost::shared_ptr; +using libdcp::Size; + +ImageDecoder::ImageDecoder (shared_ptr f, shared_ptr c) + : Decoder (f) + , VideoDecoder (f, c) + , _image_content (c) +{ + +} + +void +ImageDecoder::pass () +{ + if (_video_position >= _image_content->video_length ()) { + return; + } + + if (_image && _image_content->still ()) { + video (_image, true, _video_position); + return; + } + + Magick::Image* magick_image = new Magick::Image (_image_content->path(_video_position).string ()); + libdcp::Size size (magick_image->columns(), magick_image->rows()); + + _image.reset (new Image (PIX_FMT_RGB24, size, true)); + + using namespace MagickCore; + + uint8_t* p = _image->data()[0]; + for (int y = 0; y < size.height; ++y) { + uint8_t* q = p; + for (int x = 0; x < size.width; ++x) { + Magick::Color c = magick_image->pixelColor (x, y); + *q++ = c.redQuantum() * 255 / QuantumRange; + *q++ = c.greenQuantum() * 255 / QuantumRange; + *q++ = c.blueQuantum() * 255 / QuantumRange; + } + p += _image->stride()[0]; + } + + delete magick_image; + + video (_image, false, _video_position); +} + +void +ImageDecoder::seek (VideoContent::Frame frame, bool) +{ + _video_position = frame; +} + +bool +ImageDecoder::done () const +{ + return _video_position >= _image_content->video_length (); +} diff --git a/src/lib/image_decoder.h b/src/lib/image_decoder.h new file mode 100644 index 000000000..c7500243e --- /dev/null +++ b/src/lib/image_decoder.h @@ -0,0 +1,47 @@ +/* + Copyright (C) 2012-2013 Carl Hetherington + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "video_decoder.h" + +namespace Magick { + class Image; +} + +class ImageContent; + +class ImageDecoder : public VideoDecoder +{ +public: + ImageDecoder (boost::shared_ptr, boost::shared_ptr); + + boost::shared_ptr content () { + return _image_content; + } + + /* Decoder */ + + void pass (); + void seek (VideoContent::Frame, bool); + bool done () const; + +private: + boost::shared_ptr _image_content; + boost::shared_ptr _image; +}; + diff --git a/src/lib/image_examiner.cc b/src/lib/image_examiner.cc new file mode 100644 index 000000000..2d150583a --- /dev/null +++ b/src/lib/image_examiner.cc @@ -0,0 +1,97 @@ +/* + Copyright (C) 2013 Carl Hetherington + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include +#include +#include +#include "image_content.h" +#include "image_examiner.h" +#include "film.h" +#include "job.h" +#include "exceptions.h" +#include "config.h" + +#include "i18n.h" + +using std::cout; +using std::list; +using std::sort; +using boost::shared_ptr; +using boost::lexical_cast; +using boost::bad_lexical_cast; + +ImageExaminer::ImageExaminer (shared_ptr film, shared_ptr content, shared_ptr job) + : _film (film) + , _image_content (content) + , _video_length (0) +{ + list frames; + size_t const N = content->number_of_paths (); + + for (size_t i = 0; i < N; ++i) { + boost::filesystem::path const p = content->path (i); + try { + frames.push_back (lexical_cast (p.stem().string())); + } catch (bad_lexical_cast &) { + /* We couldn't turn that filename into a number; never mind */ + } + + if (!_video_size) { + using namespace MagickCore; + Magick::Image* image = new Magick::Image (p.string()); + _video_size = libdcp::Size (image->columns(), image->rows()); + delete image; + } + + job->set_progress (float (i) / N); + } + + frames.sort (); + + if (N > 1 && frames.front() != 0 && frames.front() != 1) { + throw StringError (String::compose (_("first frame in moving image directory is number %1"), frames.front ())); + } + + if (N > 1 && frames.back() != frames.size() && frames.back() != (frames.size() - 1)) { + throw StringError (String::compose (_("there are %1 images in the directory but the last one is number %2"), frames.size(), frames.back ())); + } + + if (content->still ()) { + _video_length = Config::instance()->default_still_length() * video_frame_rate(); + } else { + _video_length = _image_content->number_of_paths (); + } +} + +libdcp::Size +ImageExaminer::video_size () const +{ + return _video_size.get (); +} + +float +ImageExaminer::video_frame_rate () const +{ + boost::shared_ptr f = _film.lock (); + if (!f) { + return 24; + } + + return f->video_frame_rate (); +} diff --git a/src/lib/image_examiner.h b/src/lib/image_examiner.h new file mode 100644 index 000000000..8887f0d3d --- /dev/null +++ b/src/lib/image_examiner.h @@ -0,0 +1,44 @@ +/* + Copyright (C) 2013 Carl Hetherington + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "video_examiner.h" + +namespace Magick { + class Image; +} + +class ImageContent; + +class ImageExaminer : public VideoExaminer +{ +public: + ImageExaminer (boost::shared_ptr, boost::shared_ptr, boost::shared_ptr); + + float video_frame_rate () const; + libdcp::Size video_size () const; + VideoContent::Frame video_length () const { + return _video_length; + } + +private: + boost::weak_ptr _film; + boost::shared_ptr _image_content; + boost::optional _video_size; + VideoContent::Frame _video_length; +}; diff --git a/src/lib/moving_image.h b/src/lib/moving_image.h deleted file mode 100644 index a81403dbd..000000000 --- a/src/lib/moving_image.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - Copyright (C) 2012 Carl Hetherington - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -class MovingImageContent; - -class MovingImage -{ -public: - MovingImage (boost::shared_ptr c) - : _moving_image_content (c) - {} - - boost::shared_ptr content () const { - return _moving_image_content; - } - -protected: - boost::shared_ptr _moving_image_content; -}; diff --git a/src/lib/moving_image_content.cc b/src/lib/moving_image_content.cc deleted file mode 100644 index 23d18240b..000000000 --- a/src/lib/moving_image_content.cc +++ /dev/null @@ -1,114 +0,0 @@ -/* - Copyright (C) 2013 Carl Hetherington - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#include -#include "moving_image_content.h" -#include "moving_image_examiner.h" -#include "config.h" -#include "compose.hpp" -#include "film.h" -#include "job.h" - -#include "i18n.h" - -using std::string; -using std::cout; -using std::list; -using std::stringstream; -using std::vector; -using boost::shared_ptr; - -MovingImageContent::MovingImageContent (shared_ptr f, boost::filesystem::path p) - : Content (f) - , VideoContent (f) -{ - for (boost::filesystem::directory_iterator i(p); i != boost::filesystem::directory_iterator(); ++i) { - if (boost::filesystem::is_regular_file (i->path()) && valid_image_file (i->path())) { - _paths.push_back (i->path ()); - } - } - - sort (_paths.begin(), _paths.end()); -} - -MovingImageContent::MovingImageContent (shared_ptr f, shared_ptr node) - : Content (f, node) - , VideoContent (f, node) -{ - -} - -string -MovingImageContent::summary () const -{ - /* Get the string() here so that the name does not have quotes around it */ - return String::compose (_("%1 [moving images]"), path().filename().string()); -} - -string -MovingImageContent::technical_summary () const -{ - return Content::technical_summary() + " - " - + VideoContent::technical_summary() + " - " - + "moving"; -} - -void -MovingImageContent::as_xml (xmlpp::Node* node) const -{ - node->add_child("Type")->add_child_text ("MovingImage"); - Content::as_xml (node); - VideoContent::as_xml (node); -} - -void -MovingImageContent::examine (shared_ptr job) -{ - job->sub (_("Computing digest")); - Content::examine (job); - - shared_ptr film = _film.lock (); - assert (film); - - job->sub (_("Examining content")); - shared_ptr examiner (new MovingImageExaminer (film, shared_from_this(), job)); - - take_from_video_examiner (examiner); - - _video_length = number_of_paths (); -} - -Time -MovingImageContent::full_length () const -{ - shared_ptr film = _film.lock (); - assert (film); - - FrameRateConversion frc (video_frame_rate(), film->video_frame_rate ()); - return video_length() * frc.factor() * TIME_HZ / video_frame_rate(); -} - -string -MovingImageContent::identifier () const -{ - stringstream s; - s << VideoContent::identifier (); - s << "_" << video_length(); - return s.str (); -} diff --git a/src/lib/moving_image_content.h b/src/lib/moving_image_content.h deleted file mode 100644 index f6a7778be..000000000 --- a/src/lib/moving_image_content.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - Copyright (C) 2013 Carl Hetherington - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#ifndef DCPOMATIC_MOVING_IMAGE_CONTENT_H -#define DCPOMATIC_MOVING_IMAGE_CONTENT_H - -#include -#include "video_content.h" - -namespace cxml { - class Node; -} - -/** A directory of image files which are to be presented as a movie */ -class MovingImageContent : public VideoContent -{ -public: - MovingImageContent (boost::shared_ptr, boost::filesystem::path); - MovingImageContent (boost::shared_ptr, boost::shared_ptr); - - boost::shared_ptr shared_from_this () { - return boost::dynamic_pointer_cast (Content::shared_from_this ()); - }; - - void examine (boost::shared_ptr); - std::string summary () const; - std::string technical_summary () const; - void as_xml (xmlpp::Node *) const; - Time full_length () const; - - std::string identifier () const; -}; - -#endif diff --git a/src/lib/moving_image_decoder.cc b/src/lib/moving_image_decoder.cc deleted file mode 100644 index 4bfc7c130..000000000 --- a/src/lib/moving_image_decoder.cc +++ /dev/null @@ -1,84 +0,0 @@ -/* - Copyright (C) 2012-2013 Carl Hetherington - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#include -#include -#include -#include "moving_image_content.h" -#include "moving_image_decoder.h" -#include "image.h" -#include "film.h" -#include "exceptions.h" - -#include "i18n.h" - -using std::cout; -using boost::shared_ptr; -using libdcp::Size; - -MovingImageDecoder::MovingImageDecoder (shared_ptr f, shared_ptr c) - : Decoder (f) - , VideoDecoder (f, c) - , MovingImage (c) -{ - -} - -void -MovingImageDecoder::pass () -{ - if (_video_position >= _moving_image_content->video_length ()) { - return; - } - - Magick::Image* magick_image = new Magick::Image (_moving_image_content->path(_video_position).string ()); - libdcp::Size size (magick_image->columns(), magick_image->rows()); - - shared_ptr image (new Image (PIX_FMT_RGB24, size, true)); - - using namespace MagickCore; - - uint8_t* p = image->data()[0]; - for (int y = 0; y < size.height; ++y) { - uint8_t* q = p; - for (int x = 0; x < size.width; ++x) { - Magick::Color c = magick_image->pixelColor (x, y); - *q++ = c.redQuantum() * 255 / QuantumRange; - *q++ = c.greenQuantum() * 255 / QuantumRange; - *q++ = c.blueQuantum() * 255 / QuantumRange; - } - p += image->stride()[0]; - } - - delete magick_image; - - video (image, false, _video_position); -} - -void -MovingImageDecoder::seek (VideoContent::Frame frame, bool) -{ - _video_position = frame; -} - -bool -MovingImageDecoder::done () const -{ - return _video_position >= _moving_image_content->video_length (); -} diff --git a/src/lib/moving_image_decoder.h b/src/lib/moving_image_decoder.h deleted file mode 100644 index 5cc8b32b9..000000000 --- a/src/lib/moving_image_decoder.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - Copyright (C) 2012-2013 Carl Hetherington - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#include "video_decoder.h" -#include "moving_image.h" - -namespace Magick { - class Image; -} - -class MovingImageContent; - -class MovingImageDecoder : public VideoDecoder, public MovingImage -{ -public: - MovingImageDecoder (boost::shared_ptr, boost::shared_ptr); - - /* Decoder */ - - void pass (); - void seek (VideoContent::Frame, bool); - bool done () const; -}; - diff --git a/src/lib/moving_image_examiner.cc b/src/lib/moving_image_examiner.cc deleted file mode 100644 index 029c44104..000000000 --- a/src/lib/moving_image_examiner.cc +++ /dev/null @@ -1,94 +0,0 @@ -/* - Copyright (C) 2013 Carl Hetherington - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#include -#include -#include -#include "moving_image_content.h" -#include "moving_image_examiner.h" -#include "film.h" -#include "job.h" -#include "exceptions.h" - -#include "i18n.h" - -using std::cout; -using std::list; -using std::sort; -using boost::shared_ptr; -using boost::lexical_cast; - -MovingImageExaminer::MovingImageExaminer (shared_ptr film, shared_ptr content, shared_ptr job) - : MovingImage (content) - , _film (film) - , _video_length (0) -{ - list frames; - size_t const N = content->number_of_paths (); - - int j = 0; - for (size_t i = 0; i < N; ++i) { - boost::filesystem::path const p = content->path (i); - frames.push_back (lexical_cast (p.stem().string())); - - if (!_video_size) { - using namespace MagickCore; - Magick::Image* image = new Magick::Image (p.string()); - _video_size = libdcp::Size (image->columns(), image->rows()); - delete image; - } - - job->set_progress (float (i) / N); - } - - frames.sort (); - - if (frames.size() < 2) { - throw StringError (String::compose (_("only %1 file(s) found in moving image directory"), frames.size ())); - } - - if (frames.front() != 0 && frames.front() != 1) { - throw StringError (String::compose (_("first frame in moving image directory is number %1"), frames.front ())); - } - - if (frames.back() != frames.size() && frames.back() != (frames.size() - 1)) { - throw StringError (String::compose (_("there are %1 images in the directory but the last one is number %2"), frames.size(), frames.back ())); - } - - _video_length = frames.size (); -} - -libdcp::Size -MovingImageExaminer::video_size () const -{ - return _video_size.get (); -} - -int -MovingImageExaminer::video_length () const -{ - return _video_length; -} - -float -MovingImageExaminer::video_frame_rate () const -{ - return 24; -} - diff --git a/src/lib/moving_image_examiner.h b/src/lib/moving_image_examiner.h deleted file mode 100644 index 4c2cfa003..000000000 --- a/src/lib/moving_image_examiner.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - Copyright (C) 2013 Carl Hetherington - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#include "moving_image.h" -#include "video_examiner.h" - -namespace Magick { - class Image; -} - -class MovingImageContent; - -class MovingImageExaminer : public MovingImage, public VideoExaminer -{ -public: - MovingImageExaminer (boost::shared_ptr, boost::shared_ptr, boost::shared_ptr); - - float video_frame_rate () const; - libdcp::Size video_size () const; - VideoContent::Frame video_length () const; - -private: - boost::weak_ptr _film; - boost::optional _video_size; - VideoContent::Frame _video_length; -}; diff --git a/src/lib/player.cc b/src/lib/player.cc index b5a961631..87b10a398 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -22,10 +22,8 @@ #include "film.h" #include "ffmpeg_decoder.h" #include "ffmpeg_content.h" -#include "still_image_decoder.h" -#include "still_image_content.h" -#include "moving_image_decoder.h" -#include "moving_image_content.h" +#include "image_decoder.h" +#include "image_content.h" #include "sndfile_decoder.h" #include "sndfile_content.h" #include "subtitle_content.h" @@ -466,36 +464,24 @@ Player::setup_pieces () piece->decoder = fd; } - shared_ptr ic = dynamic_pointer_cast (*i); + shared_ptr ic = dynamic_pointer_cast (*i); if (ic) { - shared_ptr id; + bool reusing = false; - /* See if we can re-use an old StillImageDecoder */ + /* See if we can re-use an old ImageDecoder */ for (list >::const_iterator j = old_pieces.begin(); j != old_pieces.end(); ++j) { - shared_ptr imd = dynamic_pointer_cast ((*j)->decoder); + shared_ptr imd = dynamic_pointer_cast ((*j)->decoder); if (imd && imd->content() == ic) { - id = imd; + piece = *j; + reusing = true; } } - if (!id) { - id.reset (new StillImageDecoder (_film, ic)); + if (!reusing) { + shared_ptr id (new ImageDecoder (_film, ic)); id->Video.connect (bind (&Player::process_video, this, weak_ptr (piece), _1, _2, _3, _4, 0)); + piece->decoder = id; } - - piece->decoder = id; - } - - shared_ptr mc = dynamic_pointer_cast (*i); - if (mc) { - shared_ptr md; - - if (!md) { - md.reset (new MovingImageDecoder (_film, mc)); - md->Video.connect (bind (&Player::process_video, this, weak_ptr (piece), _1, _2, _3, _4, 0)); - } - - piece->decoder = md; } shared_ptr sc = dynamic_pointer_cast (*i); diff --git a/src/lib/playlist.cc b/src/lib/playlist.cc index 8f40c9e6d..e2a3c3486 100644 --- a/src/lib/playlist.cc +++ b/src/lib/playlist.cc @@ -26,8 +26,7 @@ #include "video_content.h" #include "ffmpeg_decoder.h" #include "ffmpeg_content.h" -#include "still_image_decoder.h" -#include "still_image_content.h" +#include "image_decoder.h" #include "content_factory.h" #include "job.h" #include "config.h" diff --git a/src/lib/still_image.h b/src/lib/still_image.h deleted file mode 100644 index 366d69331..000000000 --- a/src/lib/still_image.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - Copyright (C) 2012 Carl Hetherington - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#ifndef DCPOMATIC_STILL_IMAGE_H -#define DCPOMATIC_STILL_IMAGE_H - -class StillImageContent; - -class StillImage -{ -public: - StillImage (boost::shared_ptr c) - : _still_image_content (c) - {} - - boost::shared_ptr content () const { - return _still_image_content; - } - -protected: - boost::shared_ptr _still_image_content; -}; - -#endif diff --git a/src/lib/still_image_content.cc b/src/lib/still_image_content.cc deleted file mode 100644 index 0cf80b546..000000000 --- a/src/lib/still_image_content.cc +++ /dev/null @@ -1,113 +0,0 @@ -/* - Copyright (C) 2013 Carl Hetherington - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#include -#include "still_image_content.h" -#include "still_image_examiner.h" -#include "config.h" -#include "compose.hpp" -#include "film.h" - -#include "i18n.h" - -using std::string; -using std::cout; -using std::stringstream; -using boost::shared_ptr; - -StillImageContent::StillImageContent (shared_ptr f, boost::filesystem::path p) - : Content (f, p) - , VideoContent (f, p) -{ - -} - -StillImageContent::StillImageContent (shared_ptr f, shared_ptr node) - : Content (f, node) - , VideoContent (f, node) -{ - -} - -string -StillImageContent::summary () const -{ - /* Get the string() here so that the name does not have quotes around it */ - return String::compose (_("%1 [still]"), path().filename().string()); -} - -string -StillImageContent::technical_summary () const -{ - return Content::technical_summary() + " - " - + VideoContent::technical_summary() + " - " - + "still"; -} - -void -StillImageContent::as_xml (xmlpp::Node* node) const -{ - node->add_child("Type")->add_child_text ("StillImage"); - Content::as_xml (node); - VideoContent::as_xml (node); -} - -void -StillImageContent::examine (shared_ptr job) -{ - Content::examine (job); - - shared_ptr film = _film.lock (); - assert (film); - - shared_ptr examiner (new StillImageExaminer (film, shared_from_this())); - - take_from_video_examiner (examiner); - set_video_length (Config::instance()->default_still_length() * video_frame_rate()); -} - -void -StillImageContent::set_video_length (VideoContent::Frame len) -{ - { - boost::mutex::scoped_lock lm (_mutex); - _video_length = len; - } - - signal_changed (ContentProperty::LENGTH); -} - -Time -StillImageContent::full_length () const -{ - shared_ptr film = _film.lock (); - assert (film); - - FrameRateConversion frc (video_frame_rate(), film->video_frame_rate ()); - return video_length() * frc.factor() * TIME_HZ / video_frame_rate(); -} - -string -StillImageContent::identifier () const -{ - stringstream s; - s << VideoContent::identifier (); - s << "_" << video_length(); - return s.str (); -} diff --git a/src/lib/still_image_content.h b/src/lib/still_image_content.h deleted file mode 100644 index ccd7fbc03..000000000 --- a/src/lib/still_image_content.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - Copyright (C) 2013 Carl Hetherington - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#ifndef DCPOMATIC_STILL_IMAGE_CONTENT_H -#define DCPOMATIC_STILL_IMAGE_CONTENT_H - -#include -#include "video_content.h" - -namespace cxml { - class Node; -} - -/** A single image which is to be held on screen for some time (i.e. a slide) */ -class StillImageContent : public VideoContent -{ -public: - StillImageContent (boost::shared_ptr, boost::filesystem::path); - StillImageContent (boost::shared_ptr, boost::shared_ptr); - - boost::shared_ptr shared_from_this () { - return boost::dynamic_pointer_cast (Content::shared_from_this ()); - }; - - void examine (boost::shared_ptr); - std::string summary () const; - std::string technical_summary () const; - void as_xml (xmlpp::Node *) const; - Time full_length () const; - - std::string identifier () const; - - void set_video_length (VideoContent::Frame); -}; - -#endif diff --git a/src/lib/still_image_decoder.cc b/src/lib/still_image_decoder.cc deleted file mode 100644 index 6e82f9a55..000000000 --- a/src/lib/still_image_decoder.cc +++ /dev/null @@ -1,89 +0,0 @@ -/* - Copyright (C) 2012-2013 Carl Hetherington - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#include -#include -#include -#include "still_image_content.h" -#include "still_image_decoder.h" -#include "image.h" -#include "film.h" -#include "exceptions.h" - -#include "i18n.h" - -using std::cout; -using boost::shared_ptr; -using libdcp::Size; - -StillImageDecoder::StillImageDecoder (shared_ptr f, shared_ptr c) - : Decoder (f) - , VideoDecoder (f, c) - , StillImage (c) -{ - -} - -void -StillImageDecoder::pass () -{ - if (_video_position >= _still_image_content->video_length ()) { - return; - } - - if (_image) { - video (_image, true, _video_position); - return; - } - - Magick::Image* magick_image = new Magick::Image (_still_image_content->path().string ()); - _video_size = libdcp::Size (magick_image->columns(), magick_image->rows()); - - _image.reset (new Image (PIX_FMT_RGB24, _video_size.get(), true)); - - using namespace MagickCore; - - uint8_t* p = _image->data()[0]; - for (int y = 0; y < _video_size->height; ++y) { - uint8_t* q = p; - for (int x = 0; x < _video_size->width; ++x) { - Magick::Color c = magick_image->pixelColor (x, y); - *q++ = c.redQuantum() * 255 / QuantumRange; - *q++ = c.greenQuantum() * 255 / QuantumRange; - *q++ = c.blueQuantum() * 255 / QuantumRange; - } - p += _image->stride()[0]; - } - - delete magick_image; - - video (_image, false, _video_position); -} - -void -StillImageDecoder::seek (VideoContent::Frame frame, bool) -{ - _video_position = frame; -} - -bool -StillImageDecoder::done () const -{ - return _video_position >= _still_image_content->video_length (); -} diff --git a/src/lib/still_image_decoder.h b/src/lib/still_image_decoder.h deleted file mode 100644 index db41b0357..000000000 --- a/src/lib/still_image_decoder.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - Copyright (C) 2012-2013 Carl Hetherington - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#include "video_decoder.h" -#include "still_image.h" - -namespace Magick { - class Image; -} - -class StillImageContent; - -class StillImageDecoder : public VideoDecoder, public StillImage -{ -public: - StillImageDecoder (boost::shared_ptr, boost::shared_ptr); - - /* Decoder */ - - void pass (); - void seek (VideoContent::Frame, bool); - bool done () const; - -private: - boost::shared_ptr _image; - mutable boost::optional _video_size; -}; - diff --git a/src/lib/still_image_examiner.cc b/src/lib/still_image_examiner.cc deleted file mode 100644 index 5f45d6365..000000000 --- a/src/lib/still_image_examiner.cc +++ /dev/null @@ -1,63 +0,0 @@ -/* - Copyright (C) 2013 Carl Hetherington - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#include -#include -#include "still_image_content.h" -#include "still_image_examiner.h" -#include "film.h" - -#include "i18n.h" - -using std::cout; -using boost::shared_ptr; - -StillImageExaminer::StillImageExaminer (shared_ptr f, shared_ptr c) - : StillImage (c) - , _film (f) -{ - using namespace MagickCore; - Magick::Image* image = new Magick::Image (_still_image_content->path().string()); - _video_size = libdcp::Size (image->columns(), image->rows()); - delete image; -} - -libdcp::Size -StillImageExaminer::video_size () const -{ - return _video_size; -} - -int -StillImageExaminer::video_length () const -{ - return _still_image_content->video_length (); -} - -float -StillImageExaminer::video_frame_rate () const -{ - boost::shared_ptr f = _film.lock (); - if (!f) { - return 24; - } - - return f->video_frame_rate (); -} - diff --git a/src/lib/still_image_examiner.h b/src/lib/still_image_examiner.h deleted file mode 100644 index fa3456e8a..000000000 --- a/src/lib/still_image_examiner.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - Copyright (C) 2013 Carl Hetherington - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#include "still_image.h" -#include "video_examiner.h" - -namespace Magick { - class Image; -} - -class StillImageContent; - -class StillImageExaminer : public StillImage, public VideoExaminer -{ -public: - StillImageExaminer (boost::shared_ptr, boost::shared_ptr); - - float video_frame_rate () const; - libdcp::Size video_size () const; - VideoContent::Frame video_length () const; - -private: - boost::weak_ptr _film; - libdcp::Size _video_size; -}; diff --git a/src/lib/wscript b/src/lib/wscript index 852bb1aed..1e88e6e62 100644 --- a/src/lib/wscript +++ b/src/lib/wscript @@ -30,13 +30,13 @@ sources = """ film.cc filter.cc image.cc + image_content.cc + image_decoder.cc + image_examiner.cc job.cc job_manager.cc kdm.cc log.cc - moving_image_content.cc - moving_image_decoder.cc - moving_image_examiner.cc player.cc playlist.cc ratio.cc @@ -48,9 +48,6 @@ sources = """ sndfile_content.cc sndfile_decoder.cc sound_processor.cc - still_image_content.cc - still_image_decoder.cc - still_image_examiner.cc subtitle_content.cc subtitle_decoder.cc timer.cc -- cgit v1.2.3