diff --git a/src/modules/image/producer/image_producer.cpp b/src/modules/image/producer/image_producer.cpp index 291e75e077..051eccb959 100644 --- a/src/modules/image/producer/image_producer.cpp +++ b/src/modules/image/producer/image_producer.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -63,35 +64,30 @@ struct image_producer : public core::frame_producer const uint32_t length_ = 0; core::draw_frame frame_; - image_producer(const spl::shared_ptr& frame_factory, std::wstring description, uint32_t length) - : description_(std::move(description)) - , frame_factory_(frame_factory) - , length_(length) + image_producer(const spl::shared_ptr& frame_factory, std::wstring description, uint32_t length, core::frame_geometry::scale_mode scale_mode) : + description_(std::move(description)), frame_factory_(frame_factory), length_(length) { - load(load_image(description_)); + load(load_image(description_), scale_mode); CASPAR_LOG(info) << print() << L" Initialized"; } - image_producer(const spl::shared_ptr& frame_factory, - const void* png_data, - size_t size, - uint32_t length) - : description_(L"png from memory") - , frame_factory_(frame_factory) - , length_(length) + image_producer(const spl::shared_ptr& frame_factory, const void* png_data, size_t size, uint32_t length, core::frame_geometry::scale_mode scale_mode) : + description_(L"png from memory"), frame_factory_(frame_factory), length_(length) { - load(load_png_from_memory(png_data, size)); + load(load_png_from_memory(png_data, size), scale_mode); CASPAR_LOG(info) << print() << L" Initialized"; } - void load(const std::shared_ptr& bitmap) + void load(const std::shared_ptr& bitmap, core::frame_geometry::scale_mode scale_mode) { FreeImage_FlipVertical(bitmap.get()); core::pixel_format_desc desc(core::pixel_format::bgra); desc.planes.emplace_back(FreeImage_GetWidth(bitmap.get()), FreeImage_GetHeight(bitmap.get()), 4); + auto frame = frame_factory_->create_frame(this, desc); + frame.geometry() = core::frame_geometry::get_default(scale_mode); std::copy_n(FreeImage_GetBits(bitmap.get()), frame.image_data(0).size(), frame.image_data(0).begin()); frame_ = core::draw_frame(std::move(frame)); @@ -120,19 +116,6 @@ struct image_producer : public core::frame_producer core::monitor::state state() const override { return state_; } }; -// class ieq -//{ -// std::wstring test_; -// -// public: -// explicit ieq(std::wstring test) -// : test_(std::move(test)) -// { -// } -// -// bool operator()(const std::wstring& elem) const { return boost::iequals(elem, test_); } -// }; - spl::shared_ptr create_producer(const core::frame_producer_dependencies& dependencies, const std::vector& params) { @@ -141,72 +124,14 @@ spl::shared_ptr create_producer(const core::frame_producer } auto length = get_param(L"LENGTH", params, std::numeric_limits::max()); + auto scale_mode = core::scale_mode_from_string(get_param(L"SCALE_MODE", params, L"STRETCH")); - // if (boost::iequals(params.at(0), L"[IMG_SEQUENCE]")) - //{ - // if (params.size() != 2) - // return core::frame_producer::empty(); - - // auto dir = boost::filesystem::path(env::media_folder() + params.at(1)).parent_path(); - // auto basename = boost::filesystem::basename(params.at(1)); - // std::set files; - // boost::filesystem::directory_iterator end; - - // for (boost::filesystem::directory_iterator it(dir); it != end; ++it) - // { - // auto name = it->path().filename().wstring(); - - // if (!boost::algorithm::istarts_with(name, basename)) - // continue; - - // auto extension = it->path().extension().wstring(); - - // if (std::find_if(supported_extensions().begin(), supported_extensions().end(), ieq(extension)) == - // supported_extensions().end()) continue; - - // files.insert(it->path().wstring()); - // } - - // if (files.empty()) - // return core::frame_producer::empty(); - - // int width = -1; - // int height = -1; - // std::vector frames; - // frames.reserve(files.size()); - - // for (auto& file : files) - // { - // auto frame = load_image(dependencies.frame_factory, file); - - // if (width == -1) - // { - // width = static_cast(frame.second.width.get()); - // height = static_cast(frame.second.height.get()); - // } - - // frames.push_back(std::move(frame.first)); - // } - - // return core::create_const_producer(std::move(frames), width, height); - //} - // else - // if (boost::iequals(params.at(0), L"[PNG_BASE64]")) { - // if (params.size() < 2) - // return core::frame_producer::empty(); - - // auto png_data = from_base64(std::string(params.at(1).begin(), params.at(1).end())); - - // return spl::make_shared(dependencies.frame_factory, png_data.data(), png_data.size(), length); - //} - - std::optional filename = - find_file_within_dir_or_absolute(env::media_folder(), params.at(0), is_valid_file); + auto filename = find_file_within_dir_or_absolute(env::media_folder(), params.at(0), is_valid_file); if (!filename) { return core::frame_producer::empty(); } - return spl::make_shared(dependencies.frame_factory, filename->wstring(), length); + return spl::make_shared(dependencies.frame_factory, filename->wstring(), length, scale_mode); } }} // namespace caspar::image