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
21 #include "../../stdafx.h"
\r
23 #include "color_producer.h"
\r
25 #include "../../frame/frame_format.h"
\r
28 #pragma intrinsic(__movsd, __stosd)
\r
30 namespace caspar { namespace core {
\r
32 class color_producer : public frame_producer
\r
35 explicit color_producer(unsigned long color_value, const frame_format_desc& format_desc) : format_desc_(format_desc){}
\r
37 gpu_frame_ptr get_frame() { return frame_; }
\r
38 const frame_format_desc& get_frame_format_desc() const { return format_desc_; }
\r
40 void initialize(const frame_factory_ptr& factory)
\r
42 frame_ = factory->create_frame(format_desc_);
\r
43 __stosd(reinterpret_cast<unsigned long*>(frame_->data()), color_value_, frame_->size() / sizeof(unsigned long));
\r
46 frame_format_desc format_desc_;
\r
47 gpu_frame_ptr frame_;
\r
48 unsigned long color_value_;
\r
61 unsigned long value;
\r
64 unsigned long get_pixel_color_value(const std::wstring& parameter)
\r
66 std::wstring color_code;
\r
67 if(parameter.length() != 9 || parameter[0] != '#')
\r
68 BOOST_THROW_EXCEPTION(invalid_argument() << arg_name_info("parameter") << arg_value_info(common::narrow(parameter)) << msg_info("Invalid color code"));
\r
70 color_code = parameter.substr(1);
\r
73 color.value = _tcstoul(color_code.c_str(), 0, 16);
\r
74 unsigned char temp = color.comp.a;
\r
75 color.comp.a = color.comp.b;
\r
76 color.comp.b = temp;
\r
77 temp = color.comp.r;
\r
78 color.comp.r = color.comp.g;
\r
79 color.comp.g = temp;
\r
84 frame_producer_ptr create_color_producer(const std::vector<std::wstring>& params, const frame_format_desc& format_desc)
\r
86 if(params.empty() || params[0].at(0) != '#')
\r
88 return std::make_shared<color_producer>(get_pixel_color_value(params[0]), format_desc);
\r