obs-StreamFX/source/gfx/blur/gfx-blur-gaussian-linear.hpp

144 lines
4.8 KiB
C++
Raw Normal View History

// 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 "common.hpp"
#include "gfx-blur-base.hpp"
#include "obs/gs/gs-effect.hpp"
#include "obs/gs/gs-rendertarget.hpp"
#include "obs/gs/gs-texture.hpp"
#include "warning-disable.hpp"
#include <mutex>
#include <vector>
#include "warning-enable.hpp"
2021-06-08 02:47:04 +00:00
namespace streamfx::gfx {
namespace blur {
class gaussian_linear_data {
2021-06-08 02:38:24 +00:00
streamfx::obs::gs::effect _effect;
2019-08-04 14:20:26 +00:00
std::vector<std::vector<float_t>> _kernels;
public:
gaussian_linear_data();
virtual ~gaussian_linear_data();
2021-06-08 02:38:24 +00:00
streamfx::obs::gs::effect get_effect();
2020-04-08 21:38:42 +00:00
std::vector<float_t> const& get_kernel(std::size_t width);
};
2021-06-08 02:47:04 +00:00
class gaussian_linear_factory : public ::streamfx::gfx::blur::ifactory {
std::mutex _data_lock;
std::weak_ptr<::streamfx::gfx::blur::gaussian_linear_data> _data;
public:
gaussian_linear_factory();
virtual ~gaussian_linear_factory() override;
2021-06-08 02:47:04 +00:00
virtual bool is_type_supported(::streamfx::gfx::blur::type type) override;
2021-06-08 02:47:04 +00:00
virtual std::shared_ptr<::streamfx::gfx::blur::base> create(::streamfx::gfx::blur::type type) override;
2021-06-08 02:47:04 +00:00
virtual double_t get_min_size(::streamfx::gfx::blur::type type) override;
2021-06-08 02:47:04 +00:00
virtual double_t get_step_size(::streamfx::gfx::blur::type type) override;
2021-06-08 02:47:04 +00:00
virtual double_t get_max_size(::streamfx::gfx::blur::type type) override;
2021-06-08 02:47:04 +00:00
virtual double_t get_min_angle(::streamfx::gfx::blur::type type) override;
2021-06-08 02:47:04 +00:00
virtual double_t get_step_angle(::streamfx::gfx::blur::type type) override;
2021-06-08 02:47:04 +00:00
virtual double_t get_max_angle(::streamfx::gfx::blur::type type) override;
2021-06-08 02:47:04 +00:00
virtual bool is_step_scale_supported(::streamfx::gfx::blur::type type) override;
2021-06-08 02:47:04 +00:00
virtual double_t get_min_step_scale_x(::streamfx::gfx::blur::type type) override;
2021-06-08 02:47:04 +00:00
virtual double_t get_step_step_scale_x(::streamfx::gfx::blur::type type) override;
2021-06-08 02:47:04 +00:00
virtual double_t get_max_step_scale_x(::streamfx::gfx::blur::type type) override;
2021-06-08 02:47:04 +00:00
virtual double_t get_min_step_scale_y(::streamfx::gfx::blur::type type) override;
2021-06-08 02:47:04 +00:00
virtual double_t get_step_step_scale_y(::streamfx::gfx::blur::type type) override;
2021-06-08 02:47:04 +00:00
virtual double_t get_max_step_scale_y(::streamfx::gfx::blur::type type) override;
2021-06-08 02:47:04 +00:00
std::shared_ptr<::streamfx::gfx::blur::gaussian_linear_data> data();
public: // Singleton
2021-06-08 02:47:04 +00:00
static ::streamfx::gfx::blur::gaussian_linear_factory& get();
};
2021-06-08 02:47:04 +00:00
class gaussian_linear : public ::streamfx::gfx::blur::base {
protected:
2021-06-08 02:47:04 +00:00
std::shared_ptr<::streamfx::gfx::blur::gaussian_linear_data> _data;
2021-06-08 02:38:24 +00:00
double_t _size;
std::pair<double_t, double_t> _step_scale;
std::shared_ptr<::streamfx::obs::gs::texture> _input_texture;
std::shared_ptr<::streamfx::obs::gs::rendertarget> _rendertarget;
private:
2021-06-08 02:38:24 +00:00
std::shared_ptr<::streamfx::obs::gs::rendertarget> _rendertarget2;
public:
gaussian_linear();
virtual ~gaussian_linear() override;
2021-06-08 02:38:24 +00:00
virtual void set_input(std::shared_ptr<::streamfx::obs::gs::texture> texture) override;
2021-06-08 02:47:04 +00:00
virtual ::streamfx::gfx::blur::type get_type() override;
virtual double_t get_size() override;
virtual void set_size(double_t width) override;
virtual void set_step_scale(double_t x, double_t y) override;
virtual void get_step_scale(double_t& x, double_t& y) override;
virtual double_t get_step_scale_x() override;
virtual double_t get_step_scale_y() override;
2021-06-08 02:38:24 +00:00
virtual std::shared_ptr<::streamfx::obs::gs::texture> render() override;
2021-06-08 02:38:24 +00:00
virtual std::shared_ptr<::streamfx::obs::gs::texture> get() override;
};
2021-06-08 02:47:04 +00:00
class gaussian_linear_directional : public ::streamfx::gfx::blur::gaussian_linear,
public ::streamfx::gfx::blur::base_angle {
2019-08-04 14:20:26 +00:00
double_t _angle;
public:
gaussian_linear_directional();
virtual ~gaussian_linear_directional() override;
2021-06-08 02:47:04 +00:00
virtual ::streamfx::gfx::blur::type get_type() override;
virtual double_t get_angle() override;
2019-04-02 22:19:01 +00:00
virtual void set_angle(double_t angle) override;
2021-06-08 02:38:24 +00:00
virtual std::shared_ptr<::streamfx::obs::gs::texture> render() override;
};
} // namespace blur
2021-06-08 02:47:04 +00:00
} // namespace streamfx::gfx