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
|
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>
|
|
|
|
#include <memory>
|
2019-01-14 10:23:21 +00:00
|
|
|
#include "gfx-source-texture.hpp"
|
|
|
|
#include "gs-effect.hpp"
|
|
|
|
#include "gs-helper.hpp"
|
|
|
|
#include "gs-rendertarget.hpp"
|
2019-01-25 16:54:18 +00:00
|
|
|
#include "gs-texture.hpp"
|
2019-01-14 10:23:21 +00:00
|
|
|
#include "plugin.hpp"
|
2017-07-06 04:02:41 +00:00
|
|
|
|
2019-01-14 10:23:21 +00:00
|
|
|
// OBS
|
|
|
|
#ifdef _MSC_VER
|
2018-09-30 22:54:36 +00:00
|
|
|
#pragma warning(push)
|
|
|
|
#pragma warning(disable : 4201)
|
2019-01-14 10:23:21 +00:00
|
|
|
#endif
|
2019-01-27 22:19:09 +00:00
|
|
|
#include <obs.h>
|
2019-01-14 10:23:21 +00:00
|
|
|
#ifdef _MSC_VER
|
2018-09-30 22:54:36 +00:00
|
|
|
#pragma warning(pop)
|
2019-01-14 10:23:21 +00:00
|
|
|
#endif
|
2018-09-30 22:54:36 +00:00
|
|
|
|
2018-09-30 16:49:52 +00:00
|
|
|
namespace filter {
|
2018-09-30 18:50:00 +00:00
|
|
|
namespace blur {
|
2019-01-25 16:54:18 +00:00
|
|
|
class instance;
|
|
|
|
|
2018-09-30 18:50:00 +00:00
|
|
|
enum type : int64_t {
|
2018-04-28 11:59:54 +00:00
|
|
|
Box,
|
|
|
|
Gaussian,
|
|
|
|
Bilateral,
|
2018-12-22 21:54:17 +00:00
|
|
|
BoxLinear,
|
|
|
|
GaussianLinear,
|
2018-04-28 11:59:54 +00:00
|
|
|
};
|
|
|
|
|
2018-09-30 20:48:47 +00:00
|
|
|
enum mask_type : int64_t {
|
|
|
|
Region,
|
|
|
|
Image,
|
|
|
|
Source,
|
|
|
|
};
|
|
|
|
|
2019-01-25 16:54:18 +00:00
|
|
|
class factory {
|
|
|
|
friend class std::_Ptr_base<filter::blur::factory>;
|
|
|
|
|
|
|
|
obs_source_info source_info;
|
|
|
|
std::list<instance*> sources;
|
|
|
|
std::shared_ptr<gs::effect> color_converter_effect;
|
|
|
|
std::shared_ptr<gs::effect> mask_effect;
|
|
|
|
|
|
|
|
std::shared_ptr<gs::effect> blur_effect;
|
|
|
|
std::map<filter::blur::type, std::shared_ptr<gs::texture>> kernels;
|
|
|
|
std::map<uint8_t, std::shared_ptr<std::vector<float_t>>> gaussian_kernels;
|
|
|
|
|
|
|
|
public: // Singleton
|
|
|
|
static void initialize();
|
|
|
|
static void finalize();
|
|
|
|
static std::shared_ptr<factory> get();
|
|
|
|
|
|
|
|
public:
|
|
|
|
factory();
|
|
|
|
~factory();
|
|
|
|
|
|
|
|
void on_list_fill();
|
|
|
|
void on_list_empty();
|
|
|
|
|
|
|
|
void generate_gaussian_kernels();
|
|
|
|
void generate_kernel_textures();
|
|
|
|
|
|
|
|
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_effect(filter::blur::type type);
|
|
|
|
|
|
|
|
std::string get_technique(filter::blur::type type);
|
|
|
|
|
|
|
|
std::shared_ptr<gs::effect> get_color_converter_effect();
|
|
|
|
|
|
|
|
std::shared_ptr<gs::effect> get_mask_effect();
|
|
|
|
|
|
|
|
std::shared_ptr<gs::texture> get_kernel(filter::blur::type type);
|
|
|
|
|
|
|
|
std::shared_ptr<std::vector<float_t>> get_gaussian_kernel(uint8_t size);
|
|
|
|
};
|
|
|
|
|
|
|
|
class instance {
|
|
|
|
obs_source_t* m_source;
|
|
|
|
std::shared_ptr<gs::rendertarget> rt_source;
|
2018-12-23 17:27:24 +00:00
|
|
|
std::shared_ptr<gs::rendertarget> rt_primary;
|
|
|
|
std::shared_ptr<gs::rendertarget> rt_secondary;
|
2018-09-30 18:50:00 +00:00
|
|
|
|
|
|
|
// blur
|
|
|
|
std::shared_ptr<gs::effect> blur_effect;
|
2018-12-22 21:07:33 +00:00
|
|
|
std::string blur_technique;
|
2018-09-30 18:50:00 +00:00
|
|
|
filter::blur::type type;
|
|
|
|
uint64_t size;
|
|
|
|
|
|
|
|
// bilateral
|
|
|
|
double_t bilateral_smoothing;
|
|
|
|
double_t bilateral_sharpness;
|
|
|
|
|
2018-12-23 17:27:24 +00:00
|
|
|
// Masking
|
2018-09-30 20:48:47 +00:00
|
|
|
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;
|
2018-09-30 22:54:36 +00:00
|
|
|
std::string path_old;
|
2018-09-30 20:48:47 +00:00
|
|
|
std::shared_ptr<gs::texture> texture;
|
|
|
|
} image;
|
|
|
|
struct {
|
2018-09-30 22:54:36 +00:00
|
|
|
std::string name_old;
|
2018-09-30 20:48:47 +00:00
|
|
|
std::string name;
|
2018-09-30 22:54:36 +00:00
|
|
|
bool is_scene;
|
2018-09-30 20:48:47 +00:00
|
|
|
std::shared_ptr<gfx::source_texture> source_texture;
|
|
|
|
std::shared_ptr<gs::texture> texture;
|
|
|
|
} source;
|
2018-09-30 22:54:36 +00:00
|
|
|
struct {
|
|
|
|
float_t r;
|
|
|
|
float_t g;
|
|
|
|
float_t b;
|
|
|
|
float_t a;
|
|
|
|
} color;
|
|
|
|
float_t multiplier;
|
2018-09-30 20:48:47 +00:00
|
|
|
} mask;
|
2018-09-30 18:50:00 +00:00
|
|
|
|
2018-12-23 18:54:57 +00:00
|
|
|
// Directional
|
2019-01-25 16:54:18 +00:00
|
|
|
bool directional;
|
2018-12-23 18:54:57 +00:00
|
|
|
double_t angle;
|
|
|
|
|
|
|
|
// Scale
|
2019-01-25 16:54:18 +00:00
|
|
|
bool scaling;
|
2018-12-23 18:54:57 +00:00
|
|
|
std::pair<double_t, double_t> scale;
|
|
|
|
|
2018-09-30 18:50:00 +00:00
|
|
|
// advanced
|
|
|
|
uint64_t color_format;
|
|
|
|
|
|
|
|
bool apply_shared_param(gs_texture_t* input, float texelX, float texelY);
|
|
|
|
bool apply_bilateral_param();
|
2018-12-23 01:00:30 +00:00
|
|
|
bool apply_gaussian_param(uint8_t width);
|
2018-09-30 22:54:36 +00:00
|
|
|
bool apply_mask_parameters(std::shared_ptr<gs::effect> effect, gs_texture_t* original_texture,
|
|
|
|
gs_texture_t* blurred_texture);
|
2018-09-30 18:50:00 +00:00
|
|
|
|
|
|
|
static bool modified_properties(void* ptr, obs_properties_t* props, obs_property* prop,
|
|
|
|
obs_data_t* settings);
|
|
|
|
|
2018-12-23 17:27:24 +00:00
|
|
|
// Logging
|
|
|
|
std::chrono::high_resolution_clock::time_point last_log;
|
2019-01-25 16:54:18 +00:00
|
|
|
bool can_log();
|
2018-12-23 17:27:24 +00:00
|
|
|
|
2017-07-03 00:46:33 +00:00
|
|
|
public:
|
2019-01-25 16:54:18 +00:00
|
|
|
instance(obs_data_t* settings, obs_source_t* self);
|
|
|
|
~instance();
|
2018-09-30 18:50:00 +00:00
|
|
|
|
|
|
|
obs_properties_t* get_properties();
|
|
|
|
void update(obs_data_t*);
|
2019-01-27 22:29:47 +00:00
|
|
|
void load(obs_data_t*);
|
2017-07-03 00:46:33 +00:00
|
|
|
|
|
|
|
uint32_t get_width();
|
|
|
|
uint32_t get_height();
|
2018-09-30 18:50:00 +00:00
|
|
|
|
2017-07-03 00:46:33 +00:00
|
|
|
void activate();
|
|
|
|
void deactivate();
|
2018-09-30 18:50:00 +00:00
|
|
|
|
2017-07-03 00:46:33 +00:00
|
|
|
void video_tick(float);
|
|
|
|
void video_render(gs_effect_t*);
|
2018-09-30 18:50:00 +00:00
|
|
|
};
|
|
|
|
} // namespace blur
|
|
|
|
} // namespace filter
|