2023-02-28 01:15:26 +00:00
|
|
|
// AUTOGENERATED COPYRIGHT HEADER START
|
|
|
|
// Copyright (C) 2019-2023 Michael Fabian 'Xaymar' Dirks <info@xaymar.com>
|
|
|
|
// AUTOGENERATED COPYRIGHT HEADER END
|
2017-07-03 00:46:33 +00:00
|
|
|
|
|
|
|
#pragma once
|
2020-04-02 15:02:01 +00:00
|
|
|
#include "common.hpp"
|
2019-04-02 01:05:05 +00:00
|
|
|
#include "gfx/blur/gfx-blur-base.hpp"
|
2019-02-11 02:54:16 +00:00
|
|
|
#include "gfx/gfx-source-texture.hpp"
|
2022-11-28 08:11:55 +00:00
|
|
|
#include "gfx/gfx-util.hpp"
|
2019-02-11 02:54:16 +00:00
|
|
|
#include "obs/gs/gs-effect.hpp"
|
|
|
|
#include "obs/gs/gs-helper.hpp"
|
|
|
|
#include "obs/gs/gs-rendertarget.hpp"
|
|
|
|
#include "obs/gs/gs-texture.hpp"
|
2019-12-03 19:37:57 +00:00
|
|
|
#include "obs/obs-source-factory.hpp"
|
2018-09-30 22:54:36 +00:00
|
|
|
|
2022-08-29 10:29:44 +00:00
|
|
|
#include "warning-disable.hpp"
|
|
|
|
#include <chrono>
|
|
|
|
#include <functional>
|
|
|
|
#include <list>
|
|
|
|
#include <map>
|
|
|
|
#include "warning-enable.hpp"
|
|
|
|
|
2020-04-05 16:52:06 +00:00
|
|
|
namespace streamfx::filter::blur {
|
2020-01-13 21:40:15 +00:00
|
|
|
enum class mask_type : int64_t {
|
|
|
|
Region,
|
|
|
|
Image,
|
|
|
|
Source,
|
|
|
|
};
|
|
|
|
|
|
|
|
class blur_instance : public obs::source_instance {
|
|
|
|
// Effects
|
2022-11-28 08:11:55 +00:00
|
|
|
streamfx::obs::gs::effect _effect_mask;
|
|
|
|
std::shared_ptr<streamfx::gfx::util> _gfx_util;
|
2020-01-13 21:40:15 +00:00
|
|
|
|
|
|
|
// Input
|
2021-06-08 02:38:24 +00:00
|
|
|
std::shared_ptr<streamfx::obs::gs::rendertarget> _source_rt;
|
|
|
|
std::shared_ptr<streamfx::obs::gs::texture> _source_texture;
|
|
|
|
bool _source_rendered;
|
2020-01-13 21:40:15 +00:00
|
|
|
|
|
|
|
// Rendering
|
2021-06-08 02:38:24 +00:00
|
|
|
std::shared_ptr<streamfx::obs::gs::texture> _output_texture;
|
|
|
|
std::shared_ptr<streamfx::obs::gs::rendertarget> _output_rt;
|
|
|
|
bool _output_rendered;
|
2020-01-13 21:40:15 +00:00
|
|
|
|
|
|
|
// Blur
|
2021-06-08 02:47:04 +00:00
|
|
|
std::shared_ptr<::streamfx::gfx::blur::base> _blur;
|
|
|
|
double_t _blur_size;
|
|
|
|
double_t _blur_angle;
|
|
|
|
std::pair<double_t, double_t> _blur_center;
|
|
|
|
bool _blur_step_scaling;
|
|
|
|
std::pair<double_t, double_t> _blur_step_scale;
|
2020-01-13 21:40:15 +00:00
|
|
|
|
|
|
|
// Masking
|
|
|
|
struct {
|
|
|
|
bool enabled;
|
|
|
|
mask_type type;
|
2018-09-30 20:48:47 +00:00
|
|
|
struct {
|
2020-01-13 21:40:15 +00:00
|
|
|
float_t left;
|
|
|
|
float_t top;
|
|
|
|
float_t right;
|
|
|
|
float_t bottom;
|
|
|
|
float_t feather;
|
|
|
|
float_t feather_shift;
|
|
|
|
bool invert;
|
|
|
|
} region;
|
|
|
|
struct {
|
2021-06-08 02:38:24 +00:00
|
|
|
std::string path;
|
|
|
|
std::string path_old;
|
|
|
|
std::shared_ptr<streamfx::obs::gs::texture> texture;
|
2020-01-13 21:40:15 +00:00
|
|
|
} image;
|
|
|
|
struct {
|
2021-06-08 02:47:04 +00:00
|
|
|
std::string name_old;
|
|
|
|
std::string name;
|
|
|
|
bool is_scene;
|
|
|
|
std::shared_ptr<streamfx::gfx::source_texture> source_texture;
|
|
|
|
std::shared_ptr<streamfx::obs::gs::texture> texture;
|
2020-01-13 21:40:15 +00:00
|
|
|
} source;
|
|
|
|
struct {
|
|
|
|
float_t r;
|
|
|
|
float_t g;
|
|
|
|
float_t b;
|
|
|
|
float_t a;
|
|
|
|
} color;
|
|
|
|
float_t multiplier;
|
|
|
|
} _mask;
|
|
|
|
|
|
|
|
public:
|
|
|
|
blur_instance(obs_data_t* settings, obs_source_t* self);
|
|
|
|
~blur_instance();
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual void load(obs_data_t* settings) override;
|
2020-08-10 01:29:05 +00:00
|
|
|
virtual void migrate(obs_data_t* settings, uint64_t version) override;
|
2020-04-05 04:02:03 +00:00
|
|
|
virtual void update(obs_data_t* settings) override;
|
2020-01-13 21:40:15 +00:00
|
|
|
|
2020-04-08 21:38:42 +00:00
|
|
|
virtual void video_tick(float_t time) override;
|
2020-01-13 21:40:15 +00:00
|
|
|
virtual void video_render(gs_effect_t* effect) override;
|
|
|
|
|
|
|
|
private:
|
2023-05-13 12:35:46 +00:00
|
|
|
bool apply_mask_parameters(streamfx::obs::gs::effect effect, gs_texture_t* original_texture, gs_texture_t* blurred_texture);
|
2020-01-13 21:40:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class blur_factory : public obs::source_factory<filter::blur::blur_factory, filter::blur::blur_instance> {
|
|
|
|
std::vector<std::string> _translation_cache;
|
|
|
|
|
|
|
|
public:
|
|
|
|
blur_factory();
|
|
|
|
virtual ~blur_factory();
|
|
|
|
|
|
|
|
virtual const char* get_name() override;
|
|
|
|
|
|
|
|
virtual void get_defaults2(obs_data_t* settings) override;
|
|
|
|
|
|
|
|
virtual obs_properties_t* get_properties2(filter::blur::blur_instance* data) override;
|
|
|
|
|
|
|
|
std::string translate_string(const char* format, ...);
|
2020-04-05 16:52:06 +00:00
|
|
|
|
2021-04-16 23:43:30 +00:00
|
|
|
#ifdef ENABLE_FRONTEND
|
|
|
|
static bool on_manual_open(obs_properties_t* props, obs_property_t* property, void* data);
|
|
|
|
#endif
|
|
|
|
|
2020-04-05 16:52:06 +00:00
|
|
|
public: // Singleton
|
|
|
|
static void initialize();
|
|
|
|
|
|
|
|
static void finalize();
|
|
|
|
|
|
|
|
static std::shared_ptr<blur_factory> get();
|
2020-01-13 21:40:15 +00:00
|
|
|
};
|
2020-04-05 16:52:06 +00:00
|
|
|
} // namespace streamfx::filter::blur
|