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
|
|
|
|
*/
|
|
|
|
|
2018-11-08 10:16:55 +00:00
|
|
|
#ifndef OBS_STREAM_EFFECTS_FILTER_BLUR_HPP
|
|
|
|
#define OBS_STREAM_EFFECTS_FILTER_BLUR_HPP
|
2017-07-03 00:46:33 +00:00
|
|
|
#pragma once
|
2018-11-08 10:16:55 +00:00
|
|
|
|
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-texture.hpp"
|
|
|
|
#include "gs-rendertarget.hpp"
|
|
|
|
#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
|
|
|
|
#include <callback/signal.h>
|
|
|
|
#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 {
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2018-11-08 10:16:55 +00:00
|
|
|
class blur_instance {
|
2018-09-30 18:50:00 +00:00
|
|
|
obs_source_t* m_source;
|
2018-12-23 17:27:24 +00:00
|
|
|
std::shared_ptr<gs::rendertarget> rt_source;
|
|
|
|
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
|
|
|
|
bool directional;
|
|
|
|
double_t angle;
|
|
|
|
|
|
|
|
// Scale
|
|
|
|
bool scaling;
|
|
|
|
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;
|
|
|
|
bool can_log();
|
|
|
|
|
2017-07-03 00:46:33 +00:00
|
|
|
public:
|
2018-11-08 10:16:55 +00:00
|
|
|
blur_instance(obs_data_t* settings, obs_source_t* self);
|
|
|
|
~blur_instance();
|
2018-09-30 18:50:00 +00:00
|
|
|
|
|
|
|
obs_properties_t* get_properties();
|
|
|
|
void update(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
|
|
|
};
|
|
|
|
|
2018-11-08 10:16:55 +00:00
|
|
|
class blur_factory {
|
2018-09-30 18:50:00 +00:00
|
|
|
obs_source_info source_info;
|
2018-12-22 21:07:33 +00:00
|
|
|
std::list<blur_instance*> sources;
|
2018-09-30 18:50:00 +00:00
|
|
|
std::shared_ptr<gs::effect> color_converter_effect;
|
2018-09-30 20:48:47 +00:00
|
|
|
std::shared_ptr<gs::effect> mask_effect;
|
2018-09-30 18:50:00 +00:00
|
|
|
|
2018-12-22 21:07:33 +00:00
|
|
|
std::shared_ptr<gs::effect> blur_effect;
|
2018-09-30 18:50:00 +00:00
|
|
|
std::map<filter::blur::type, std::shared_ptr<gs::texture>> kernels;
|
2018-12-23 01:00:30 +00:00
|
|
|
std::map<uint8_t, std::shared_ptr<std::vector<float_t>>> gaussian_kernels;
|
2017-07-03 05:20:15 +00:00
|
|
|
|
2018-09-30 22:54:36 +00:00
|
|
|
std::map<std::string, obs_scene_t*> scenes;
|
|
|
|
|
2017-07-03 00:46:33 +00:00
|
|
|
private:
|
2018-11-08 10:16:55 +00:00
|
|
|
blur_factory();
|
|
|
|
~blur_factory();
|
2017-07-03 05:20:15 +00:00
|
|
|
|
2018-09-30 18:50:00 +00:00
|
|
|
void on_list_fill();
|
|
|
|
void on_list_empty();
|
2017-07-03 05:20:15 +00:00
|
|
|
|
2018-09-30 18:50:00 +00:00
|
|
|
void generate_gaussian_kernels();
|
|
|
|
void generate_kernel_textures();
|
2017-07-06 04:02:41 +00:00
|
|
|
|
2018-09-30 18:50:00 +00:00
|
|
|
protected:
|
2018-09-30 22:54:36 +00:00
|
|
|
static void* create(obs_data_t* settings, obs_source_t* self);
|
2018-09-30 18:50:00 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
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);
|
2018-04-28 22:14:29 +00:00
|
|
|
|
2018-09-30 22:54:36 +00:00
|
|
|
static void scene_create_handler(void* ptr, calldata_t* data);
|
|
|
|
static void scene_destroy_handler(void* ptr, calldata_t* data);
|
|
|
|
|
2018-09-30 18:50:00 +00:00
|
|
|
public:
|
|
|
|
std::shared_ptr<gs::effect> get_effect(filter::blur::type type);
|
|
|
|
|
2018-12-22 21:07:33 +00:00
|
|
|
std::string get_technique(filter::blur::type type);
|
|
|
|
|
2018-09-30 18:50:00 +00:00
|
|
|
std::shared_ptr<gs::effect> get_color_converter_effect();
|
|
|
|
|
2018-09-30 20:48:47 +00:00
|
|
|
std::shared_ptr<gs::effect> get_mask_effect();
|
|
|
|
|
2018-09-30 18:50:00 +00:00
|
|
|
std::shared_ptr<gs::texture> get_kernel(filter::blur::type type);
|
|
|
|
|
2018-12-23 01:00:30 +00:00
|
|
|
std::shared_ptr<std::vector<float_t>> get_gaussian_kernel(uint8_t size);
|
|
|
|
|
2018-09-30 22:54:36 +00:00
|
|
|
obs_scene_t* get_scene(std::string name);
|
|
|
|
|
|
|
|
void enum_scenes(std::function<bool(obs_scene_t*)> fnc);
|
|
|
|
|
2018-09-30 18:50:00 +00:00
|
|
|
public: // Singleton
|
2018-12-22 21:07:33 +00:00
|
|
|
static void initialize();
|
|
|
|
static void finalize();
|
2018-11-08 10:16:55 +00:00
|
|
|
static blur_factory* get();
|
2017-07-03 00:46:33 +00:00
|
|
|
};
|
2018-09-30 18:50:00 +00:00
|
|
|
|
|
|
|
} // namespace blur
|
|
|
|
|
|
|
|
} // namespace filter
|
2018-11-08 10:16:55 +00:00
|
|
|
|
|
|
|
#endif
|