]> 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 98e6233aa3e20b1139254e4ec7c78e8918b5ccd0..532fd9d216e141d624da7faaf8502d62167f7984 100644 (file)
@@ -1,3 +1,22 @@
+/*\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
@@ -5,7 +24,8 @@
 #include <core/video_format.h>\r
 \r
 #include <core/producer/frame/basic_frame.h>\r
-#include <core/producer/frame/write_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
-       std::wstring filename_;\r
+       const std::wstring filename_;\r
        safe_ptr<core::basic_frame> frame_;\r
        \r
        explicit image_producer(const safe_ptr<core::frame_factory>& frame_factory, const std::wstring& filename) \r
@@ -29,23 +49,38 @@ struct image_producer : public core::frame_producer
        {\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 safe_ptr<core::basic_frame> receive(){return frame_;}\r
+       // frame_producer\r
 \r
-       \r
-       virtual std::wstring print() const\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
+               return frame_;\r
+       }\r
+\r
+       virtual std::wstring print() const override\r
        {\r
                return L"image_producer[" + filename_ + L"]";\r
        }\r
 };\r
 \r
-safe_ptr<core::frame_producer> create_image_producer(const safe_ptr<core::frame_factory>& frame_factory, 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
@@ -60,4 +95,4 @@ safe_ptr<core::frame_producer> create_image_producer(const safe_ptr<core::frame_
 }\r
 \r
 \r
-}
\ No newline at end of file
+}}
\ No newline at end of file