--- /dev/null
+/*\r
+* copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
+*\r
+* This file is part of CasparCG.\r
+*\r
+* CasparCG is free software: you can redistribute it and/or modify\r
+* it under the terms of the GNU General Public License as published by\r
+* the Free Software Foundation, either version 3 of the License, or\r
+* (at your option) any later version.\r
+*\r
+* CasparCG is distributed in the hope that it will be useful,\r
+* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+* GNU General Public License for more details.\r
+\r
+* You should have received a copy of the GNU General Public License\r
+* along with CasparCG. If not, see <http://www.gnu.org/licenses/>.\r
+*\r
+*/\r
+#include "image_scroll_producer.h"\r
+\r
+#include "../util/image_loader.h"\r
+\r
+#include <core/video_format.h>\r
+\r
+#include <core/producer/frame/basic_frame.h>\r
+#include <core/producer/frame/image_transform.h>\r
+#include <core/mixer/write_frame.h>\r
+\r
+#include <common/env.h>\r
+#include <common/memory/memclr.h>\r
+#include <common/exception/exceptions.h>\r
+\r
+#include <boost/assign.hpp>\r
+#include <boost/filesystem.hpp>\r
+#include <boost/foreach.hpp>\r
+\r
+#include <algorithm>\r
+\r
+using namespace boost::assign;\r
+\r
+namespace caspar {\r
+\r
+enum direction\r
+{\r
+ down,\r
+ right\r
+};\r
+ \r
+struct image_scroll_producer : public core::frame_producer\r
+{ \r
+ const std::wstring filename_;\r
+ std::vector<safe_ptr<core::basic_frame>> frames_;\r
+ size_t pixel_offset_;\r
+ core::video_format_desc format_desc_;\r
+ size_t width_;\r
+ size_t height_;\r
+ size_t speed_;\r
+ \r
+ explicit image_scroll_producer(const safe_ptr<core::frame_factory>& frame_factory, const std::wstring& filename, size_t speed) \r
+ : filename_(filename)\r
+ , pixel_offset_(0)\r
+ , format_desc_(frame_factory->get_video_format_desc())\r
+ , speed_(speed)\r
+ {\r
+ auto bitmap = load_image(filename_);\r
+ FreeImage_FlipVertical(bitmap.get());\r
+\r
+ width_ = FreeImage_GetWidth(bitmap.get());\r
+ height_ = FreeImage_GetHeight(bitmap.get());\r
+\r
+ auto bytes = FreeImage_GetBits(bitmap.get());\r
+ int count = width_*height_*4;\r
+\r
+ if(height_ > format_desc_.height)\r
+ {\r
+ while(count > 0)\r
+ {\r
+ auto frame = frame_factory->create_frame(reinterpret_cast<void*>(rand()), width_, format_desc_.height);\r
+ if(count >= frame->image_data().size())\r
+ { \r
+ std::copy_n(bytes + count - frame->image_data().size(), frame->image_data().size(), frame->image_data().begin());\r
+ count -= frame->image_data().size();\r
+ }\r
+ else\r
+ {\r
+ fast_memclr(frame->image_data().begin(), frame->image_data().size()); \r
+ std::copy_n(bytes, count, frame->image_data().begin() + format_desc_.size - count);\r
+ count = 0;\r
+ }\r
+ \r
+ frame->commit();\r
+ frames_.push_back(frame);\r
+ }\r
+ }\r
+ //else\r
+ //{\r
+ // while(count > 0)\r
+ // {\r
+ // auto frame = frame_factory->create_frame(reinterpret_cast<void*>(rand()), format_desc_.width, height_);\r
+ // if(count >= frame->image_data().size())\r
+ // { \r
+ // count -= frame->image_data().size();\r
+ // }\r
+ // else\r
+ // {\r
+ // fast_memclr(frame->image_data().begin(), frame->image_data().size()); \r
+ // //std::copy_n(bytes, count, frame->image_data().begin() + format_desc_.size - count);\r
+ // count = 0;\r
+ // }\r
+ // \r
+ // frame->commit();\r
+ // frames_.push_back(frame);\r
+ // }\r
+ //}\r
+ }\r
+ \r
+ // frame_producer\r
+\r
+ virtual safe_ptr<core::basic_frame> receive()\r
+ {\r
+ pixel_offset_ += speed_;\r
+\r
+ if(frames_.empty())\r
+ return core::basic_frame::eof();\r
+\r
+ for(size_t n = 0; n < frames_.size(); ++n)\r
+ 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
+\r
+ return core::basic_frame(frames_);\r
+ }\r
+ \r
+ virtual std::wstring print() const\r
+ {\r
+ return L"image_scroll_producer[" + filename_ + L"]";\r
+ }\r
+};\r
+\r
+safe_ptr<core::frame_producer> create_image_scroll_producer(const safe_ptr<core::frame_factory>& frame_factory, const std::vector<std::wstring>& params)\r
+{\r
+ 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
+ std::wstring filename = env::media_folder() + L"\\" + params[0];\r
+ \r
+ auto ext = std::find_if(extensions.begin(), extensions.end(), [&](const std::wstring& ex) -> bool\r
+ { \r
+ return boost::filesystem::is_regular_file(boost::filesystem::wpath(filename).replace_extension(ex));\r
+ });\r
+\r
+ if(ext == extensions.end())\r
+ return core::frame_producer::empty();\r
+ \r
+ size_t speed = 0;\r
+ auto speed_it = std::find(params.begin(), params.end(), L"SPEED");\r
+ if(speed_it != params.end())\r
+ {\r
+ if(++speed_it != params.end())\r
+ speed = boost::lexical_cast<int>(*speed_it);\r
+ }\r
+\r
+ if(speed == 0)\r
+ return core::frame_producer::empty();\r
+\r
+ return make_safe<image_scroll_producer>(frame_factory, filename + L"." + *ext, speed);\r
+}\r
+\r
+\r
+}
\ No newline at end of file
--- /dev/null
+/*\r
+* copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
+*\r
+* This file is part of CasparCG.\r
+*\r
+* CasparCG is free software: you can redistribute it and/or modify\r
+* it under the terms of the GNU General Public License as published by\r
+* the Free Software Foundation, either version 3 of the License, or\r
+* (at your option) any later version.\r
+*\r
+* CasparCG is distributed in the hope that it will be useful,\r
+* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+* GNU General Public License for more details.\r
+\r
+* You should have received a copy of the GNU General Public License\r
+* along with CasparCG. If not, see <http://www.gnu.org/licenses/>.\r
+*\r
+*/\r
+#pragma once\r
+\r
+#include <core/producer/frame_producer.h>\r
+\r
+#include <string>\r
+#include <vector>\r
+\r
+namespace caspar { \r
+\r
+safe_ptr<core::frame_producer> create_image_scroll_producer(const safe_ptr<core::frame_factory>& frame_factory, const std::vector<std::wstring>& params);\r
+\r
+}
\ No newline at end of file