]> git.sesse.net Git - casparcg/commitdiff
2.0.0.2: image: Started working on image_scroll_producer.
authorronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Thu, 28 Jul 2011 15:13:25 +0000 (15:13 +0000)
committerronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Thu, 28 Jul 2011 15:13:25 +0000 (15:13 +0000)
git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches/2.0.0.2@1004 362d55ac-95cf-4e76-9f9a-cbaa9c17b72d

common/memory/memclr.h
core/producer/frame/basic_frame.cpp
core/producer/frame/basic_frame.h
modules/image/image.cpp
modules/image/image.vcxproj
modules/image/image.vcxproj.filters
modules/image/producer/image_producer.cpp
modules/image/producer/image_scroll_producer.cpp [new file with mode: 0644]
modules/image/producer/image_scroll_producer.h [new file with mode: 0644]

index c3ee149a88f21088a10d9352fe991a1dd9ba4563..7f65869ed2888dec7c0f66ca0831d2a4e57f33be 100644 (file)
@@ -21,6 +21,8 @@
 \r
 #include <assert.h>\r
 \r
+#include <cstring>\r
+\r
 namespace caspar {\r
 \r
 static void* fast_memclr(void* dest, size_t count)\r
index 3c9cd776d6e449cec821eeb43521e36b87493bd8..91f78b54fdb80854d1cc230e619fa056de5c99cb 100644 (file)
@@ -57,6 +57,7 @@ public:
 };\r
        \r
 basic_frame::basic_frame() : impl_(new implementation(std::vector<safe_ptr<basic_frame>>())){}\r
+basic_frame::basic_frame(const std::vector<safe_ptr<basic_frame>>& frames) : impl_(new implementation(frames)){}\r
 basic_frame::basic_frame(const basic_frame& other) : impl_(new implementation(*other.impl_)){}\r
 basic_frame::basic_frame(std::vector<safe_ptr<basic_frame>>&& frames) : impl_(new implementation(frames)){}\r
 basic_frame::basic_frame(const safe_ptr<basic_frame>& frame) : impl_(new implementation(frame)){}\r
index 1ab7546db83bd98db226f606e8dacf7ff76ac82a..d6d57d0ea753a9c92b656e6df96e34ce57a97ae8 100644 (file)
@@ -41,6 +41,7 @@ public:
        basic_frame();  \r
        basic_frame(const safe_ptr<basic_frame>& frame);\r
        basic_frame(safe_ptr<basic_frame>&& frame);\r
+       basic_frame(const std::vector<safe_ptr<basic_frame>>& frames);\r
 \r
        void swap(basic_frame& other);\r
        \r
index 36c998c3a9ee32a5ee48df8f83205d1cd919fc97..e010fd28807414808c95a328d2689b5a57cf2db6 100644 (file)
@@ -20,6 +20,7 @@
 #include "image.h"\r
 \r
 #include "producer/image_producer.h"\r
+#include "producer/image_scroll_producer.h"\r
 \r
 #include <core/producer/frame_producer.h>\r
 \r
