]> git.sesse.net Git - casparcg/commitdiff
2.0. color_producer: Misc improvements.
authorronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Mon, 15 Aug 2011 11:08:52 +0000 (11:08 +0000)
committerronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Mon, 15 Aug 2011 11:08:52 +0000 (11:08 +0000)
git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches/2.0.0.2@1181 362d55ac-95cf-4e76-9f9a-cbaa9c17b72d

core/producer/color/color_producer.cpp
core/producer/frame_producer.cpp

index aa6e3a6317139fc6ca2795b048d8c11a4ca9d842..7c14aaf281f6e2fe66f1ebbc6bcaa955c664c0d4 100644 (file)
@@ -27,6 +27,8 @@
 \r
 #include <common/exception/exceptions.h>\r
 \r
+#include <boost/algorithm/string.hpp>\r
+\r
 #include <sstream>\r
 \r
 namespace caspar { namespace core {\r
@@ -49,24 +51,69 @@ public:
        virtual std::wstring print() const { return L"color[" + color_str_ + L"]"; }\r
 };\r
 \r
-safe_ptr<frame_producer> create_color_producer(const safe_ptr<core::frame_factory>& frame_factory, const std::vector<std::wstring>& params)\r
+std::wstring get_hex_color(const std::wstring& str)\r
 {\r
-       if(params.empty() || params[0].at(0) != '#')\r
-               return frame_producer::empty();\r
-       return make_safe<color_producer>(frame_factory, params[0]);\r
+       if(str.at(0) == '#')\r
+               return str.length() == 7 ? L"#FF" + str.substr(1) : str;\r
+       \r
+       if(boost::iequals(str, L"BLACK"))\r
+               return L"#000000FF";\r
+       \r
+       if(boost::iequals(str, L"WHITE"))\r
+               return L"#FFFFFFFF";\r
+       \r
+       if(boost::iequals(str, L"RED"))\r
+               return L"#FFFF0000";\r
+       \r
+       if(boost::iequals(str, L"GREEN"))\r
+               return L"#FF00FF00";\r
+       \r
+       if(boost::iequals(str, L"BLUE"))\r
+               return L"#FF0000FF";    \r
+       \r
+       if(boost::iequals(str, L"ORANGE"))\r
+               return L"#FFFFA500";    \r
+       \r
+       if(boost::iequals(str, L"YELLOW"))\r
+               return L"#FFFFFF00";\r
+       \r
+       if(boost::iequals(str, L"BROWN"))\r
+               return L"#FFA52A2A";\r
+       \r
+       if(boost::iequals(str, L"GRAY"))\r
+               return L"#FF808080";\r
+       \r
+       if(boost::iequals(str, L"TEAL"))\r
+               return L"#FF008080";\r
+       \r
+       return str;\r
 }\r
 \r
+safe_ptr<frame_producer> create_color_producer(const safe_ptr<core::frame_factory>& frame_factory, const std::vector<std::wstring>& params)\r
+{\r
+       if(params.size() < 0)\r
+               return core::frame_producer::empty();\r
+\r
+       auto color2 = get_hex_color(params[0]);\r
+       if(color2.length() != 9 || color2[0] != '#')\r
+               return core::frame_producer::empty();\r
+\r
+       return make_safe<color_producer>(frame_factory, color2);\r
+}\r
 safe_ptr<core::write_frame> create_color_frame(void* tag, const safe_ptr<core::frame_factory>& frame_factory, const std::wstring& color)\r
 {\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
+       auto color2 = get_hex_color(color);\r
+       if(color2.length() != 9 || color2[0] != '#')\r
+               BOOST_THROW_EXCEPTION(invalid_argument() << arg_name_info("color") << arg_value_info(narrow(color2)) << msg_info("Invalid color."));\r
 \r
        auto frame = frame_factory->create_frame(tag, 1, 1, pixel_format::bgra);\r
                \r
        // Read color from hex-string and write to frame pixel.\r
+\r
        auto& value = *reinterpret_cast<uint32_t*>(frame->image_data().begin());\r
-       std::wstringstream str(color.substr(1));\r
-       str >> std::hex >> value;\r
+       std::wstringstream str(color2.substr(1));\r
+       if(!(str >> std::hex >> value) || !str.eof())\r
+               BOOST_THROW_EXCEPTION(invalid_argument() << arg_name_info("color") << arg_value_info(narrow(color2)) << msg_info("Invalid color."));\r
 \r
        frame->commit();\r
                \r
index 548d8314a4c931b384e7e59601c00371cd435253..04400539c269a031de41aa792adf145e326395cb 100644 (file)
@@ -85,7 +85,7 @@ safe_ptr<core::frame_producer> do_create_producer(const safe_ptr<frame_factory>&
                        }\r
                        catch(...)\r
                        {\r
-                               CASPAR_LOG_CURRENT_EXCEPTION();\r
+                               //CASPAR_LOG_CURRENT_EXCEPTION();\r
                        }\r
                        return producer != frame_producer::empty();\r
                });\r