]> git.sesse.net Git - casparcg/blobdiff - core/producer/color/color_producer.cpp
2.0.0.2: Improved logging. Added "parent logging".
[casparcg] / core / producer / color / color_producer.cpp
index 58d2fd5315d1f7ab3e5d3cfdc8f7905ecc29e44e..1f8484e5517c9ce2ff7f40dfa96c69774a166fac 100644 (file)
 \r
 #include "color_producer.h"\r
 \r
-#include "../../frame/frame_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
+       \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(unsigned int color_value, const frame_format_desc& format_desc) \r
-               : color_value_(color_value), format_desc_(format_desc){}\r
 \r
-       gpu_frame_ptr get_frame()\r
-       { \r
-               return frame_;\r
-       }\r
-       const frame_format_desc& get_frame_format_desc() const { return format_desc_; }\r
-       \r
-       void initialize(const frame_factory_ptr& factory)\r
+       explicit color_producer(const std::wstring& color) : color_str_(color), frame_(draw_frame::empty())\r
        {\r
-               frame_ = factory->create_frame(format_desc_);\r
-               __stosd(reinterpret_cast<unsigned long*>(frame_->data()), color_value_, frame_->size() / sizeof(unsigned long));\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
-       frame_format_desc format_desc_;\r
-       gpu_frame_ptr frame_;\r
-       unsigned int color_value_;\r
-};\r
-\r
-union Color \r
-{\r
-       struct Components \r
+       virtual void initialize(const safe_ptr<frame_factory>& frame_factory)\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
+               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
-unsigned int get_pixel_color_value(const std::wstring& parameter)\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
+       virtual void set_parent_printer(const printer& parent_printer){parent_printer_ = parent_printer;}\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
+       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, const frame_format_desc& format_desc)\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>(get_pixel_color_value(params[0]), format_desc);\r
+               return frame_producer::empty();\r
+       return make_safe<color_producer>(params[0]);\r
 }\r
 \r
 }}
\ No newline at end of file