@@ -31,6 +32,7 @@ namespace caspar {
 \r
 void init_image()\r
 {\r
+       core::register_producer_factory(create_image_scroll_producer);\r
        core::register_producer_factory(create_image_producer);\r
 }\r
 \r
index 4468ae604f1f5e789cb209801e9097e23a00b300..4c12131f8b717ea7eed63a251741ab75bb1a148b 100644 (file)
       <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Develop|Win32'">NotUsing</PrecompiledHeader>\r
       <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>\r
     </ClCompile>\r
+    <ClCompile Include="producer\image_scroll_producer.cpp" />\r
     <ClCompile Include="util\image_loader.cpp" />\r
   </ItemGroup>\r
   <ItemGroup>\r
     <ClInclude Include="image.h" />\r
     <ClInclude Include="producer\image_producer.h" />\r
+    <ClInclude Include="producer\image_scroll_producer.h" />\r
     <ClInclude Include="util\image_loader.h" />\r
   </ItemGroup>\r
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />\r
index 3bdec78306a1d7b7c2274279bddf37ee9074fae3..9f76fb774f2d543a2c7c9841d68dcafb5bd98f31 100644 (file)
@@ -21,6 +21,9 @@
     <ClCompile Include="image.cpp">\r
       <Filter>source</Filter>\r
     </ClCompile>\r
+    <ClCompile Include="producer\image_scroll_producer.cpp">\r
+      <Filter>source\producer</Filter>\r
+    </ClCompile>\r
   </ItemGroup>\r
   <ItemGroup>\r
     <ClInclude Include="producer\image_producer.h">\r
@@ -32,5 +35,8 @@
     <ClInclude Include="image.h">\r
       <Filter>source</Filter>\r
     </ClInclude>\r
+    <ClInclude Include="producer\image_scroll_producer.h">\r
+      <Filter>source\producer</Filter>\r
+    </ClInclude>\r
   </ItemGroup>\r
 </Project>
\ No newline at end of file
index d19a0fac2bab2567039849373c160d7863dfe672..09dbd929a326f35c0f5bec117d6ddce995c9fa06 100644 (file)
@@ -48,7 +48,7 @@ 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(this, FreeImage_GetWidth(bitmap.get()), FreeImage_GetHeight(bitmap.get()));\r
+               auto frame = frame_factory->create_frame(this, FreeImage_GetWidth(bitmap.get()), FreeImage_GetHeight(bitmap.get()), core::pixel_format::bgra);\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
diff --git a/modules/image/producer/image_scroll_producer.cpp b/modules/image/producer/image_scroll_producer.cpp
new file mode 100644 (file)
index 0000000..17879ee
--- /dev/null
@@ -0,0 +1,167 @@
+/*\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_scroll_producer.h"\r
+\r
+#include "../util/image_loader.h"\r
+\r
+#include <core/video_format.h>\r
+\r
+#include <core/producer/frame/basic_frame.h>\r
+#include <core/producer/frame/image_transform.h>\r
+#include <core/mixer/write_frame.h>\r
+\r
+#include <common/env.h>\r
+#include <common/memory/memclr.h>\r
+#include <common/exception/exceptions.h>\r
+\r
+#include <boost/assign.hpp>\r
+#include <boost/filesystem.hpp>\r
+#include <boost/foreach.hpp>\r
+\r
+#include <algorithm>\r
+\r
+using namespace boost::assign;\r
+\r
+namespace caspar {\r
+\r
+enum direction\r
+{\r
+       down,\r
+       right\r
+};\r
+       \r
+struct image_scroll_producer : public core::frame_producer\r
+{      \r
+       const std::wstring                                                      filename_;\r
+       std::vector<safe_ptr<core::basic_frame>>        frames_;\r
+       size_t                                                                          pixel_offset_;\r
+       core::video_format_desc                                         format_desc_;\r
+       size_t                                                                          width_;\r
+       size_t                                                                          height_;\r
+       size_t                                                                          speed_;\r
+       \r
+       explicit image_scroll_producer(const safe_ptr<core::frame_factory>& frame_factory, const std::wstring& filename, size_t speed) \r
+               : filename_(filename)\r
+               , pixel_offset_(0)\r
+               , format_desc_(frame_factory->get_video_format_desc())\r
+               , speed_(speed)\r
+       {\r
+               auto bitmap = load_image(filename_);\r
+               FreeImage_FlipVertical(bitmap.get());\r
+\r
+               width_  = FreeImage_GetWidth(bitmap.get());\r
+               height_ = FreeImage_GetHeight(bitmap.get());\r
+\r
+               auto bytes = FreeImage_GetBits(bitmap.get());\r
+               int count = width_*height_*4;\r
+\r
+               if(height_ > format_desc_.height)\r
+               {\r
+                       while(count > 0)\r
+                       {\r
+                               auto frame = frame_factory->create_frame(reinterpret_cast<void*>(rand()), width_, format_desc_.height);\r
+                               if(count >= frame->image_data().size())\r
+                               {       \r
+                                       std::copy_n(bytes + count - frame->image_data().size(), frame->image_data().size(), frame->image_data().begin());\r
+                                       count -= frame->image_data().size();\r
+                               }\r
+                               else\r
+                               {\r
+                                       fast_memclr(frame->image_data().begin(), frame->image_data().size());   \r
+                                       std::copy_n(bytes, count, frame->image_data().begin() + format_desc_.size - count);\r
+                                       count = 0;\r
+                               }\r
+                       \r
+                               frame->commit();\r
+                               frames_.push_back(frame);\r
+                       }\r
+               }\r
+               //else\r
+               //{\r
+               //      while(count > 0)\r
+               //      {\r
+               //              auto frame = frame_factory->create_frame(reinterpret_cast<void*>(rand()), format_desc_.width, height_);\r
+               //              if(count >= frame->image_data().size())\r
+               //              {       \r
+               //                      count -= frame->image_data().size();\r
+               //              }\r
+               //              else\r
+               //              {\r
+               //                      fast_memclr(frame->image_data().begin(), frame->image_data().size());   \r
+               //                      //std::copy_n(bytes, count, frame->image_data().begin() + format_desc_.size - count);\r
+               //                      count = 0;\r
+               //              }\r
+               //      \r
+               //              frame->commit();\r
+               //              frames_.push_back(frame);\r
+               //      }\r
+               //}\r
+       }\r
+       \r
+       // frame_producer\r
+\r
+       virtual safe_ptr<core::basic_frame> receive()\r
+       {\r
+               pixel_offset_ += speed_;\r
+\r
+               if(frames_.empty())\r
+                       return core::basic_frame::eof();\r
+\r
+               for(size_t n = 0; n < frames_.size(); ++n)\r
+                       frames_[n]->get_image_transform().set_fill_translation(0.0, -0.5*(n+1) + pixel_offset_ * 0.5/static_cast<double>(format_desc_.height));\r
+\r
+               return core::basic_frame(frames_);\r
+       }\r
+               \r
+       virtual std::wstring print() const\r
+       {\r
+               return L"image_scroll_producer[" + filename_ + L"]";\r
+       }\r
+};\r
+\r
+safe_ptr<core::frame_producer> create_image_scroll_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")(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
+               {                                       \r
+                       return boost::filesystem::is_regular_file(boost::filesystem::wpath(filename).replace_extension(ex));\r
+               });\r
+\r
+       if(ext == extensions.end())\r
+               return core::frame_producer::empty();\r
+       \r
+       size_t speed = 0;\r
+       auto speed_it = std::find(params.begin(), params.end(), L"SPEED");\r
+       if(speed_it != params.end())\r
+       {\r
+               if(++speed_it != params.end())\r
+                       speed = boost::lexical_cast<int>(*speed_it);\r
+       }\r
+\r
+       if(speed == 0)\r
+               return core::frame_producer::empty();\r
+\r
+       return make_safe<image_scroll_producer>(frame_factory, filename + L"." + *ext, speed);\r
+}\r
+\r
+\r
+}
\ No newline at end of file
diff --git a/modules/image/producer/image_scroll_producer.h b/modules/image/producer/image_scroll_producer.h
new file mode 100644 (file)
index 0000000..11c1014
--- /dev/null
@@ -0,0 +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
+#pragma once\r
+\r
+#include <core/producer/frame_producer.h>\r
+\r
+#include <string>\r
+#include <vector>\r
+\r
+namespace caspar { \r
+\r
+safe_ptr<core::frame_producer> create_image_scroll_producer(const safe_ptr<core::frame_factory>& frame_factory, const std::vector<std::wstring>& params);\r
+\r
+}
\ No newline at end of file