* along with CasparCG. If not, see <http://www.gnu.org/licenses/>.\r
*\r
*/\r
+// TODO: Refactor.\r
+// TODO: Looping.\r
+\r
#include "image_scroll_producer.h"\r
\r
#include "../util/image_loader.h"\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/producer/frame/frame_factory.h>\r
+#include <core/producer/frame/frame_transform.h>\r
#include <core/mixer/write_frame.h>\r
\r
#include <common/env.h>\r
#include <boost/assign.hpp>\r
#include <boost/filesystem.hpp>\r
#include <boost/foreach.hpp>\r
+#include <boost/lexical_cast.hpp>\r
\r
#include <algorithm>\r
+#include <array>\r
\r
using namespace boost::assign;\r
\r
-namespace caspar {\r
-\r
-enum direction\r
-{\r
- down,\r
- right\r
-};\r
- \r
+namespace caspar { namespace image {\r
+ \r
struct image_scroll_producer : public core::frame_producer\r
{ \r
const std::wstring filename_;\r
int speed_;\r
\r
std::array<double, 2> start_offset_;\r
+\r
+ safe_ptr<core::basic_frame> last_frame_;\r
\r
explicit image_scroll_producer(const safe_ptr<core::frame_factory>& frame_factory, const std::wstring& filename, int speed) \r
: filename_(filename)\r
, delta_(0)\r
, format_desc_(frame_factory->get_video_format_desc())\r
, speed_(speed)\r
+ , last_frame_(core::basic_frame::empty())\r
{\r
start_offset_.assign(0.0);\r
\r
fast_memclr(frame->image_data().begin(), frame->image_data().size()); \r
int width2 = width_ % format_desc_.width;\r
for(size_t y = 0; y < height_; ++y)\r
- std::copy_n(bytes + i * format_desc_.width*4 + y * width_*4,width2*4, frame->image_data().begin() + y * format_desc_.width*4);\r
+ std::copy_n(bytes + i * format_desc_.width*4 + y * width_*4, width2*4, frame->image_data().begin() + y * format_desc_.width*4);\r
\r
count = 0;\r
}\r
\r
// frame_producer\r
\r
- virtual safe_ptr<core::basic_frame> receive()\r
- {\r
+ virtual safe_ptr<core::basic_frame> receive(int)\r
+ { \r
delta_ += speed_;\r
\r
if(frames_.empty())\r
\r
if(height_ > format_desc_.height)\r
{\r
+ if(static_cast<size_t>(std::abs(delta_)) >= height_ - format_desc_.height)\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(start_offset_[0], start_offset_[1] -0.5*(n+1) + delta_ * 0.5/static_cast<double>(format_desc_.height));\r
+ {\r
+ frames_[n]->get_frame_transform().fill_translation[0] = start_offset_[0];\r
+ frames_[n]->get_frame_transform().fill_translation[1] = start_offset_[1] - (n+1) + delta_ * 0.5/static_cast<double>(format_desc_.height);\r
+ }\r
}\r
else\r
{\r
+ if(static_cast<size_t>(std::abs(delta_)) >= width_ - format_desc_.width)\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(start_offset_[0] -0.5*(n+1) + delta_ * 0.5/static_cast<double>(format_desc_.height), start_offset_[1]);\r
+ {\r
+ frames_[n]->get_frame_transform().fill_translation[0] = start_offset_[0] - (n+1) + delta_ * 0.5/static_cast<double>(format_desc_.width); \r
+ frames_[n]->get_frame_transform().fill_translation[1] = start_offset_[1];\r
+ }\r
}\r
\r
- return core::basic_frame(frames_);\r
+ return last_frame_ = core::basic_frame(frames_);\r
+ }\r
+\r
+ virtual safe_ptr<core::basic_frame> last_frame() const\r
+ {\r
+ return last_frame_;\r
}\r
\r
virtual std::wstring print() const\r
{\r
return L"image_scroll_producer[" + filename_ + L"]";\r
}\r
+\r
+ virtual int64_t nb_frames() const \r
+ {\r
+ if(height_ > format_desc_.height)\r
+ {\r
+ auto length = (height_ - format_desc_.height);\r
+ return length/std::abs(speed_);// + length % std::abs(delta_));\r
+ }\r
+ else\r
+ {\r
+ auto length = (width_ - format_desc_.width);\r
+ auto result = length/std::abs(speed_);// + length % std::abs(delta_));\r
+ return result;\r
+ }\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
+safe_ptr<core::frame_producer> create_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
return make_safe<image_scroll_producer>(frame_factory, filename + L"." + *ext, speed);\r
}\r
\r
-\r
-}
\ No newline at end of file
+}}
\ No newline at end of file