From bd453939da140ea994282e1c167ea5f8d02e2d94 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Fri, 19 Jul 2013 16:08:29 +0100 Subject: Spacing tweaks; rename ImageMagick -> StillImage. --- src/lib/content_factory.cc | 6 +-- src/lib/imagemagick.h | 35 ------------- src/lib/imagemagick_content.cc | 112 ---------------------------------------- src/lib/imagemagick_content.h | 52 ------------------- src/lib/imagemagick_decoder.cc | 87 ------------------------------- src/lib/imagemagick_decoder.h | 43 --------------- src/lib/imagemagick_examiner.cc | 63 ---------------------- src/lib/imagemagick_examiner.h | 41 --------------- src/lib/player.cc | 18 +++---- src/lib/playlist.cc | 4 +- src/lib/playlist.h | 4 +- src/lib/still_image.h | 35 +++++++++++++ src/lib/still_image_content.cc | 112 ++++++++++++++++++++++++++++++++++++++++ src/lib/still_image_content.h | 52 +++++++++++++++++++ src/lib/still_image_decoder.cc | 87 +++++++++++++++++++++++++++++++ src/lib/still_image_decoder.h | 44 ++++++++++++++++ src/lib/still_image_examiner.cc | 63 ++++++++++++++++++++++ src/lib/still_image_examiner.h | 41 +++++++++++++++ src/lib/wscript | 6 +-- 19 files changed, 453 insertions(+), 452 deletions(-) delete mode 100644 src/lib/imagemagick.h delete mode 100644 src/lib/imagemagick_content.cc delete mode 100644 src/lib/imagemagick_content.h delete mode 100644 src/lib/imagemagick_decoder.cc delete mode 100644 src/lib/imagemagick_decoder.h delete mode 100644 src/lib/imagemagick_examiner.cc delete mode 100644 src/lib/imagemagick_examiner.h create mode 100644 src/lib/still_image.h create mode 100644 src/lib/still_image_content.cc create mode 100644 src/lib/still_image_content.h create mode 100644 src/lib/still_image_decoder.cc create mode 100644 src/lib/still_image_decoder.h create mode 100644 src/lib/still_image_examiner.cc create mode 100644 src/lib/still_image_examiner.h (limited to 'src/lib') diff --git a/src/lib/content_factory.cc b/src/lib/content_factory.cc index cf45b6aa6..bf447641d 100644 --- a/src/lib/content_factory.cc +++ b/src/lib/content_factory.cc @@ -19,7 +19,7 @@ #include #include "ffmpeg_content.h" -#include "imagemagick_content.h" +#include "still_image_content.h" #include "sndfile_content.h" using std::string; @@ -34,8 +34,8 @@ content_factory (shared_ptr film, shared_ptr node) if (type == "FFmpeg") { content.reset (new FFmpegContent (film, node)); - } else if (type == "ImageMagick") { - content.reset (new ImageMagickContent (film, node)); + } else if (type == "StillImage") { + content.reset (new StillImageContent (film, node)); } else if (type == "Sndfile") { content.reset (new SndfileContent (film, node)); } diff --git a/src/lib/imagemagick.h b/src/lib/imagemagick.h deleted file mode 100644 index 5a1712a3a..000000000 --- a/src/lib/imagemagick.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 ImageMagickContent; - -class ImageMagick -{ -public: - ImageMagick (boost::shared_ptr c) - : _imagemagick_content (c) - {} - - boost::shared_ptr content () const { - return _imagemagick_content; - } - -protected: - boost::shared_ptr _imagemagick_content; -}; diff --git a/src/lib/imagemagick_content.cc b/src/lib/imagemagick_content.cc deleted file mode 100644 index 0c4e84015..000000000 --- a/src/lib/imagemagick_content.cc +++ /dev/null @@ -1,112 +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 "imagemagick_content.h" -#include "imagemagick_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; - -ImageMagickContent::ImageMagickContent (shared_ptr f, boost::filesystem::path p) - : Content (f, p) - , VideoContent (f, p) -{ - -} - -ImageMagickContent::ImageMagickContent (shared_ptr f, shared_ptr node) - : Content (f, node) - , VideoContent (f, node) -{ - -} - -string -ImageMagickContent::summary () const -{ - return String::compose (_("%1 [still]"), file().filename().string()); -} - -bool -ImageMagickContent::valid_file (boost::filesystem::path f) -{ - string ext = f.extension().string(); - transform (ext.begin(), ext.end(), ext.begin(), ::tolower); - return (ext == ".tif" || ext == ".tiff" || ext == ".jpg" || ext == ".jpeg" || ext == ".png" || ext == ".bmp"); -} - -void -ImageMagickContent::as_xml (xmlpp::Node* node) const -{ - node->add_child("Type")->add_child_text ("ImageMagick"); - Content::as_xml (node); - VideoContent::as_xml (node); -} - -void -ImageMagickContent::examine (shared_ptr job) -{ - Content::examine (job); - - shared_ptr film = _film.lock (); - assert (film); - - shared_ptr examiner (new ImageMagickExaminer (film, shared_from_this())); - - take_from_video_examiner (examiner); - set_video_length (Config::instance()->default_still_length() * video_frame_rate()); -} - -void -ImageMagickContent::set_video_length (VideoContent::Frame len) -{ - { - boost::mutex::scoped_lock lm (_mutex); - _video_length = len; - } - - signal_changed (ContentProperty::LENGTH); -} - -Time -ImageMagickContent::length () const -{ - shared_ptr film = _film.lock (); - assert (film); - - FrameRateConversion frc (video_frame_rate(), film->dcp_video_frame_rate ()); - return video_length() * frc.factor() * TIME_HZ / video_frame_rate(); -} - -string -ImageMagickContent::identifier () const -{ - stringstream s; - s << VideoContent::identifier (); - s << "_" << video_length(); - return s.str (); -} diff --git a/src/lib/imagemagick_content.h b/src/lib/imagemagick_content.h deleted file mode 100644 index 50191cc5a..000000000 --- a/src/lib/imagemagick_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_IMAGEMAGICK_CONTENT_H -#define DCPOMATIC_IMAGEMAGICK_CONTENT_H - -#include -#include "video_content.h" - -namespace cxml { - class Node; -} - -class ImageMagickContent : public VideoContent -{ -public: - ImageMagickContent (boost::shared_ptr, boost::filesystem::path); - ImageMagickContent (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; - void as_xml (xmlpp::Node *) const; - Time length () const; - - std::string identifier () const; - - void set_video_length (VideoContent::Frame); - - static bool valid_file (boost::filesystem::path); -}; - -#endif diff --git a/src/lib/imagemagick_decoder.cc b/src/lib/imagemagick_decoder.cc deleted file mode 100644 index ee50f3fb1..000000000 --- a/src/lib/imagemagick_decoder.cc +++ /dev/null @@ -1,87 +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 "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 (shared_ptr f, shared_ptr c) - : Decoder (f) - , VideoDecoder (f) - , ImageMagick (c) -{ - -} - -void -ImageMagickDecoder::pass () -{ - if (_video_position >= _imagemagick_content->video_length ()) { - return; - } - - if (_image) { - video (_image, true, _video_position); - return; - } - - Magick::Image* magick_image = new Magick::Image (_imagemagick_content->file().string ()); - _video_size = libdcp::Size (magick_image->columns(), magick_image->rows()); - - _image.reset (new Image (PIX_FMT_RGB24, _video_size.get(), false)); - - using namespace MagickCore; - - uint8_t* p = _image->data()[0]; - for (int y = 0; y < _video_size->height; ++y) { - for (int x = 0; x < _video_size->width; ++x) { - Magick::Color c = magick_image->pixelColor (x, y); - *p++ = c.redQuantum() * 255 / QuantumRange; - *p++ = c.greenQuantum() * 255 / QuantumRange; - *p++ = c.blueQuantum() * 255 / QuantumRange; - } - } - - delete magick_image; - - video (_image, false, _video_position); -} - -void -ImageMagickDecoder::seek (VideoContent::Frame frame, bool) -{ - _video_position = frame; -} - -bool -ImageMagickDecoder::done () const -{ - return _video_position >= _imagemagick_content->video_length (); -} diff --git a/src/lib/imagemagick_decoder.h b/src/lib/imagemagick_decoder.h deleted file mode 100644 index 3e551c3b7..000000000 --- a/src/lib/imagemagick_decoder.h +++ /dev/null @@ -1,43 +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 "imagemagick.h" - -namespace Magick { - class Image; -} - -class ImageMagickContent; - -class ImageMagickDecoder : public VideoDecoder, public ImageMagick -{ -public: - ImageMagickDecoder (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/imagemagick_examiner.cc b/src/lib/imagemagick_examiner.cc deleted file mode 100644 index 0eee0d425..000000000 --- a/src/lib/imagemagick_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 "imagemagick_content.h" -#include "imagemagick_examiner.h" -#include "film.h" - -#include "i18n.h" - -using std::cout; -using boost::shared_ptr; - -ImageMagickExaminer::ImageMagickExaminer (shared_ptr f, shared_ptr c) - : ImageMagick (c) - , _film (f) -{ - using namespace MagickCore; - Magick::Image* image = new Magick::Image (_imagemagick_content->file().string()); - _video_size = libdcp::Size (image->columns(), image->rows()); - delete image; -} - -libdcp::Size -ImageMagickExaminer::video_size () const -{ - return _video_size; -} - -int -ImageMagickExaminer::video_length () const -{ - return _imagemagick_content->video_length (); -} - -float -ImageMagickExaminer::video_frame_rate () const -{ - boost::shared_ptr f = _film.lock (); - if (!f) { - return 24; - } - - return f->dcp_video_frame_rate (); -} - diff --git a/src/lib/imagemagick_examiner.h b/src/lib/imagemagick_examiner.h deleted file mode 100644 index 801ede442..000000000 --- a/src/lib/imagemagick_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 "imagemagick.h" -#include "video_examiner.h" - -namespace Magick { - class Image; -} - -class ImageMagickContent; - -class ImageMagickExaminer : public ImageMagick, public VideoExaminer -{ -public: - ImageMagickExaminer (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/player.cc b/src/lib/player.cc index d3d5d0f6b..1ffced425 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -22,8 +22,8 @@ #include "film.h" #include "ffmpeg_decoder.h" #include "ffmpeg_content.h" -#include "imagemagick_decoder.h" -#include "imagemagick_content.h" +#include "still_image_decoder.h" +#include "still_image_content.h" #include "sndfile_decoder.h" #include "sndfile_content.h" #include "subtitle_content.h" @@ -74,8 +74,8 @@ std::ostream& operator<<(std::ostream& s, Piece const & p) { if (dynamic_pointer_cast (p.content)) { s << "\tffmpeg "; - } else if (dynamic_pointer_cast (p.content)) { - s << "\timagemagick"; + } else if (dynamic_pointer_cast (p.content)) { + s << "\tstill image"; } else if (dynamic_pointer_cast (p.content)) { s << "\tsndfile "; } @@ -421,20 +421,20 @@ 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; + shared_ptr id; - /* See if we can re-use an old ImageMagickDecoder */ + /* See if we can re-use an old StillImageDecoder */ 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; } } if (!id) { - id.reset (new ImageMagickDecoder (_film, ic)); + id.reset (new StillImageDecoder (_film, ic)); id->Video.connect (bind (&Player::process_video, this, piece, _1, _2, _3)); } diff --git a/src/lib/playlist.cc b/src/lib/playlist.cc index c9d05b049..5ccc12b61 100644 --- a/src/lib/playlist.cc +++ b/src/lib/playlist.cc @@ -26,8 +26,8 @@ #include "video_content.h" #include "ffmpeg_decoder.h" #include "ffmpeg_content.h" -#include "imagemagick_decoder.h" -#include "imagemagick_content.h" +#include "still_image_decoder.h" +#include "still_image_content.h" #include "content_factory.h" #include "job.h" #include "config.h" diff --git a/src/lib/playlist.h b/src/lib/playlist.h index e39e9f51f..7dbf41604 100644 --- a/src/lib/playlist.h +++ b/src/lib/playlist.h @@ -29,8 +29,8 @@ class Content; class FFmpegContent; class FFmpegDecoder; -class ImageMagickContent; -class ImageMagickDecoder; +class StillImageMagickContent; +class StillImageMagickDecoder; class SndfileContent; class SndfileDecoder; class Job; diff --git a/src/lib/still_image.h b/src/lib/still_image.h new file mode 100644 index 000000000..b60069419 --- /dev/null +++ b/src/lib/still_image.h @@ -0,0 +1,35 @@ +/* + 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 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; +}; diff --git a/src/lib/still_image_content.cc b/src/lib/still_image_content.cc new file mode 100644 index 000000000..3a30ccf87 --- /dev/null +++ b/src/lib/still_image_content.cc @@ -0,0 +1,112 @@ +/* + 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 +{ + return String::compose (_("%1 [still]"), file().filename().string()); +} + +bool +StillImageContent::valid_file (boost::filesystem::path f) +{ + string ext = f.extension().string(); + transform (ext.begin(), ext.end(), ext.begin(), ::tolower); + return (ext == ".tif" || ext == ".tiff" || ext == ".jpg" || ext == ".jpeg" || ext == ".png" || ext == ".bmp"); +} + +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::length () const +{ + shared_ptr film = _film.lock (); + assert (film); + + FrameRateConversion frc (video_frame_rate(), film->dcp_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 new file mode 100644 index 000000000..02921f4e2 --- /dev/null +++ b/src/lib/still_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_STILL_IMAGE_CONTENT_H +#define DCPOMATIC_STILL_IMAGE_CONTENT_H + +#include +#include "video_content.h" + +namespace cxml { + class Node; +} + +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; + void as_xml (xmlpp::Node *) const; + Time length () const; + + std::string identifier () const; + + void set_video_length (VideoContent::Frame); + + static bool valid_file (boost::filesystem::path); +}; + +#endif diff --git a/src/lib/still_image_decoder.cc b/src/lib/still_image_decoder.cc new file mode 100644 index 000000000..21cc83f54 --- /dev/null +++ b/src/lib/still_image_decoder.cc @@ -0,0 +1,87 @@ +/* + 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) + , 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->file().string ()); + _video_size = libdcp::Size (magick_image->columns(), magick_image->rows()); + + _image.reset (new Image (PIX_FMT_RGB24, _video_size.get(), false)); + + using namespace MagickCore; + + uint8_t* p = _image->data()[0]; + for (int y = 0; y < _video_size->height; ++y) { + for (int x = 0; x < _video_size->width; ++x) { + Magick::Color c = magick_image->pixelColor (x, y); + *p++ = c.redQuantum() * 255 / QuantumRange; + *p++ = c.greenQuantum() * 255 / QuantumRange; + *p++ = c.blueQuantum() * 255 / QuantumRange; + } + } + + 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 new file mode 100644 index 000000000..db41b0357 --- /dev/null +++ b/src/lib/still_image_decoder.h @@ -0,0 +1,44 @@ +/* + 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 new file mode 100644 index 000000000..71357e5ef --- /dev/null +++ b/src/lib/still_image_examiner.cc @@ -0,0 +1,63 @@ +/* + 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->file().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->dcp_video_frame_rate (); +} + diff --git a/src/lib/still_image_examiner.h b/src/lib/still_image_examiner.h new file mode 100644 index 000000000..fa3456e8a --- /dev/null +++ b/src/lib/still_image_examiner.h @@ -0,0 +1,41 @@ +/* + 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 2bedc1fce..100663b87 100644 --- a/src/lib/wscript +++ b/src/lib/wscript @@ -28,9 +28,9 @@ sources = """ film.cc filter.cc image.cc - imagemagick_content.cc - imagemagick_decoder.cc - imagemagick_examiner.cc + still_image_content.cc + still_image_decoder.cc + still_image_examiner.cc job.cc job_manager.cc log.cc -- cgit v1.2.3