2 Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <boost/filesystem.hpp>
23 #include "imagemagick_decoder.h"
26 #include "exceptions.h"
29 using boost::shared_ptr;
31 ImageMagickDecoder::ImageMagickDecoder (
32 boost::shared_ptr<Film> f, boost::shared_ptr<const DecodeOptions> o, Job* j)
34 , VideoDecoder (f, o, j)
36 if (boost::filesystem::is_directory (_film->content_path())) {
38 boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator (_film->content_path());
39 i != boost::filesystem::directory_iterator();
42 if (still_image_file (i->path().string())) {
43 _files.push_back (i->path().string());
47 _files.push_back (_film->content_path ());
50 _iter = _files.begin ();
54 ImageMagickDecoder::native_size () const
56 if (_files.empty ()) {
57 throw DecodeError ("no still image files found");
60 /* Look at the first file and assume its size holds for all */
61 using namespace MagickCore;
62 Magick::Image* image = new Magick::Image (_film->content_path ());
63 Size const s = Size (image->columns(), image->rows());
70 ImageMagickDecoder::pass ()
72 if (_iter == _files.end()) {
76 Magick::Image* magick_image = new Magick::Image (_film->content_path ());
78 Size size = native_size ();
79 shared_ptr<Image> image (new SimpleImage (PIX_FMT_RGB24, size, false));
81 using namespace MagickCore;
83 uint8_t* p = image->data()[0];
84 for (int y = 0; y < size.height; ++y) {
85 for (int x = 0; x < size.width; ++x) {
86 Magick::Color c = magick_image->pixelColor (x, y);
87 *p++ = c.redQuantum() * 255 / QuantumRange;
88 *p++ = c.greenQuantum() * 255 / QuantumRange;
89 *p++ = c.blueQuantum() * 255 / QuantumRange;
95 image = image->crop (_film->crop(), false);
97 emit_video (image, 0);
104 ImageMagickDecoder::pixel_format () const
106 /* XXX: always true? */
107 return PIX_FMT_RGB24;
111 ImageMagickDecoder::seek (SourceFrame f)
113 _iter = _files.begin ();
114 for (int i = 0; i < f; ++i) {
115 if (_iter == _files.end()) {
125 ImageMagickDecoder::film_changed (Film::Property p)
127 if (p == Film::CROP) {