- if(params.empty() || params[0].at(0) != '#')\r
- return frame_producer::empty();\r
- return make_safe<color_producer>(params[0]);\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
+ 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
+ core::pixel_format_desc desc;\r
+ desc.pix_fmt = pixel_format::bgra;\r
+ desc.planes.push_back(core::pixel_format_desc::plane(1, 1, 4));\r
+ auto frame = frame_factory->create_frame(tag, desc);\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(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
+ return frame;\r