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_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/mixer/write_frame.h>
\r
29 #include <common/env.h>
\r
31 #include <boost/assign.hpp>
\r
32 #include <boost/filesystem.hpp>
\r
34 #include <algorithm>
\r
36 using namespace boost::assign;
\r
40 struct image_producer : public core::frame_producer
\r
42 const std::wstring filename_;
\r
43 safe_ptr<core::basic_frame> frame_;
\r
45 explicit image_producer(const safe_ptr<core::frame_factory>& frame_factory, const std::wstring& filename)
\r
46 : filename_(filename)
\r
47 , frame_(core::basic_frame::empty())
\r
49 auto bitmap = load_image(filename_);
\r
50 FreeImage_FlipVertical(bitmap.get());
\r
51 auto frame = frame_factory->create_frame(this, FreeImage_GetWidth(bitmap.get()), FreeImage_GetHeight(bitmap.get()), core::pixel_format::bgra);
\r
52 std::copy_n(FreeImage_GetBits(bitmap.get()), frame->image_data().size(), frame->image_data().begin());
\r
54 frame_ = std::move(frame);
\r
59 virtual safe_ptr<core::basic_frame> receive(int){return frame_;}
\r
61 virtual safe_ptr<core::basic_frame> last_frame() const
\r
66 virtual std::wstring print() const
\r
68 return L"image_producer[" + filename_ + L"]";
\r
72 safe_ptr<core::frame_producer> create_image_producer(const safe_ptr<core::frame_factory>& frame_factory, const std::vector<std::wstring>& params)
\r
74 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
75 std::wstring filename = env::media_folder() + L"\\" + params[0];
\r
77 auto ext = std::find_if(extensions.begin(), extensions.end(), [&](const std::wstring& ex) -> bool
\r
79 return boost::filesystem::is_regular_file(boost::filesystem::wpath(filename).replace_extension(ex));
\r
82 if(ext == extensions.end())
\r
83 return core::frame_producer::empty();
\r
85 return make_safe<image_producer>(frame_factory, filename + L"." + *ext);
\r