2 * copyright (c) 2010 Sveriges Television AB <info@casparcg.com>
\r
4 * This file is part of CasparCG.
\r
6 * CasparCG is free software: you can redistribute it and/or modify
\r
7 * it under the terms of the GNU General Public License as published by
\r
8 * the Free Software Foundation, either version 3 of the License, or
\r
9 * (at your option) any later version.
\r
11 * CasparCG is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
\r
20 #include "image_scroll_producer.h"
\r
22 #include "../util/image_loader.h"
\r
24 #include <core/video_format.h>
\r
26 #include <core/producer/frame/basic_frame.h>
\r
27 #include <core/producer/frame/image_transform.h>
\r
28 #include <core/mixer/write_frame.h>
\r
30 #include <common/env.h>
\r
31 #include <common/memory/memclr.h>
\r
32 #include <common/exception/exceptions.h>
\r
34 #include <boost/assign.hpp>
\r
35 #include <boost/filesystem.hpp>
\r
36 #include <boost/foreach.hpp>
\r
38 #include <algorithm>
\r
40 using namespace boost::assign;
\r
50 struct image_scroll_producer : public core::frame_producer
\r
52 const std::wstring filename_;
\r
53 std::vector<safe_ptr<core::basic_frame>> frames_;
\r
54 size_t pixel_offset_;
\r
55 core::video_format_desc format_desc_;
\r
60 explicit image_scroll_producer(const safe_ptr<core::frame_factory>& frame_factory, const std::wstring& filename, size_t speed)
\r
61 : filename_(filename)
\r
63 , format_desc_(frame_factory->get_video_format_desc())
\r
66 auto bitmap = load_image(filename_);
\r
67 FreeImage_FlipVertical(bitmap.get());
\r
69 width_ = FreeImage_GetWidth(bitmap.get());
\r
70 height_ = FreeImage_GetHeight(bitmap.get());
\r
72 auto bytes = FreeImage_GetBits(bitmap.get());
\r
73 int count = width_*height_*4;
\r
75 if(height_ > format_desc_.height)
\r
79 auto frame = frame_factory->create_frame(reinterpret_cast<void*>(rand()), width_, format_desc_.height);
\r
80 if(count >= frame->image_data().size())
\r
82 std::copy_n(bytes + count - frame->image_data().size(), frame->image_data().size(), frame->image_data().begin());
\r
83 count -= frame->image_data().size();
\r
87 fast_memclr(frame->image_data().begin(), frame->image_data().size());
\r
88 std::copy_n(bytes, count, frame->image_data().begin() + format_desc_.size - count);
\r
93 frames_.push_back(frame);
\r
100 // auto frame = frame_factory->create_frame(reinterpret_cast<void*>(rand()), format_desc_.width, height_);
\r
101 // if(count >= frame->image_data().size())
\r
103 // count -= frame->image_data().size();
\r
107 // fast_memclr(frame->image_data().begin(), frame->image_data().size());
\r
108 // //std::copy_n(bytes, count, frame->image_data().begin() + format_desc_.size - count);
\r
112 // frame->commit();
\r
113 // frames_.push_back(frame);
\r
120 virtual safe_ptr<core::basic_frame> receive()
\r
122 pixel_offset_ += speed_;
\r
124 if(frames_.empty())
\r
125 return core::basic_frame::eof();
\r
127 for(size_t n = 0; n < frames_.size(); ++n)
\r
128 frames_[n]->get_image_transform().set_fill_translation(0.0, -0.5*(n+1) + pixel_offset_ * 0.5/static_cast<double>(format_desc_.height));
\r
130 return core::basic_frame(frames_);
\r
133 virtual std::wstring print() const
\r
135 return L"image_scroll_producer[" + filename_ + L"]";
\r
139 safe_ptr<core::frame_producer> create_image_scroll_producer(const safe_ptr<core::frame_factory>& frame_factory, const std::vector<std::wstring>& params)
\r
141 static const std::vector<std::wstring> extensions = list_of(L"png")(L"tga")(L"bmp")(L"jpg")(L"jpeg")(L"gif")(L"tiff")(L"tif")(L"jp2")(L"jpx")(L"j2k")(L"j2c");
\r
142 std::wstring filename = env::media_folder() + L"\\" + params[0];
\r
144 auto ext = std::find_if(extensions.begin(), extensions.end(), [&](const std::wstring& ex) -> bool
\r
146 return boost::filesystem::is_regular_file(boost::filesystem::wpath(filename).replace_extension(ex));
\r
149 if(ext == extensions.end())
\r
150 return core::frame_producer::empty();
\r
153 auto speed_it = std::find(params.begin(), params.end(), L"SPEED");
\r
154 if(speed_it != params.end())
\r
156 if(++speed_it != params.end())
\r
157 speed = boost::lexical_cast<int>(*speed_it);
\r
161 return core::frame_producer::empty();
\r
163 return make_safe<image_scroll_producer>(frame_factory, filename + L"." + *ext, speed);
\r