2017-07-03 00:46:33 +00:00
|
|
|
/*
|
|
|
|
* Modern effects for a modern Streamer
|
2018-04-28 11:59:54 +00:00
|
|
|
* Copyright (C) 2017-2018 Michael Fabian Dirks
|
2017-07-03 00:46:33 +00:00
|
|
|
*
|
|
|
|
* 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
|
2020-04-02 15:02:01 +00:00
|
|
|
#include "common.hpp"
|
2018-12-23 17:27:24 +00:00
|
|
|
#include <chrono>
|
2018-09-30 22:54:36 +00:00
|
|
|
#include <functional>
|
2018-09-30 18:50:00 +00:00
|
|
|
#include <list>
|
|
|
|
#include <map>
|
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"
|
|
|
|
#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
|
|
|
|
2020-01-13 21:40:15 +00:00
|
|
|
namespace filter::blur {
|
|
|
|
enum class mask_type : int64_t {
|
|
|
|
Region,
|
|
|
|
Image,
|
|
|
|
Source,
|
|
|
|
};
|
|
|
|
|
|
|
|
class blur_instance : public obs::source_instance {
|
|
|
|
// Effects
|
|
|
|
gs::effect _effect_mask;
|
|
|
|
|
|
|
|
// Input
|
|
|
|
std::shared_ptr<gs::rendertarget> _source_rt;
|
|
|
|
std::shared_ptr<gs::texture> _source_texture;
|
|
|
|
bool _source_rendered;
|
|
|
|
|
|
|
|
// Rendering
|
|
|
|
std::shared_ptr<gs::texture> _output_texture;
|
|
|
|
std::shared_ptr<gs::rendertarget> _output_rt;
|
|
|
|
bool _output_rendered;
|
|
|
|
|
|
|
|
// Blur
|
|
|
|
std::shared_ptr<::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;
|
|
|
|
|
|
|
|
// 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 {
|
|
|
|
std::string path;
|
|
|
|
std::string path_old;
|
|
|
|
std::shared_ptr<gs::texture> texture;
|
|
|
|
} image;
|
|
|
|
struct {
|
|
|
|
std::string name_old;
|
|
|
|
std::string name;
|
|
|
|
bool is_scene;
|
|
|
|
std::shared_ptr<gfx::source_texture> source_texture;
|
|
|
|
std::shared_ptr<gs::texture> texture;
|
|
|
|
} 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-04-05 04:02:03 +00:00
|
|
|
virtual void migrate(obs_data_t* settings, std::uint64_t version) override;
|
|
|
|
virtual void update(obs_data_t* settings) override;
|
2020-01-13 21:40:15 +00:00
|
|
|
|
|
|
|
virtual void video_tick(float time) override;
|
|
|
|
virtual void video_render(gs_effect_t* effect) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool apply_mask_parameters(gs::effect effect, gs_texture_t* original_texture, gs_texture_t* blurred_texture);
|
|
|
|
};
|
|
|
|
|
|
|
|
class blur_factory : public obs::source_factory<filter::blur::blur_factory, filter::blur::blur_instance> {
|
|
|
|
static std::shared_ptr<filter::blur::blur_factory> factory_instance;
|
|
|
|
|
|
|
|
public: // Singleton
|
|
|
|
static void initialize()
|
|
|
|
{
|
|
|
|
factory_instance = std::make_shared<filter::blur::blur_factory>();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void finalize()
|
|
|
|
{
|
|
|
|
factory_instance.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::shared_ptr<blur_factory> get()
|
|
|
|
{
|
|
|
|
return factory_instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
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, ...);
|
|
|
|
};
|
|
|
|
} // namespace filter::blur
|