2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
4 * This file is part of CasparCG (www.casparcg.com).
6 * CasparCG is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * CasparCG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
19 * Author: Robert Nagy, ronag89@gmail.com
22 #include "image_consumer.h"
24 #include <common/except.h>
25 #include <common/env.h>
26 #include <common/log.h>
27 #include <common/utf.h>
28 #include <common/array.h>
29 #include <common/future.h>
31 #include <core/consumer/frame_consumer.h>
32 #include <core/video_format.h>
33 #include <core/frame/frame.h>
35 #include <boost/date_time/posix_time/posix_time.hpp>
36 #include <boost/thread.hpp>
38 #include <tbb/concurrent_queue.h>
42 #include <FreeImage.h>
46 namespace caspar { namespace image {
48 struct image_consumer : public core::frame_consumer
54 void initialize(const core::video_format_desc&, int) override
58 boost::unique_future<bool> send(core::const_frame frame) override
60 boost::thread async([frame]
64 auto filename = u8(env::data_folder()) + boost::posix_time::to_iso_string(boost::posix_time::second_clock::local_time()) + ".png";
66 auto bitmap = std::shared_ptr<FIBITMAP>(FreeImage_Allocate(static_cast<int>(frame.width()), static_cast<int>(frame.height()), 32), FreeImage_Unload);
67 A_memcpy(FreeImage_GetBits(bitmap.get()), frame.image_data().begin(), frame.image_data().size());
68 FreeImage_FlipVertical(bitmap.get());
69 FreeImage_Save(FIF_PNG, bitmap.get(), filename.c_str(), 0);
73 CASPAR_LOG_CURRENT_EXCEPTION();
78 return wrap_as_future(false);
81 std::wstring print() const override
86 std::wstring name() const override
91 boost::property_tree::wptree info() const override
93 boost::property_tree::wptree info;
94 info.add(L"type", L"image");
98 int buffer_depth() const override
103 int index() const override
108 void subscribe(const monitor::observable::observer_ptr& o) override
112 void unsubscribe(const monitor::observable::observer_ptr& o) override
117 spl::shared_ptr<core::frame_consumer> create_consumer(const std::vector<std::wstring>& params)
119 if(params.size() < 1 || params[0] != L"IMAGE")
120 return core::frame_consumer::empty();
122 return spl::make_shared<image_consumer>();