X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=core%2Fproducer%2Fcolor%2Fcolor_producer.cpp;h=a6793b2dec052cb64e382853ed381ecc2d198f75;hb=ccaa3af7e1b264956b40c4dd908442d755aa2b81;hp=58f6888a8753c72ed2eedbcd4e7abae43f17a59a;hpb=39dc5cacc441d19eaa2341e79cd02b50d6f5fbac;p=casparcg
diff --git a/core/producer/color/color_producer.cpp b/core/producer/color/color_producer.cpp
index 58f6888a8..a6793b2de 100644
--- a/core/producer/color/color_producer.cpp
+++ b/core/producer/color/color_producer.cpp
@@ -16,13 +16,18 @@
* You should have received a copy of the GNU General Public License
* along with CasparCG. If not, see .
*
-*/
-
+*/
#include "../../stdafx.h"
#include "color_producer.h"
-#include
+#include "../frame/basic_frame.h"
+#include "../frame/frame_factory.h"
+#include "../../mixer/write_frame.h"
+
+#include
+
+#include
#include
@@ -30,41 +35,92 @@ namespace caspar { namespace core {
class color_producer : public frame_producer
{
- safe_ptr frame_;
- std::wstring color_str_;
- printer parent_printer_;
+ safe_ptr frame_;
+ const std::wstring color_str_;
public:
-
- explicit color_producer(const std::wstring& color)
+ explicit color_producer(const safe_ptr& frame_factory, const std::wstring& color)
: color_str_(color)
- , frame_(draw_frame::empty())
- {
- if(color.length() != 9 || color[0] != '#')
- BOOST_THROW_EXCEPTION(invalid_argument() << arg_name_info("color") << arg_value_info(narrow(color)) << msg_info("Invalid color code"));
- }
-
- virtual void initialize(const safe_ptr& frame_factory)
- {
- auto frame = frame_factory->create_frame(1, 1, pixel_format::bgra);
- auto& value = *reinterpret_cast(frame->image_data().begin());
- std::wstringstream str(color_str_.substr(1));
- str >> std::hex >> value;
- frame_ = std::move(frame);
- }
-
- virtual void set_parent_printer(const printer& parent_printer){parent_printer_ = parent_printer;}
+ , frame_(create_color_frame(this, frame_factory, color))
+ {}
+
+ // frame_producer
+
+ virtual safe_ptr receive(int) { return frame_; }
+ virtual safe_ptr last_frame() const { return frame_; }
+ virtual std::wstring print() const { return L"color[" + color_str_ + L"]"; }
+};
+
+std::wstring get_hex_color(const std::wstring& str)
+{
+ if(str.at(0) == '#')
+ return str.length() == 7 ? L"#FF" + str.substr(1) : str;
- virtual safe_ptr receive() { return frame_; }
+ if(boost::iequals(str, L"EMPTY"))
+ return L"#00000000";
+
+ if(boost::iequals(str, L"BLACK"))
+ return L"#FF000000";
- virtual std::wstring print() const { return (parent_printer_ ? parent_printer_() + L"/" : L"") + L"color[" + color_str_ + L"]"; }
-};
+ if(boost::iequals(str, L"WHITE"))
+ return L"#FFFFFFFF";
+
+ if(boost::iequals(str, L"RED"))
+ return L"#FFFF0000";
+
+ if(boost::iequals(str, L"GREEN"))
+ return L"#FF00FF00";
+
+ if(boost::iequals(str, L"BLUE"))
+ return L"#FF0000FF";
+
+ if(boost::iequals(str, L"ORANGE"))
+ return L"#FFFFA500";
+
+ if(boost::iequals(str, L"YELLOW"))
+ return L"#FFFFFF00";
+
+ if(boost::iequals(str, L"BROWN"))
+ return L"#FFA52A2A";
+
+ if(boost::iequals(str, L"GRAY"))
+ return L"#FF808080";
+
+ if(boost::iequals(str, L"TEAL"))
+ return L"#FF008080";
+
+ return str;
+}
-safe_ptr create_color_producer(const std::vector& params)
+safe_ptr create_color_producer(const safe_ptr& frame_factory, const std::vector& params)
{
- if(params.empty() || params[0].at(0) != '#')
- return frame_producer::empty();
- return make_safe(params[0]);
+ if(params.size() < 0)
+ return core::frame_producer::empty();
+
+ auto color2 = get_hex_color(params[0]);
+ if(color2.length() != 9 || color2[0] != '#')
+ return core::frame_producer::empty();
+
+ return make_safe(frame_factory, color2);
+}
+safe_ptr create_color_frame(void* tag, const safe_ptr& frame_factory, const std::wstring& color)
+{
+ auto color2 = get_hex_color(color);
+ if(color2.length() != 9 || color2[0] != '#')
+ BOOST_THROW_EXCEPTION(invalid_argument() << arg_name_info("color") << arg_value_info(narrow(color2)) << msg_info("Invalid color."));
+
+ auto frame = frame_factory->create_frame(tag, 1, 1, pixel_format::bgra);
+
+ // Read color from hex-string and write to frame pixel.
+
+ auto& value = *reinterpret_cast(frame->image_data().begin());
+ std::wstringstream str(color2.substr(1));
+ if(!(str >> std::hex >> value) || !str.eof())
+ BOOST_THROW_EXCEPTION(invalid_argument() << arg_name_info("color") << arg_value_info(narrow(color2)) << msg_info("Invalid color."));
+
+ frame->commit();
+
+ return frame;
}
}}
\ No newline at end of file