]> git.sesse.net Git - casparcg/blobdiff - core/producer/color/color_producer.cpp
2.1.0: Refactored away "write_frame", only "data_frame" and "draw_frame" are needed.
[casparcg] / core / producer / color / color_producer.cpp
index b6b738c8d00e3c49fd274485b1b3386c0fe72a18..2879623ef3bb0bc27454a8dd0905f179cf2a11c7 100644 (file)
@@ -1,31 +1,35 @@
 /*\r
-* copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
+* Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>\r
 *\r
-*  This file is part of CasparCG.\r
+* This file is part of CasparCG (www.casparcg.com).\r
 *\r
-*    CasparCG is free software: you can redistribute it and/or modify\r
-*    it under the terms of the GNU General Public License as published by\r
-*    the Free Software Foundation, either version 3 of the License, or\r
-*    (at your option) any later version.\r
+* CasparCG is free software: you can redistribute it and/or modify\r
+* it under the terms of the GNU General Public License as published by\r
+* the Free Software Foundation, either version 3 of the License, or\r
+* (at your option) any later version.\r
 *\r
-*    CasparCG is distributed in the hope that it will be useful,\r
-*    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
-*    GNU General Public License for more details.\r
-\r
-*    You should have received a copy of the GNU General Public License\r
-*    along with CasparCG.  If not, see <http://www.gnu.org/licenses/>.\r
+* CasparCG is distributed in the hope that it will be useful,\r
+* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+* GNU General Public License for more details.\r
+*\r
+* You should have received a copy of the GNU General Public License\r
+* along with CasparCG. If not, see <http://www.gnu.org/licenses/>.\r
 *\r
-*/ \r
+* Author: Robert Nagy, ronag89@gmail.com\r
+*/\r
+\r
 #include "../../stdafx.h"\r
 \r
 #include "color_producer.h"\r
 \r
-#include "../frame/basic_frame.h"\r
-#include "../frame/frame_factory.h"\r
-#include "../../mixer/write_frame.h"\r
+#include <core/producer/frame_producer.h>\r
+#include <core/frame/data_frame.h>\r
+#include <core/frame/draw_frame.h>\r
+#include <core/frame/frame_factory.h>\r
+#include <core/frame/pixel_format.h>\r
 \r
-#include <common/exception/exceptions.h>\r
+#include <common/except.h>\r
 \r
 #include <boost/algorithm/string.hpp>\r
 \r
@@ -35,30 +39,43 @@ namespace caspar { namespace core {
        \r
 class color_producer : public frame_producer\r
 {\r
-       safe_ptr<basic_frame> frame_;\r
+       spl::shared_ptr<draw_frame> frame_;\r
        const std::wstring color_str_;\r
 \r
 public:\r
-       explicit color_producer(const safe_ptr<core::frame_factory>& frame_factory, const std::wstring& color) \r
+       explicit color_producer(const spl::shared_ptr<core::frame_factory>& frame_factory, const std::wstring& color) \r
                : color_str_(color)\r
                , frame_(create_color_frame(this, frame_factory, color))\r
        {}\r
 \r
        // frame_producer\r
                        \r
-       virtual safe_ptr<basic_frame> receive(int) override\r
+       virtual spl::shared_ptr<draw_frame> receive(int) override\r
        {\r
                return frame_;\r
        }       \r
+       \r
+       virtual std::wstring print() const override\r
+       {\r
+               return L"color[" + color_str_ + L"]";\r
+       }\r
 \r
-       virtual safe_ptr<basic_frame> last_frame() const override\r
+       virtual std::wstring name() const override\r
        {\r
-               return frame_; \r
-       }       \r
+               return L"color";\r
+       }\r
 \r
-       virtual std::wstring print() const override\r
+       virtual spl::shared_ptr<draw_frame> last_frame() const override\r
        {\r
-               return L"color[" + color_str_ + L"]";\r
+               return frame_;\r
+       }\r
+\r
+       boost::property_tree::wptree info() const override\r
+       {\r
+               boost::property_tree::wptree info;\r
+               info.add(L"type", L"color");\r
+               info.add(L"color", color_str_);\r
+               return info;\r
        }\r
 };\r
 \r
@@ -103,7 +120,7 @@ std::wstring get_hex_color(const std::wstring& str)
        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
+spl::shared_ptr<frame_producer> create_color_producer(const spl::shared_ptr<frame_factory>& frame_factory, const std::vector<std::wstring>& params)\r
 {\r
        if(params.size() < 0)\r
                return core::frame_producer::empty();\r
@@ -112,26 +129,26 @@ safe_ptr<frame_producer> create_color_producer(const safe_ptr<core::frame_factor
        if(color2.length() != 9 || color2[0] != '#')\r
                return core::frame_producer::empty();\r
 \r
-       return make_safe<color_producer>(frame_factory, color2);\r
+       return core::wrap_producer(spl::make_shared<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
+spl::shared_ptr<draw_frame> create_color_frame(void* tag, const spl::shared_ptr<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
-       auto frame = frame_factory->create_frame(tag, 1, 1, pixel_format::bgra);\r
+               BOOST_THROW_EXCEPTION(invalid_argument() << arg_name_info("color") << arg_value_info(color2) << msg_info("Invalid color."));\r
+       \r
+       core::pixel_format_desc desc(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
+       auto& value = *reinterpret_cast<uint32_t*>(frame->image_data(0).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
+               BOOST_THROW_EXCEPTION(invalid_argument() << arg_name_info("color") << arg_value_info(color2) << msg_info("Invalid color."));\r
+                       \r
+       return spl::make_shared<draw_frame>(frame);\r
 }\r
 \r
 }}
\ No newline at end of file