obs-StreamFX/source/filters/filter-blur.hpp

186 lines
5.1 KiB
C++
Raw Normal View History

/*
* Modern effects for a modern Streamer
* Copyright (C) 2017-2018 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 <chrono>
#include <functional>
#include <list>
#include <map>
#include <memory>
#include "gfx/blur/gfx-blur-base.hpp"
#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"
#include "plugin.hpp"
// OBS
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4201)
#endif
#include <obs.h>
#ifdef _MSC_VER
#pragma warning(pop)
#endif
2018-09-30 16:49:52 +00:00
namespace filter {
namespace blur {
2019-01-27 22:33:12 +00:00
class blur_instance;
2019-01-25 16:54:18 +00:00
enum mask_type : int64_t {
Region,
Image,
Source,
};
2019-01-27 22:33:12 +00:00
class blur_factory {
friend class std::_Ptr_base<filter::blur::blur_factory>;
2019-01-25 16:54:18 +00:00
obs_source_info source_info;
std::list<blur_instance*> sources;
2019-01-25 16:54:18 +00:00
std::shared_ptr<gs::effect> color_converter_effect;
std::shared_ptr<gs::effect> mask_effect;
std::map<std::string, std::string> translation_map;
2019-01-25 16:54:18 +00:00
public: // Singleton
static void initialize();
static void finalize();
2019-01-27 22:33:12 +00:00
static std::shared_ptr<blur_factory> get();
2019-01-25 16:54:18 +00:00
public:
2019-01-27 22:33:12 +00:00
blur_factory();
~blur_factory();
2019-01-25 16:54:18 +00:00
void on_list_fill();
void on_list_empty();
2019-03-01 10:33:19 +00:00
std::string const& get_translation(std::string const key);
2019-01-25 16:54:18 +00:00
static void* create(obs_data_t* settings, obs_source_t* self);
static void destroy(void* source);
static void get_defaults(obs_data_t* settings);
static obs_properties_t* get_properties(void* source);
static void update(void* source, obs_data_t* settings);
2019-01-27 22:29:47 +00:00
static void load(void* source, obs_data_t* settings);
2019-01-25 16:54:18 +00:00
static const char* get_name(void* source);
static uint32_t get_width(void* source);
static uint32_t get_height(void* source);
static void activate(void* source);
static void deactivate(void* source);
static void video_tick(void* source, float delta);
static void video_render(void* source, gs_effect_t* effect);
public:
std::shared_ptr<gs::effect> get_color_converter_effect();
std::shared_ptr<gs::effect> get_mask_effect();
};
2019-01-27 22:33:12 +00:00
class blur_instance {
obs_source_t* m_self;
2019-01-28 00:08:13 +00:00
// Input
std::shared_ptr<gs::rendertarget> m_source_rt;
std::shared_ptr<gs::texture> m_source_texture;
bool m_source_rendered;
2019-01-28 00:08:13 +00:00
// Rendering
std::shared_ptr<gs::texture> m_output_texture;
std::shared_ptr<gs::rendertarget> m_output_rt;
2019-01-28 00:08:13 +00:00
bool m_output_rendered;
// Blur
std::shared_ptr<::gfx::blur::ibase> m_blur;
double_t m_blur_size;
double_t m_blur_angle;
std::pair<double_t, double_t> m_blur_center;
bool m_blur_step_scaling;
std::pair<double_t, double_t> m_blur_step_scale;
// Masking
struct {
bool enabled;
mask_type type;
struct {
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;
2019-01-28 00:08:13 +00:00
} m_mask;
2019-01-28 00:08:13 +00:00
public:
blur_instance(obs_data_t* settings, obs_source_t* self);
~blur_instance();
private:
bool apply_mask_parameters(std::shared_ptr<gs::effect> effect, gs_texture_t* original_texture,
gs_texture_t* blurred_texture);
static bool modified_properties(void* ptr, obs_properties_t* props, obs_property* prop,
obs_data_t* settings);
void translate_old_settings(obs_data_t*);
public:
obs_properties_t* get_properties();
void update(obs_data_t*);
2019-01-27 22:29:47 +00:00
void load(obs_data_t*);
uint32_t get_width();
uint32_t get_height();
void activate();
void deactivate();
void video_tick(float);
void video_render(gs_effect_t*);
};
} // namespace blur
} // namespace filter