\r
#include "color_producer.h"\r
\r
-#include "../../format/video_format.h"\r
+#include <mixer/frame/draw_frame.h>\r
\r
-#include <intrin.h>\r
-#pragma intrinsic(__movsd, __stosd)\r
+#include <sstream>\r
\r
namespace caspar { namespace core {\r
\r
-unsigned int get_pixel_color_value(const std::wstring& parameter)\r
-{\r
- union Color \r
- {\r
- struct Components \r
- {\r
- unsigned char a;\r
- unsigned char r;\r
- unsigned char g;\r
- unsigned char b;\r
- } comp;\r
-\r
- unsigned int value;\r
- };\r
-\r
- std::wstring color_code;\r
- if(parameter.length() != 9 || parameter[0] != '#')\r
- BOOST_THROW_EXCEPTION(invalid_argument() << arg_name_info("parameter") << arg_value_info(common::narrow(parameter)) << msg_info("Invalid color code"));\r
- \r
- color_code = parameter.substr(1);\r
-\r
- Color color;\r
- color.value = _tcstoul(color_code.c_str(), 0, 16);\r
- unsigned char temp = color.comp.a;\r
- color.comp.a = color.comp.b;\r
- color.comp.b = temp;\r
- temp = color.comp.r;\r
- color.comp.r = color.comp.g;\r
- color.comp.g = temp;\r
-\r
- return color.value;\r
-}\r
-\r
class color_producer : public frame_producer\r
{\r
+ safe_ptr<draw_frame> frame_;\r
+ std::wstring color_str_;\r
+ printer parent_printer_;\r
+\r
public:\r
- explicit color_producer(const std::wstring& color) : color_str_(color), color_value_(get_pixel_color_value(color)){}\r
- \r
- gpu_frame_ptr receive()\r
- { \r
- return frame_;\r
- }\r
\r
- void initialize(const frame_processor_device_ptr& frame_processor)\r
+ explicit color_producer(const std::wstring& color) : color_str_(color), frame_(draw_frame::empty())\r
{\r
- auto frame = frame_processor->create_frame();\r
- __stosd(reinterpret_cast<unsigned long*>(frame->data().begin()), color_value_, frame->data().size() / sizeof(unsigned long));\r
- frame_ = frame;\r
+ if(color.length() != 9 || color[0] != '#')\r
+ BOOST_THROW_EXCEPTION(invalid_argument() << arg_name_info("color") << arg_value_info(narrow(color)) << msg_info("Invalid color code"));\r
}\r
- \r
- std::wstring print() const\r
+\r
+ virtual void initialize(const safe_ptr<frame_factory>& frame_factory)\r
{\r
- return + L"color_producer. color: " + color_str_;\r
+ auto frame = frame_factory->create_frame(1, 1, pixel_format::bgra);\r
+ auto& value = *reinterpret_cast<unsigned long*>(frame->image_data().begin());\r
+ std::wstringstream str(color_str_.substr(1));\r
+ str >> std::hex >> value; \r
+ frame_ = std::move(frame);\r
}\r
\r
- gpu_frame_ptr frame_;\r
- unsigned int color_value_;\r
- std::wstring color_str_;\r
+ virtual void set_parent_printer(const printer& parent_printer){parent_printer_ = parent_printer;}\r
+ \r
+ virtual safe_ptr<draw_frame> receive() { return frame_; }\r
+ \r
+ virtual std::wstring print() const { return (parent_printer_ ? parent_printer_() + L"/" : L"") + L"color[" + color_str_ + L"]"; }\r
};\r
\r
-frame_producer_ptr create_color_producer(const std::vector<std::wstring>& params)\r
+safe_ptr<frame_producer> create_color_producer(const std::vector<std::wstring>& params)\r
{\r
if(params.empty() || params[0].at(0) != '#')\r
- return nullptr;\r
- return std::make_shared<color_producer>(params[0]);\r
+ return frame_producer::empty();\r
+ return make_safe<color_producer>(params[0]);\r
}\r
\r
}}
\ No newline at end of file