]> git.sesse.net Git - casparcg/blobdiff - modules/image/producer/image_producer.cpp
2.0.2: Refactoring. AMCP commands now executed asynchronously when possible, which...
[casparcg] / modules / image / producer / image_producer.cpp
index 339d6c5837c0fddca88b889a0413bbdada482aa5..532fd9d216e141d624da7faaf8502d62167f7984 100644 (file)
@@ -1,11 +1,31 @@
+/*\r
+* copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
+*\r
+*  This file is part of CasparCG.\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
+*\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
 #include "image_producer.h"\r
 \r
 #include "../util/image_loader.h"\r
 \r
 #include <core/video_format.h>\r
 \r
-#include <mixer/frame_mixer_device.h>\r
-#include <mixer/frame/draw_frame.h>\r
+#include <core/producer/frame/basic_frame.h>\r
+#include <core/producer/frame/frame_factory.h>\r
+#include <core/mixer/write_frame.h>\r
 \r
 #include <common/env.h>\r
 \r
 \r
 using namespace boost::assign;\r
 \r
-namespace caspar {\r
+namespace caspar { namespace image {\r
 \r
 struct image_producer : public core::frame_producer\r
 {      \r
-       printer parent_printer_;\r
-       std::shared_ptr<core::frame_factory> frame_factory_;\r
-       std::wstring filename_;\r
-       safe_ptr<core::draw_frame> frame_;\r
+       const std::wstring filename_;\r
+       safe_ptr<core::basic_frame> frame_;\r
        \r
-       image_producer(const std::wstring& filename) \r
-               : filename_(filename), frame_(core::draw_frame::empty())        {}\r
-       \r
-       virtual safe_ptr<core::draw_frame> receive(){return frame_;}\r
-\r
-       virtual void initialize(const safe_ptr<core::frame_factory>& frame_factory)\r
+       explicit image_producer(const safe_ptr<core::frame_factory>& frame_factory, const std::wstring& filename) \r
+               : filename_(filename)\r
+               , frame_(core::basic_frame::empty())    \r
        {\r
-               frame_factory_ = frame_factory;\r
                auto bitmap = load_image(filename_);\r
                FreeImage_FlipVertical(bitmap.get());\r
-               auto frame = frame_factory->create_frame(FreeImage_GetWidth(bitmap.get()), FreeImage_GetHeight(bitmap.get()));\r
+               \r
+               core::pixel_format_desc desc;\r
+               desc.pix_fmt = core::pixel_format::bgra;\r
+               desc.planes.push_back(core::pixel_format_desc::plane(FreeImage_GetWidth(bitmap.get()), FreeImage_GetHeight(bitmap.get()), 4));\r
+               auto frame = frame_factory->create_frame(this, desc);\r
+\r
                std::copy_n(FreeImage_GetBits(bitmap.get()), frame->image_data().size(), frame->image_data().begin());\r
+               frame->commit();\r
                frame_ = std::move(frame);\r
        }\r
        \r
-       virtual void set_parent_printer(const printer& parent_printer) \r
+       // frame_producer\r
+\r
+       virtual safe_ptr<core::basic_frame> receive(int) override\r
+       {\r
+               return frame_;\r
+       }\r
+               \r
+       virtual safe_ptr<core::basic_frame> last_frame() const override\r
        {\r
-               parent_printer_ = parent_printer;\r
+               return frame_;\r
        }\r
 \r
-       virtual std::wstring print() const\r
+       virtual std::wstring print() const override\r
        {\r
-               return (parent_printer_ ? parent_printer_() + L"/" : L"") + L"image_producer. filename: " + filename_;\r
+               return L"image_producer[" + filename_ + L"]";\r
        }\r
 };\r
 \r
-safe_ptr<core::frame_producer> create_image_producer(const std::vector<std::wstring>& params)\r
+safe_ptr<core::frame_producer> create_producer(const safe_ptr<core::frame_factory>& frame_factory, const std::vector<std::wstring>& params)\r
 {\r
-       static const std::vector<std::wstring> extensions = list_of(L"png")(L"tga")(L"bmp")(L"jpg")(L"jpeg");\r
+       static const std::vector<std::wstring> extensions = list_of(L"png")(L"tga")(L"bmp")(L"jpg")(L"jpeg")(L"gif")(L"tiff")(L"tif")(L"jp2")(L"jpx")(L"j2k")(L"j2c");\r
        std::wstring filename = env::media_folder() + L"\\" + params[0];\r
        \r
        auto ext = std::find_if(extensions.begin(), extensions.end(), [&](const std::wstring& ex) -> bool\r
@@ -64,8 +91,8 @@ safe_ptr<core::frame_producer> create_image_producer(const std::vector<std::wstr
        if(ext == extensions.end())\r
                return core::frame_producer::empty();\r
 \r
-       return make_safe<image_producer>(filename + L"." + *ext);\r
+       return make_safe<image_producer>(frame_factory, filename + L"." + *ext);\r
 }\r
 \r
 \r
-}
\ No newline at end of file
+}}
\ No newline at end of file