1 #include "image_producer.h"
\r
3 #include "../util/image_loader.h"
\r
5 #include <core/video_format.h>
\r
7 #include <core/producer/frame/basic_frame.h>
\r
8 #include <core/producer/frame/write_frame.h>
\r
10 #include <common/env.h>
\r
12 #include <boost/assign.hpp>
\r
13 #include <boost/filesystem.hpp>
\r
15 #include <algorithm>
\r
17 using namespace boost::assign;
\r
21 struct image_producer : public core::frame_producer
\r
23 std::wstring filename_;
\r
24 safe_ptr<core::basic_frame> frame_;
\r
26 explicit image_producer(const safe_ptr<core::frame_factory>& frame_factory, const std::wstring& filename)
\r
27 : filename_(filename)
\r
28 , frame_(core::basic_frame::empty())
\r
30 auto bitmap = load_image(filename_);
\r
31 FreeImage_FlipVertical(bitmap.get());
\r
32 auto frame = frame_factory->create_frame(FreeImage_GetWidth(bitmap.get()), FreeImage_GetHeight(bitmap.get()));
\r
33 std::copy_n(FreeImage_GetBits(bitmap.get()), frame->image_data().size(), frame->image_data().begin());
\r
34 frame_ = std::move(frame);
\r
37 virtual safe_ptr<core::basic_frame> receive(){return frame_;}
\r
40 virtual std::wstring print() const
\r
42 return L"image_producer[" + filename_ + L"]";
\r
46 safe_ptr<core::frame_producer> create_image_producer(const safe_ptr<core::frame_factory>& frame_factory, const std::vector<std::wstring>& params)
\r
48 static const std::vector<std::wstring> extensions = list_of(L"png")(L"tga")(L"bmp")(L"jpg")(L"jpeg");
\r
49 std::wstring filename = env::media_folder() + L"\\" + params[0];
\r
51 auto ext = std::find_if(extensions.begin(), extensions.end(), [&](const std::wstring& ex) -> bool
\r
53 return boost::filesystem::is_regular_file(boost::filesystem::wpath(filename).replace_extension(ex));
\r
56 if(ext == extensions.end())
\r
57 return core::frame_producer::empty();
\r
59 return make_safe<image_producer>(frame_factory, filename + L"." + *ext);
\r