From: Helge Norberg Date: Mon, 23 May 2016 19:14:53 +0000 (+0200) Subject: [image_producer] refuse too large images nicely instead of letting OpenGL tell us... X-Git-Tag: 2.1.0_Beta1~79 X-Git-Url: https://git.sesse.net/?p=casparcg;a=commitdiff_plain;h=c30ace6f19e057aff4d84a54f37596857df93750 [image_producer] refuse too large images nicely instead of letting OpenGL tell us later. --- diff --git a/accelerator/cpu/image/image_mixer.cpp b/accelerator/cpu/image/image_mixer.cpp index 07d669deb..bf69a0558 100644 --- a/accelerator/cpu/image/image_mixer.cpp +++ b/accelerator/cpu/image/image_mixer.cpp @@ -371,6 +371,7 @@ image_mixer::~image_mixer(){} void image_mixer::push(const core::frame_transform& transform){impl_->push(transform);} void image_mixer::visit(const core::const_frame& frame){impl_->visit(frame);} void image_mixer::pop(){impl_->pop();} +int image_mixer::get_max_frame_size() { return std::numeric_limits::max(); } std::future> image_mixer::operator()(const core::video_format_desc& format_desc, bool /* straighten_alpha */){return impl_->render(format_desc);} core::mutable_frame image_mixer::create_frame(const void* tag, const core::pixel_format_desc& desc, const core::audio_channel_layout& channel_layout) {return impl_->create_frame(tag, desc, channel_layout);} diff --git a/accelerator/cpu/image/image_mixer.h b/accelerator/cpu/image/image_mixer.h index 55f2b416b..ba4d0a391 100644 --- a/accelerator/cpu/image/image_mixer.h +++ b/accelerator/cpu/image/image_mixer.h @@ -37,7 +37,7 @@ public: core::mutable_frame create_frame(const void* tag, const core::pixel_format_desc& desc, const core::audio_channel_layout& channel_layout) override; // Properties - + int get_max_frame_size() override; private: struct impl; spl::unique_ptr impl_; diff --git a/accelerator/ogl/image/image_mixer.cpp b/accelerator/ogl/image/image_mixer.cpp index 1c983cee2..19d0191e5 100644 --- a/accelerator/ogl/image/image_mixer.cpp +++ b/accelerator/ogl/image/image_mixer.cpp @@ -369,6 +369,16 @@ public: return core::mutable_frame(std::move(buffers), core::mutable_audio_buffer(), tag, desc, channel_layout); } + + int get_max_frame_size() override + { + return ogl_->invoke([] + { + GLint64 params[1]; + glGetInteger64v(GL_MAX_TEXTURE_SIZE, params); + return static_cast(params[0]); + }); + } }; image_mixer::image_mixer(const spl::shared_ptr& ogl, bool blend_modes_wanted, bool straight_alpha_wanted, int channel_id) : impl_(new impl(ogl, blend_modes_wanted, straight_alpha_wanted, channel_id)){} @@ -376,6 +386,7 @@ image_mixer::~image_mixer(){} void image_mixer::push(const core::frame_transform& transform){impl_->push(transform);} void image_mixer::visit(const core::const_frame& frame){impl_->visit(frame);} void image_mixer::pop(){impl_->pop();} +int image_mixer::get_max_frame_size() { return impl_->get_max_frame_size(); } std::future> image_mixer::operator()(const core::video_format_desc& format_desc, bool straighten_alpha){return impl_->render(format_desc, straighten_alpha);} core::mutable_frame image_mixer::create_frame(const void* tag, const core::pixel_format_desc& desc, const core::audio_channel_layout& channel_layout) {return impl_->create_frame(tag, desc, channel_layout);} diff --git a/accelerator/ogl/image/image_mixer.h b/accelerator/ogl/image/image_mixer.h index 3b203b511..2ce6e4d69 100644 --- a/accelerator/ogl/image/image_mixer.h +++ b/accelerator/ogl/image/image_mixer.h @@ -60,6 +60,8 @@ public: // Properties + int get_max_frame_size() override; + private: struct impl; spl::unique_ptr impl_; diff --git a/core/frame/frame_factory.h b/core/frame/frame_factory.h index ac2cda113..4f9d1c8d8 100644 --- a/core/frame/frame_factory.h +++ b/core/frame/frame_factory.h @@ -48,6 +48,8 @@ public: const core::audio_channel_layout& channel_layout) = 0; // Properties + + virtual int get_max_frame_size() = 0; }; }} \ No newline at end of file diff --git a/modules/image/producer/image_producer.cpp b/modules/image/producer/image_producer.cpp index 0da1a981c..112922ac5 100644 --- a/modules/image/producer/image_producer.cpp +++ b/modules/image/producer/image_producer.cpp @@ -106,6 +106,11 @@ struct image_producer : public core::frame_producer_base void load(const std::shared_ptr& bitmap) { FreeImage_FlipVertical(bitmap.get()); + auto longest_side = static_cast(std::max(FreeImage_GetWidth(bitmap.get()), FreeImage_GetHeight(bitmap.get()))); + + if (longest_side > frame_factory_->get_max_frame_size()) + CASPAR_THROW_EXCEPTION(user_error() << msg_info("Image too large for texture")); + core::pixel_format_desc desc; desc.format = core::pixel_format::bgra; desc.planes.push_back(core::pixel_format_desc::plane(FreeImage_GetWidth(bitmap.get()), FreeImage_GetHeight(bitmap.get()), 4));