From 395e284a37ddbf29e840da16a5e1cb1f12ab3b74 Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Tue, 2 Apr 2019 02:45:01 +0200 Subject: [PATCH] gfx/blur/base: Newly refactored blur code base This is the new code base for blur effects, which is much more effective at being re-usable than the old code base. It allows for much better extendable behavior and uses an interface and factory pattern, instead of hardcoding supported features. --- source/gfx/blur/gfx-blur-base.cpp | 65 +++++++++++++++++ source/gfx/blur/gfx-blur-base.hpp | 115 ++++++++++++++++++++++++++++++ 2 files changed, 180 insertions(+) create mode 100644 source/gfx/blur/gfx-blur-base.cpp create mode 100644 source/gfx/blur/gfx-blur-base.hpp diff --git a/source/gfx/blur/gfx-blur-base.cpp b/source/gfx/blur/gfx-blur-base.cpp new file mode 100644 index 0000000..be0e3f7 --- /dev/null +++ b/source/gfx/blur/gfx-blur-base.cpp @@ -0,0 +1,65 @@ +// Modern effects for a modern Streamer +// Copyright (C) 2019 Michael Fabian Dirks +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + +#include "gfx-blur-base.hpp" + +void gfx::blur::ibase::set_step_scale_x(double_t v) +{ + this->set_step_scale(v, this->get_step_scale_y()); +} + +void gfx::blur::ibase::set_step_scale_y(double_t v) { + this->set_step_scale(this->get_step_scale_x(), v); +} + +double_t gfx::blur::ibase::get_step_scale_x() +{ + double_t x, y; + this->get_step_scale(x, y); + return x; +} + +double_t gfx::blur::ibase::get_step_scale_y() +{ + double_t x, y; + this->get_step_scale(x, y); + return y; +} + +void gfx::blur::ibase_center::set_center_x(double_t v) +{ + this->set_center(v, this->get_center_y()); +} + +void gfx::blur::ibase_center::set_center_y(double_t v) +{ + this->set_center(this->get_center_x(), v); +} + +double_t gfx::blur::ibase_center::get_center_x() +{ + double_t x, y; + this->get_center(x, y); + return x; +} + +double_t gfx::blur::ibase_center::get_center_y() +{ + double_t x, y; + this->get_center(x, y); + return y; +} diff --git a/source/gfx/blur/gfx-blur-base.hpp b/source/gfx/blur/gfx-blur-base.hpp new file mode 100644 index 0000000..7262481 --- /dev/null +++ b/source/gfx/blur/gfx-blur-base.hpp @@ -0,0 +1,115 @@ +// Modern effects for a modern Streamer +// Copyright (C) 2019 Michael Fabian Dirks +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + +#pragma once +#include +#include +#include "obs/gs/gs-texture.hpp" + +namespace gfx { + namespace blur { + enum class type : int64_t { + Invalid = -1, + Area, + Directional, + Rotational, + Zoom, + }; + + class ibase { + public: + virtual void set_input(std::shared_ptr<::gs::texture> texture) = 0; + + virtual ::gfx::blur::type get_type() = 0; + + virtual double_t get_size() = 0; + + virtual void set_size(double_t width) = 0; + + virtual void set_step_scale(double_t x, double_t y) = 0; + + virtual void set_step_scale_x(double_t v); + + virtual void set_step_scale_y(double_t v); + + virtual void get_step_scale(double_t& x, double_t& y) = 0; + + virtual double_t get_step_scale_x(); + + virtual double_t get_step_scale_y(); + + virtual std::shared_ptr<::gs::texture> render() = 0; + + virtual std::shared_ptr<::gs::texture> get() = 0; + }; + + class ibase_angle { + public: + virtual double_t get_angle() = 0; + + virtual void set_angle(double_t angle) = 0; + }; + + class ibase_center { + public: + virtual void set_center(double_t x, double_t y) = 0; + + virtual void set_center_x(double_t v); + + virtual void set_center_y(double_t v); + + virtual void get_center(double_t& x, double_t& y) = 0; + + virtual double_t get_center_x(); + + virtual double_t get_center_y(); + }; + + class ifactory { + public: + virtual bool is_type_supported(::gfx::blur::type type) = 0; + + virtual std::shared_ptr<::gfx::blur::ibase> create(::gfx::blur::type type) = 0; + + virtual double_t get_min_size(::gfx::blur::type type) = 0; + + virtual double_t get_step_size(::gfx::blur::type type) = 0; + + virtual double_t get_max_size(::gfx::blur::type type) = 0; + + virtual double_t get_min_angle(::gfx::blur::type type) = 0; + + virtual double_t get_step_angle(::gfx::blur::type type) = 0; + + virtual double_t get_max_angle(::gfx::blur::type type) = 0; + + virtual bool is_step_scale_supported(::gfx::blur::type type) = 0; + + virtual double_t get_min_step_scale_x(::gfx::blur::type type) = 0; + + virtual double_t get_step_step_scale_x(::gfx::blur::type type) = 0; + + virtual double_t get_max_step_scale_x(::gfx::blur::type type) = 0; + + virtual double_t get_min_step_scale_y(::gfx::blur::type type) = 0; + + virtual double_t get_step_step_scale_y(::gfx::blur::type type) = 0; + + virtual double_t get_max_step_scale_y(::gfx::blur::type type) = 0; + }; + } // namespace blur +} // namespace gfx