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
|
|
|
|
*/
|
|
|
|
|
2019-01-14 10:23:21 +00:00
|
|
|
#include "filter-blur.hpp"
|
2019-01-14 22:52:57 +00:00
|
|
|
#include <cfloat>
|
2019-01-14 10:23:21 +00:00
|
|
|
#include <cinttypes>
|
2019-01-14 22:52:57 +00:00
|
|
|
#include <cmath>
|
2018-09-30 18:50:00 +00:00
|
|
|
#include <map>
|
2019-04-02 01:05:05 +00:00
|
|
|
#include "gfx/blur/gfx-blur-box-linear.hpp"
|
|
|
|
#include "gfx/blur/gfx-blur-box.hpp"
|
|
|
|
#include "gfx/blur/gfx-blur-dual-filtering.hpp"
|
|
|
|
#include "gfx/blur/gfx-blur-gaussian-linear.hpp"
|
|
|
|
#include "gfx/blur/gfx-blur-gaussian.hpp"
|
2019-04-02 22:16:13 +00:00
|
|
|
#include "obs/gs/gs-helper.hpp"
|
2019-02-11 02:54:16 +00:00
|
|
|
#include "obs/obs-source-tracker.hpp"
|
2019-01-14 10:23:21 +00:00
|
|
|
#include "strings.hpp"
|
|
|
|
#include "util-math.hpp"
|
2017-07-03 00:46:33 +00:00
|
|
|
|
2019-01-14 10:23:21 +00:00
|
|
|
// OBS
|
|
|
|
#ifdef _MSC_VER
|
2018-09-30 18:50:00 +00:00
|
|
|
#pragma warning(push)
|
|
|
|
#pragma warning(disable : 4201)
|
2019-01-14 10:23:21 +00:00
|
|
|
#endif
|
|
|
|
#include <callback/signal.h>
|
|
|
|
#include <graphics/graphics.h>
|
|
|
|
#include <graphics/matrix4.h>
|
|
|
|
#include <util/platform.h>
|
|
|
|
#ifdef _MSC_VER
|
2018-09-30 18:50:00 +00:00
|
|
|
#pragma warning(pop)
|
2019-01-14 10:23:21 +00:00
|
|
|
#endif
|
2017-07-03 00:46:33 +00:00
|
|
|
|
2018-09-30 18:50:00 +00:00
|
|
|
// Translation Strings
|
2019-08-04 14:20:26 +00:00
|
|
|
#define ST "Filter.Blur"
|
|
|
|
|
|
|
|
#define ST_TYPE "Filter.Blur.Type"
|
|
|
|
#define ST_SUBTYPE "Filter.Blur.SubType"
|
|
|
|
#define ST_SIZE "Filter.Blur.Size"
|
|
|
|
#define ST_ANGLE "Filter.Blur.Angle"
|
|
|
|
#define ST_CENTER "Filter.Blur.Center"
|
|
|
|
#define ST_CENTER_X "Filter.Blur.Center.X"
|
|
|
|
#define ST_CENTER_Y "Filter.Blur.Center.Y"
|
|
|
|
#define ST_STEPSCALE "Filter.Blur.StepScale"
|
|
|
|
#define ST_STEPSCALE_X "Filter.Blur.StepScale.X"
|
|
|
|
#define ST_STEPSCALE_Y "Filter.Blur.StepScale.Y"
|
|
|
|
#define ST_MASK "Filter.Blur.Mask"
|
|
|
|
#define ST_MASK_TYPE "Filter.Blur.Mask.Type"
|
|
|
|
#define ST_MASK_TYPE_REGION "Filter.Blur.Mask.Type.Region"
|
|
|
|
#define ST_MASK_TYPE_IMAGE "Filter.Blur.Mask.Type.Image"
|
|
|
|
#define ST_MASK_TYPE_SOURCE "Filter.Blur.Mask.Type.Source"
|
|
|
|
#define ST_MASK_REGION_LEFT "Filter.Blur.Mask.Region.Left"
|
|
|
|
#define ST_MASK_REGION_RIGHT "Filter.Blur.Mask.Region.Right"
|
|
|
|
#define ST_MASK_REGION_TOP "Filter.Blur.Mask.Region.Top"
|
|
|
|
#define ST_MASK_REGION_BOTTOM "Filter.Blur.Mask.Region.Bottom"
|
|
|
|
#define ST_MASK_REGION_FEATHER "Filter.Blur.Mask.Region.Feather"
|
|
|
|
#define ST_MASK_REGION_FEATHER_SHIFT "Filter.Blur.Mask.Region.Feather.Shift"
|
|
|
|
#define ST_MASK_REGION_INVERT "Filter.Blur.Mask.Region.Invert"
|
|
|
|
#define ST_MASK_IMAGE "Filter.Blur.Mask.Image"
|
|
|
|
#define ST_MASK_SOURCE "Filter.Blur.Mask.Source"
|
|
|
|
#define ST_MASK_COLOR "Filter.Blur.Mask.Color"
|
|
|
|
#define ST_MASK_ALPHA "Filter.Blur.Mask.Alpha"
|
|
|
|
#define ST_MASK_MULTIPLIER "Filter.Blur.Mask.Multiplier"
|
2018-04-28 11:59:54 +00:00
|
|
|
|
2019-04-02 01:05:05 +00:00
|
|
|
struct local_blur_type_t {
|
|
|
|
std::function<::gfx::blur::ifactory&()> fn;
|
|
|
|
const char* name;
|
|
|
|
};
|
|
|
|
struct local_blur_subtype_t {
|
|
|
|
::gfx::blur::type type;
|
|
|
|
const char* name;
|
2017-07-06 04:02:41 +00:00
|
|
|
};
|
2017-12-13 23:24:37 +00:00
|
|
|
|
2019-04-19 07:42:15 +00:00
|
|
|
static std::map<std::string, local_blur_type_t> list_of_types = {
|
2019-04-02 01:05:05 +00:00
|
|
|
{"box", {&::gfx::blur::box_factory::get, S_BLUR_TYPE_BOX}},
|
|
|
|
{"box_linear", {&::gfx::blur::box_linear_factory::get, S_BLUR_TYPE_BOX_LINEAR}},
|
|
|
|
{"gaussian", {&::gfx::blur::gaussian_factory::get, S_BLUR_TYPE_GAUSSIAN}},
|
|
|
|
{"gaussian_linear", {&::gfx::blur::gaussian_linear_factory::get, S_BLUR_TYPE_GAUSSIAN_LINEAR}},
|
|
|
|
{"dual_filtering", {&::gfx::blur::dual_filtering_factory::get, S_BLUR_TYPE_DUALFILTERING}},
|
|
|
|
};
|
2019-04-19 07:42:15 +00:00
|
|
|
static std::map<std::string, local_blur_subtype_t> list_of_subtypes = {
|
2019-04-02 01:05:05 +00:00
|
|
|
{"area", {::gfx::blur::type::Area, S_BLUR_SUBTYPE_AREA}},
|
|
|
|
{"directional", {::gfx::blur::type::Directional, S_BLUR_SUBTYPE_DIRECTIONAL}},
|
|
|
|
{"rotational", {::gfx::blur::type::Rotational, S_BLUR_SUBTYPE_ROTATIONAL}},
|
|
|
|
{"zoom", {::gfx::blur::type::Zoom, S_BLUR_SUBTYPE_ZOOM}},
|
|
|
|
};
|
2017-07-18 14:47:29 +00:00
|
|
|
|
2019-01-27 22:33:12 +00:00
|
|
|
static std::shared_ptr<filter::blur::blur_factory> factory_instance = nullptr;
|
2018-04-28 12:41:18 +00:00
|
|
|
|
2019-01-27 22:33:12 +00:00
|
|
|
void filter::blur::blur_factory::initialize()
|
2019-01-25 16:54:18 +00:00
|
|
|
{
|
2019-01-27 22:33:12 +00:00
|
|
|
factory_instance = std::make_shared<filter::blur::blur_factory>();
|
2019-01-25 16:54:18 +00:00
|
|
|
}
|
2018-04-28 12:41:18 +00:00
|
|
|
|
2019-01-27 22:33:12 +00:00
|
|
|
void filter::blur::blur_factory::finalize()
|
2019-01-25 16:54:18 +00:00
|
|
|
{
|
|
|
|
factory_instance.reset();
|
|
|
|
}
|
2018-04-28 12:41:18 +00:00
|
|
|
|
2019-01-27 22:33:12 +00:00
|
|
|
std::shared_ptr<filter::blur::blur_factory> filter::blur::blur_factory::get()
|
2019-01-25 16:54:18 +00:00
|
|
|
{
|
|
|
|
return factory_instance;
|
2017-07-03 00:46:33 +00:00
|
|
|
}
|
|
|
|
|
2019-01-27 22:33:12 +00:00
|
|
|
filter::blur::blur_factory::blur_factory()
|
2018-09-30 18:50:00 +00:00
|
|
|
{
|
2019-08-04 14:20:26 +00:00
|
|
|
memset(&_source_info, 0, sizeof(obs_source_info));
|
|
|
|
_source_info.id = "obs-stream-effects-filter-blur";
|
|
|
|
_source_info.type = OBS_SOURCE_TYPE_FILTER;
|
|
|
|
_source_info.output_flags = OBS_SOURCE_VIDEO;
|
|
|
|
_source_info.get_name = get_name;
|
|
|
|
_source_info.get_defaults = get_defaults;
|
|
|
|
_source_info.get_properties = get_properties;
|
|
|
|
|
|
|
|
_source_info.create = create;
|
|
|
|
_source_info.destroy = destroy;
|
|
|
|
_source_info.update = update;
|
|
|
|
_source_info.activate = activate;
|
|
|
|
_source_info.deactivate = deactivate;
|
|
|
|
_source_info.video_tick = video_tick;
|
|
|
|
_source_info.video_render = video_render;
|
|
|
|
_source_info.load = load;
|
|
|
|
|
|
|
|
obs_register_source(&_source_info);
|
2019-02-01 07:35:19 +00:00
|
|
|
|
2019-02-01 18:58:05 +00:00
|
|
|
// Translation Cache
|
|
|
|
/// File Filter for Images
|
2019-08-04 14:20:26 +00:00
|
|
|
_translation_map.insert({std::string("image-filter"), std::string(D_TRANSLATE(S_FILETYPE_IMAGES))
|
2019-08-24 10:59:32 +00:00
|
|
|
+ std::string(" (" S_FILEFILTERS_IMAGE ");;")
|
|
|
|
+ std::string("* (*.*)")});
|
2017-07-03 00:46:33 +00:00
|
|
|
}
|
|
|
|
|
2019-01-27 22:33:12 +00:00
|
|
|
filter::blur::blur_factory::~blur_factory() {}
|
2017-07-03 05:20:15 +00:00
|
|
|
|
2019-01-27 22:33:12 +00:00
|
|
|
void filter::blur::blur_factory::on_list_fill()
|
2018-09-30 20:48:47 +00:00
|
|
|
{
|
2019-04-02 22:16:13 +00:00
|
|
|
auto gctx = gs::context();
|
2018-09-30 20:48:47 +00:00
|
|
|
|
2019-01-25 16:54:18 +00:00
|
|
|
{
|
2019-08-04 21:18:54 +00:00
|
|
|
char* file = obs_module_file("effects/color-conversion.effect");
|
2019-01-25 16:54:18 +00:00
|
|
|
try {
|
2019-08-04 21:18:54 +00:00
|
|
|
_color_converter_effect = gs::effect::create(file);
|
2019-07-27 17:57:17 +00:00
|
|
|
} catch (std::runtime_error& ex) {
|
2019-08-04 14:20:26 +00:00
|
|
|
P_LOG_ERROR("<filter-blur> Loading _effect '%s' failed with error(s): %s", file, ex.what());
|
2018-09-30 20:48:47 +00:00
|
|
|
}
|
2019-01-25 16:54:18 +00:00
|
|
|
bfree(file);
|
2018-09-30 20:48:47 +00:00
|
|
|
}
|
2019-01-25 16:54:18 +00:00
|
|
|
{
|
2019-08-04 21:18:54 +00:00
|
|
|
char* file = obs_module_file("effects/mask.effect");
|
2019-01-25 16:54:18 +00:00
|
|
|
try {
|
2019-08-04 21:18:54 +00:00
|
|
|
_mask_effect = gs::effect::create(file);
|
2019-07-27 17:57:17 +00:00
|
|
|
} catch (std::runtime_error& ex) {
|
2019-08-04 14:20:26 +00:00
|
|
|
P_LOG_ERROR("<filter-blur> Loading _effect '%s' failed with error(s): %s", file, ex.what());
|
2018-09-30 20:48:47 +00:00
|
|
|
}
|
2019-01-25 16:54:18 +00:00
|
|
|
bfree(file);
|
2018-09-30 20:48:47 +00:00
|
|
|
}
|
2019-01-25 16:54:18 +00:00
|
|
|
}
|
2018-09-30 20:48:47 +00:00
|
|
|
|
2019-01-27 22:33:12 +00:00
|
|
|
void filter::blur::blur_factory::on_list_empty()
|
2019-01-25 16:54:18 +00:00
|
|
|
{
|
2019-04-02 22:16:13 +00:00
|
|
|
auto gctx = gs::context();
|
2019-08-04 14:20:26 +00:00
|
|
|
_color_converter_effect.reset();
|
|
|
|
_mask_effect.reset();
|
2018-09-30 20:48:47 +00:00
|
|
|
}
|
|
|
|
|
2019-03-01 10:33:19 +00:00
|
|
|
std::string const& filter::blur::blur_factory::get_translation(std::string const key)
|
2019-02-01 18:58:05 +00:00
|
|
|
{
|
|
|
|
static std::string none("");
|
2019-08-04 14:20:26 +00:00
|
|
|
auto found = _translation_map.find(key);
|
|
|
|
if (found != _translation_map.end()) {
|
2019-02-01 18:58:05 +00:00
|
|
|
return found->second;
|
|
|
|
}
|
|
|
|
return none;
|
|
|
|
}
|
|
|
|
|
2019-01-27 22:33:12 +00:00
|
|
|
void* filter::blur::blur_factory::create(obs_data_t* data, obs_source_t* parent)
|
2018-09-30 18:50:00 +00:00
|
|
|
{
|
2019-08-04 14:20:26 +00:00
|
|
|
if (get()->_sources.empty()) {
|
2019-01-25 16:54:18 +00:00
|
|
|
get()->on_list_fill();
|
2018-09-30 18:50:00 +00:00
|
|
|
}
|
2019-01-27 22:33:12 +00:00
|
|
|
filter::blur::blur_instance* ptr = new filter::blur::blur_instance(data, parent);
|
2019-08-04 14:20:26 +00:00
|
|
|
get()->_sources.push_back(ptr);
|
2019-01-25 16:54:18 +00:00
|
|
|
return ptr;
|
2017-07-03 00:46:33 +00:00
|
|
|
}
|
|
|
|
|
2019-01-27 22:33:12 +00:00
|
|
|
void filter::blur::blur_factory::destroy(void* inptr)
|
2018-09-30 18:50:00 +00:00
|
|
|
{
|
2019-01-27 22:33:12 +00:00
|
|
|
filter::blur::blur_instance* ptr = reinterpret_cast<filter::blur::blur_instance*>(inptr);
|
2019-08-04 14:20:26 +00:00
|
|
|
get()->_sources.remove(ptr);
|
|
|
|
if (get()->_sources.empty()) {
|
2019-01-25 16:54:18 +00:00
|
|
|
get()->on_list_empty();
|
|
|
|
}
|
|
|
|
delete ptr;
|
2018-09-30 18:50:00 +00:00
|
|
|
}
|
2017-07-03 00:46:33 +00:00
|
|
|
|
2019-01-27 22:33:12 +00:00
|
|
|
void filter::blur::blur_factory::get_defaults(obs_data_t* data)
|
2018-09-30 18:50:00 +00:00
|
|
|
{
|
2019-04-02 01:05:05 +00:00
|
|
|
// Type, Subtype
|
2019-08-04 14:20:26 +00:00
|
|
|
obs_data_set_default_string(data, ST_TYPE, "box");
|
|
|
|
obs_data_set_default_string(data, ST_SUBTYPE, "area");
|
2017-12-14 02:52:29 +00:00
|
|
|
|
2019-04-02 01:05:05 +00:00
|
|
|
// Parameters
|
2019-08-04 14:20:26 +00:00
|
|
|
obs_data_set_default_int(data, ST_SIZE, 5);
|
|
|
|
obs_data_set_default_double(data, ST_ANGLE, 0.);
|
|
|
|
obs_data_set_default_double(data, ST_CENTER_X, 50.);
|
|
|
|
obs_data_set_default_double(data, ST_CENTER_Y, 50.);
|
|
|
|
obs_data_set_default_bool(data, ST_STEPSCALE, false);
|
|
|
|
obs_data_set_default_double(data, ST_STEPSCALE_X, 1.);
|
|
|
|
obs_data_set_default_double(data, ST_STEPSCALE_Y, 1.);
|
2018-09-30 22:54:36 +00:00
|
|
|
|
2019-01-25 16:54:18 +00:00
|
|
|
// Masking
|
2019-08-04 14:20:26 +00:00
|
|
|
obs_data_set_default_bool(data, ST_MASK, false);
|
|
|
|
obs_data_set_default_int(data, ST_MASK_TYPE, mask_type::Region);
|
|
|
|
obs_data_set_default_double(data, ST_MASK_REGION_LEFT, 0.0);
|
|
|
|
obs_data_set_default_double(data, ST_MASK_REGION_RIGHT, 0.0);
|
|
|
|
obs_data_set_default_double(data, ST_MASK_REGION_TOP, 0.0);
|
|
|
|
obs_data_set_default_double(data, ST_MASK_REGION_BOTTOM, 0.0);
|
|
|
|
obs_data_set_default_double(data, ST_MASK_REGION_FEATHER, 0.0);
|
|
|
|
obs_data_set_default_double(data, ST_MASK_REGION_FEATHER_SHIFT, 0.0);
|
|
|
|
obs_data_set_default_bool(data, ST_MASK_REGION_INVERT, false);
|
2019-04-02 01:05:05 +00:00
|
|
|
{
|
|
|
|
char* default_file = obs_module_file("white.png");
|
2019-08-04 14:20:26 +00:00
|
|
|
obs_data_set_default_string(data, ST_MASK_IMAGE, default_file);
|
2019-04-02 01:05:05 +00:00
|
|
|
bfree(default_file);
|
|
|
|
}
|
2019-08-04 14:20:26 +00:00
|
|
|
obs_data_set_default_string(data, ST_MASK_SOURCE, "");
|
|
|
|
obs_data_set_default_int(data, ST_MASK_COLOR, 0xFFFFFFFFull);
|
|
|
|
obs_data_set_default_double(data, ST_MASK_MULTIPLIER, 1.0);
|
2019-01-25 16:54:18 +00:00
|
|
|
}
|
2018-09-30 18:50:00 +00:00
|
|
|
|
2019-01-27 22:33:12 +00:00
|
|
|
obs_properties_t* filter::blur::blur_factory::get_properties(void* inptr)
|
2019-01-25 16:54:18 +00:00
|
|
|
{
|
2019-01-27 22:33:12 +00:00
|
|
|
return reinterpret_cast<filter::blur::blur_instance*>(inptr)->get_properties();
|
2019-01-25 16:54:18 +00:00
|
|
|
}
|
2018-09-30 18:50:00 +00:00
|
|
|
|
2019-01-27 22:33:12 +00:00
|
|
|
void filter::blur::blur_factory::update(void* inptr, obs_data_t* settings)
|
2019-01-25 16:54:18 +00:00
|
|
|
{
|
2019-01-27 22:33:12 +00:00
|
|
|
reinterpret_cast<filter::blur::blur_instance*>(inptr)->update(settings);
|
2017-07-03 00:46:33 +00:00
|
|
|
}
|
|
|
|
|
2019-01-27 22:33:12 +00:00
|
|
|
void filter::blur::blur_factory::load(void* inptr, obs_data_t* settings)
|
2019-01-27 22:29:47 +00:00
|
|
|
{
|
2019-03-01 19:38:06 +00:00
|
|
|
reinterpret_cast<filter::blur::blur_instance*>(inptr)->load(settings);
|
2019-01-27 22:29:47 +00:00
|
|
|
}
|
|
|
|
|
2019-01-27 22:33:12 +00:00
|
|
|
const char* filter::blur::blur_factory::get_name(void*)
|
2018-09-30 18:50:00 +00:00
|
|
|
{
|
2019-08-04 14:20:26 +00:00
|
|
|
return D_TRANSLATE(ST);
|
2019-01-25 16:54:18 +00:00
|
|
|
}
|
2018-09-30 18:50:00 +00:00
|
|
|
|
2019-01-27 22:33:12 +00:00
|
|
|
uint32_t filter::blur::blur_factory::get_width(void* inptr)
|
2019-01-25 16:54:18 +00:00
|
|
|
{
|
2019-01-27 22:33:12 +00:00
|
|
|
return reinterpret_cast<filter::blur::blur_instance*>(inptr)->get_width();
|
2019-01-25 16:54:18 +00:00
|
|
|
}
|
2018-09-30 18:50:00 +00:00
|
|
|
|
2019-01-27 22:33:12 +00:00
|
|
|
uint32_t filter::blur::blur_factory::get_height(void* inptr)
|
2019-01-25 16:54:18 +00:00
|
|
|
{
|
2019-01-27 22:33:12 +00:00
|
|
|
return reinterpret_cast<filter::blur::blur_instance*>(inptr)->get_height();
|
2019-01-25 16:54:18 +00:00
|
|
|
}
|
2018-04-28 22:14:29 +00:00
|
|
|
|
2019-01-27 22:33:12 +00:00
|
|
|
void filter::blur::blur_factory::activate(void* inptr)
|
2019-01-25 16:54:18 +00:00
|
|
|
{
|
2019-01-27 22:33:12 +00:00
|
|
|
reinterpret_cast<filter::blur::blur_instance*>(inptr)->activate();
|
2019-01-25 16:54:18 +00:00
|
|
|
}
|
2018-12-23 18:54:57 +00:00
|
|
|
|
2019-01-27 22:33:12 +00:00
|
|
|
void filter::blur::blur_factory::deactivate(void* inptr)
|
2019-01-25 16:54:18 +00:00
|
|
|
{
|
2019-01-27 22:33:12 +00:00
|
|
|
reinterpret_cast<filter::blur::blur_instance*>(inptr)->deactivate();
|
2019-01-25 16:54:18 +00:00
|
|
|
}
|
2018-12-23 18:54:57 +00:00
|
|
|
|
2019-01-27 22:33:12 +00:00
|
|
|
void filter::blur::blur_factory::video_tick(void* inptr, float delta)
|
2019-01-25 16:54:18 +00:00
|
|
|
{
|
2019-01-27 22:33:12 +00:00
|
|
|
reinterpret_cast<filter::blur::blur_instance*>(inptr)->video_tick(delta);
|
2017-07-03 00:46:33 +00:00
|
|
|
}
|
|
|
|
|
2019-01-27 22:33:12 +00:00
|
|
|
void filter::blur::blur_factory::video_render(void* inptr, gs_effect_t* effect)
|
2018-09-30 18:50:00 +00:00
|
|
|
{
|
2019-01-27 22:33:12 +00:00
|
|
|
reinterpret_cast<filter::blur::blur_instance*>(inptr)->video_render(effect);
|
2017-07-03 00:46:33 +00:00
|
|
|
}
|
|
|
|
|
2019-01-27 22:33:12 +00:00
|
|
|
std::shared_ptr<gs::effect> filter::blur::blur_factory::get_color_converter_effect()
|
2018-09-30 18:50:00 +00:00
|
|
|
{
|
2019-08-04 14:20:26 +00:00
|
|
|
return _color_converter_effect;
|
2019-01-25 16:54:18 +00:00
|
|
|
}
|
2017-07-03 00:46:33 +00:00
|
|
|
|
2019-01-27 22:33:12 +00:00
|
|
|
std::shared_ptr<gs::effect> filter::blur::blur_factory::get_mask_effect()
|
2019-01-25 16:54:18 +00:00
|
|
|
{
|
2019-08-04 14:20:26 +00:00
|
|
|
return _mask_effect;
|
2019-01-25 16:54:18 +00:00
|
|
|
}
|
2018-09-30 18:50:00 +00:00
|
|
|
|
2019-01-28 00:08:13 +00:00
|
|
|
filter::blur::blur_instance::blur_instance(obs_data_t* settings, obs_source_t* parent)
|
2019-08-04 14:20:26 +00:00
|
|
|
: _self(parent), _source_rendered(false), _output_rendered(false)
|
2019-01-28 00:08:13 +00:00
|
|
|
{
|
2019-08-04 14:20:26 +00:00
|
|
|
_self = parent;
|
2019-01-28 00:08:13 +00:00
|
|
|
|
|
|
|
// Create RenderTargets
|
|
|
|
try {
|
2019-08-04 14:20:26 +00:00
|
|
|
this->_source_rt = std::make_shared<gs::rendertarget>(GS_RGBA, GS_ZS_NONE);
|
|
|
|
this->_output_rt = std::make_shared<gs::rendertarget>(GS_RGBA, GS_ZS_NONE);
|
2019-07-27 17:57:17 +00:00
|
|
|
} catch (std::exception& ex) {
|
2019-08-04 14:20:26 +00:00
|
|
|
P_LOG_ERROR("<filter-blur:%s> Failed to create rendertargets, error %s.", obs_source_get_name(_self),
|
2019-01-28 00:08:13 +00:00
|
|
|
ex.what());
|
|
|
|
}
|
|
|
|
|
|
|
|
update(settings);
|
|
|
|
}
|
|
|
|
|
|
|
|
filter::blur::blur_instance::~blur_instance()
|
|
|
|
{
|
2019-08-04 14:20:26 +00:00
|
|
|
this->_mask.source.source_texture.reset();
|
|
|
|
this->_source_rt.reset();
|
|
|
|
this->_output_texture.reset();
|
2019-01-28 00:08:13 +00:00
|
|
|
}
|
|
|
|
|
2019-01-27 22:33:12 +00:00
|
|
|
bool filter::blur::blur_instance::apply_mask_parameters(std::shared_ptr<gs::effect> effect,
|
2019-01-27 22:29:47 +00:00
|
|
|
gs_texture_t* original_texture, gs_texture_t* blurred_texture)
|
2019-01-25 16:54:18 +00:00
|
|
|
{
|
|
|
|
if (effect->has_parameter("image_orig")) {
|
2019-08-04 21:12:30 +00:00
|
|
|
effect->get_parameter("image_orig")->set_texture(original_texture);
|
2019-01-25 16:54:18 +00:00
|
|
|
}
|
|
|
|
if (effect->has_parameter("image_blur")) {
|
2019-08-04 21:12:30 +00:00
|
|
|
effect->get_parameter("image_blur")->set_texture(blurred_texture);
|
2019-01-25 16:54:18 +00:00
|
|
|
}
|
2018-12-23 18:54:57 +00:00
|
|
|
|
2019-01-25 16:54:18 +00:00
|
|
|
// Region
|
2019-08-04 14:20:26 +00:00
|
|
|
if (_mask.type == mask_type::Region) {
|
2019-01-25 16:54:18 +00:00
|
|
|
if (effect->has_parameter("mask_region_left")) {
|
2019-08-04 21:12:30 +00:00
|
|
|
effect->get_parameter("mask_region_left")->set_float(_mask.region.left);
|
2019-01-25 16:54:18 +00:00
|
|
|
}
|
|
|
|
if (effect->has_parameter("mask_region_right")) {
|
2019-08-04 21:12:30 +00:00
|
|
|
effect->get_parameter("mask_region_right")->set_float(_mask.region.right);
|
2019-01-25 16:54:18 +00:00
|
|
|
}
|
|
|
|
if (effect->has_parameter("mask_region_top")) {
|
2019-08-04 21:12:30 +00:00
|
|
|
effect->get_parameter("mask_region_top")->set_float(_mask.region.top);
|
2019-01-25 16:54:18 +00:00
|
|
|
}
|
|
|
|
if (effect->has_parameter("mask_region_bottom")) {
|
2019-08-04 21:12:30 +00:00
|
|
|
effect->get_parameter("mask_region_bottom")->set_float(_mask.region.bottom);
|
2019-01-25 16:54:18 +00:00
|
|
|
}
|
|
|
|
if (effect->has_parameter("mask_region_feather")) {
|
2019-08-04 21:12:30 +00:00
|
|
|
effect->get_parameter("mask_region_feather")->set_float(_mask.region.feather);
|
2019-01-25 16:54:18 +00:00
|
|
|
}
|
|
|
|
if (effect->has_parameter("mask_region_feather_shift")) {
|
2019-08-04 21:12:30 +00:00
|
|
|
effect->get_parameter("mask_region_feather_shift")->set_float(_mask.region.feather_shift);
|
2019-01-25 16:54:18 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-23 18:54:57 +00:00
|
|
|
|
2019-01-25 16:54:18 +00:00
|
|
|
// Image
|
2019-08-04 14:20:26 +00:00
|
|
|
if (_mask.type == mask_type::Image) {
|
2019-01-25 16:54:18 +00:00
|
|
|
if (effect->has_parameter("mask_image")) {
|
2019-08-04 14:20:26 +00:00
|
|
|
if (_mask.image.texture) {
|
2019-08-04 21:12:30 +00:00
|
|
|
effect->get_parameter("mask_image")->set_texture(_mask.image.texture);
|
2018-12-23 18:54:57 +00:00
|
|
|
} else {
|
2019-08-04 21:12:30 +00:00
|
|
|
effect->get_parameter("mask_image")->set_texture(nullptr);
|
2018-12-23 18:54:57 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-25 16:54:18 +00:00
|
|
|
}
|
2018-12-23 18:54:57 +00:00
|
|
|
|
2019-01-25 16:54:18 +00:00
|
|
|
// Source
|
2019-08-04 14:20:26 +00:00
|
|
|
if (_mask.type == mask_type::Source) {
|
2019-01-25 16:54:18 +00:00
|
|
|
if (effect->has_parameter("mask_image")) {
|
2019-08-04 14:20:26 +00:00
|
|
|
if (_mask.source.texture) {
|
2019-08-04 21:12:30 +00:00
|
|
|
effect->get_parameter("mask_image")->set_texture(_mask.source.texture);
|
2018-12-23 18:54:57 +00:00
|
|
|
} else {
|
2019-08-04 21:12:30 +00:00
|
|
|
effect->get_parameter("mask_image")->set_texture(nullptr);
|
2018-12-23 18:54:57 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-25 16:54:18 +00:00
|
|
|
}
|
2018-12-23 18:54:57 +00:00
|
|
|
|
2019-01-25 16:54:18 +00:00
|
|
|
// Shared
|
|
|
|
if (effect->has_parameter("mask_color")) {
|
2019-08-04 21:12:30 +00:00
|
|
|
effect->get_parameter("mask_color")->set_float4(_mask.color.r, _mask.color.g, _mask.color.b, _mask.color.a);
|
2019-01-25 16:54:18 +00:00
|
|
|
}
|
|
|
|
if (effect->has_parameter("mask_multiplier")) {
|
2019-08-04 21:12:30 +00:00
|
|
|
effect->get_parameter("mask_multiplier")->set_float(_mask.multiplier);
|
2019-01-25 16:54:18 +00:00
|
|
|
}
|
2018-12-23 17:27:24 +00:00
|
|
|
|
2019-01-25 16:54:18 +00:00
|
|
|
return true;
|
|
|
|
}
|
2018-12-23 17:27:24 +00:00
|
|
|
|
2019-04-02 01:05:05 +00:00
|
|
|
bool filter::blur::blur_instance::modified_properties(void*, obs_properties_t* props, obs_property* prop,
|
2019-01-27 22:29:47 +00:00
|
|
|
obs_data_t* settings)
|
2019-01-25 16:54:18 +00:00
|
|
|
{
|
2019-04-02 01:05:05 +00:00
|
|
|
obs_property_t* p;
|
|
|
|
const char* propname = obs_property_name(prop);
|
2019-08-04 14:20:26 +00:00
|
|
|
const char* vtype = obs_data_get_string(settings, ST_TYPE);
|
|
|
|
const char* vsubtype = obs_data_get_string(settings, ST_SUBTYPE);
|
2019-04-02 01:05:05 +00:00
|
|
|
|
|
|
|
// Find new Type
|
|
|
|
auto type_found = list_of_types.find(vtype);
|
|
|
|
if (type_found == list_of_types.end()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find new Subtype
|
2019-04-02 21:07:53 +00:00
|
|
|
auto subtype_found = list_of_subtypes.find(vsubtype);
|
|
|
|
if (subtype_found == list_of_subtypes.end()) {
|
2019-04-02 01:05:05 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Blur Type
|
2019-08-04 14:20:26 +00:00
|
|
|
if (strcmp(propname, ST_TYPE) == 0) {
|
|
|
|
obs_property_t* prop_subtype = obs_properties_get(props, ST_SUBTYPE);
|
2019-04-02 01:05:05 +00:00
|
|
|
|
|
|
|
/// Disable unsupported items.
|
|
|
|
size_t subvalue_idx = 0;
|
|
|
|
for (size_t idx = 0, edx = obs_property_list_item_count(prop_subtype); idx < edx; idx++) {
|
|
|
|
const char* subtype = obs_property_list_item_string(prop_subtype, idx);
|
|
|
|
bool disabled = false;
|
|
|
|
|
2019-04-02 21:07:53 +00:00
|
|
|
auto subtype_found_idx = list_of_subtypes.find(subtype);
|
|
|
|
if (subtype_found_idx != list_of_subtypes.end()) {
|
|
|
|
disabled = !type_found->second.fn().is_type_supported(subtype_found_idx->second.type);
|
2019-04-02 01:05:05 +00:00
|
|
|
} else {
|
|
|
|
disabled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
obs_property_list_item_disable(prop_subtype, idx, disabled);
|
|
|
|
if (strcmp(subtype, vsubtype) == 0) {
|
|
|
|
subvalue_idx = idx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Ensure that there is a valid item selected.
|
|
|
|
if (obs_property_list_item_disabled(prop_subtype, subvalue_idx)) {
|
|
|
|
for (size_t idx = 0, edx = obs_property_list_item_count(prop_subtype); idx < edx; idx++) {
|
|
|
|
if (!obs_property_list_item_disabled(prop_subtype, idx)) {
|
2019-08-04 14:20:26 +00:00
|
|
|
obs_data_set_string(settings, ST_SUBTYPE, obs_property_list_item_string(prop_subtype, idx));
|
2019-04-15 10:54:19 +00:00
|
|
|
|
|
|
|
// Find new Subtype
|
|
|
|
auto subtype_found2 = list_of_subtypes.find(vsubtype);
|
|
|
|
if (subtype_found2 == list_of_subtypes.end()) {
|
|
|
|
subtype_found = list_of_subtypes.end();
|
|
|
|
} else {
|
|
|
|
subtype_found = subtype_found2;
|
|
|
|
}
|
|
|
|
|
2019-04-02 01:05:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-15 10:54:19 +00:00
|
|
|
// Update hover text with new descriptions.
|
|
|
|
if (type_found != list_of_types.end()) {
|
|
|
|
if (type_found->first == "box") {
|
2019-08-04 14:20:26 +00:00
|
|
|
obs_property_set_long_description(obs_properties_get(props, ST_TYPE), D_TRANSLATE(D_DESC(S_BLUR_TYPE_BOX)));
|
2019-04-15 10:54:19 +00:00
|
|
|
} else if (type_found->first == "box_linear") {
|
2019-08-04 14:20:26 +00:00
|
|
|
obs_property_set_long_description(obs_properties_get(props, ST_TYPE),
|
|
|
|
D_TRANSLATE(D_DESC(S_BLUR_TYPE_BOX_LINEAR)));
|
2019-04-15 10:54:19 +00:00
|
|
|
} else if (type_found->first == "gaussian") {
|
2019-08-04 14:20:26 +00:00
|
|
|
obs_property_set_long_description(obs_properties_get(props, ST_TYPE),
|
|
|
|
D_TRANSLATE(D_DESC(S_BLUR_TYPE_GAUSSIAN)));
|
2019-04-15 10:54:19 +00:00
|
|
|
} else if (type_found->first == "gaussian_linear") {
|
2019-08-04 14:20:26 +00:00
|
|
|
obs_property_set_long_description(obs_properties_get(props, ST_TYPE),
|
|
|
|
D_TRANSLATE(D_DESC(S_BLUR_TYPE_GAUSSIAN_LINEAR)));
|
2019-04-15 10:54:19 +00:00
|
|
|
}
|
|
|
|
} else {
|
2019-08-04 14:20:26 +00:00
|
|
|
obs_property_set_long_description(obs_properties_get(props, ST_TYPE), D_TRANSLATE(D_DESC(ST_TYPE)));
|
2019-04-15 10:54:19 +00:00
|
|
|
}
|
|
|
|
if (subtype_found != list_of_subtypes.end()) {
|
|
|
|
if (subtype_found->first == "area") {
|
2019-08-04 14:20:26 +00:00
|
|
|
obs_property_set_long_description(obs_properties_get(props, ST_SUBTYPE),
|
|
|
|
D_TRANSLATE(D_DESC(S_BLUR_SUBTYPE_AREA)));
|
2019-04-15 10:54:19 +00:00
|
|
|
} else if (subtype_found->first == "directional") {
|
2019-08-04 14:20:26 +00:00
|
|
|
obs_property_set_long_description(obs_properties_get(props, ST_SUBTYPE),
|
|
|
|
D_TRANSLATE(D_DESC(S_BLUR_SUBTYPE_DIRECTIONAL)));
|
2019-04-15 10:54:19 +00:00
|
|
|
} else if (subtype_found->first == "rotational") {
|
2019-08-04 14:20:26 +00:00
|
|
|
obs_property_set_long_description(obs_properties_get(props, ST_SUBTYPE),
|
|
|
|
D_TRANSLATE(D_DESC(S_BLUR_SUBTYPE_ROTATIONAL)));
|
2019-04-15 10:54:19 +00:00
|
|
|
} else if (subtype_found->first == "zoom") {
|
2019-08-04 14:20:26 +00:00
|
|
|
obs_property_set_long_description(obs_properties_get(props, ST_SUBTYPE),
|
|
|
|
D_TRANSLATE(D_DESC(S_BLUR_SUBTYPE_ZOOM)));
|
2019-04-15 10:54:19 +00:00
|
|
|
}
|
|
|
|
} else {
|
2019-08-04 14:20:26 +00:00
|
|
|
obs_property_set_long_description(obs_properties_get(props, ST_SUBTYPE), D_TRANSLATE(D_DESC(ST_SUBTYPE)));
|
2019-04-15 10:54:19 +00:00
|
|
|
}
|
|
|
|
|
2019-04-02 01:05:05 +00:00
|
|
|
// Blur Sub-Type
|
|
|
|
{
|
2019-04-02 21:07:53 +00:00
|
|
|
bool has_angle_support = (subtype_found->second.type == ::gfx::blur::type::Directional)
|
|
|
|
|| (subtype_found->second.type == ::gfx::blur::type::Rotational);
|
2019-04-15 10:54:19 +00:00
|
|
|
bool has_center_support = (subtype_found->second.type == ::gfx::blur::type::Rotational)
|
|
|
|
|| (subtype_found->second.type == ::gfx::blur::type::Zoom);
|
2019-04-02 21:07:53 +00:00
|
|
|
bool has_stepscale_support = type_found->second.fn().is_step_scale_supported(subtype_found->second.type);
|
2019-08-04 14:20:26 +00:00
|
|
|
bool show_scaling = obs_data_get_bool(settings, ST_STEPSCALE) && has_stepscale_support;
|
2019-04-02 01:05:05 +00:00
|
|
|
|
|
|
|
/// Size
|
2019-08-04 14:20:26 +00:00
|
|
|
p = obs_properties_get(props, ST_SIZE);
|
2019-04-02 21:07:53 +00:00
|
|
|
obs_property_float_set_limits(p, type_found->second.fn().get_min_size(subtype_found->second.type),
|
|
|
|
type_found->second.fn().get_max_size(subtype_found->second.type),
|
|
|
|
type_found->second.fn().get_step_size(subtype_found->second.type));
|
2019-04-02 01:05:05 +00:00
|
|
|
|
|
|
|
/// Angle
|
2019-08-04 14:20:26 +00:00
|
|
|
p = obs_properties_get(props, ST_ANGLE);
|
2019-04-02 01:05:05 +00:00
|
|
|
obs_property_set_visible(p, has_angle_support);
|
2019-04-02 21:07:53 +00:00
|
|
|
obs_property_float_set_limits(p, type_found->second.fn().get_min_angle(subtype_found->second.type),
|
|
|
|
type_found->second.fn().get_max_angle(subtype_found->second.type),
|
|
|
|
type_found->second.fn().get_step_angle(subtype_found->second.type));
|
2019-04-02 01:05:05 +00:00
|
|
|
|
|
|
|
/// Center, Radius
|
2019-08-04 14:20:26 +00:00
|
|
|
obs_property_set_visible(obs_properties_get(props, ST_CENTER_X), has_center_support);
|
|
|
|
obs_property_set_visible(obs_properties_get(props, ST_CENTER_Y), has_center_support);
|
2019-04-02 01:05:05 +00:00
|
|
|
|
|
|
|
/// Step Scaling
|
2019-08-04 14:20:26 +00:00
|
|
|
obs_property_set_visible(obs_properties_get(props, ST_STEPSCALE), has_stepscale_support);
|
|
|
|
p = obs_properties_get(props, ST_STEPSCALE_X);
|
2019-04-02 01:05:05 +00:00
|
|
|
obs_property_set_visible(p, show_scaling);
|
2019-04-02 21:07:53 +00:00
|
|
|
obs_property_float_set_limits(p, type_found->second.fn().get_min_step_scale_x(subtype_found->second.type),
|
|
|
|
type_found->second.fn().get_max_step_scale_x(subtype_found->second.type),
|
|
|
|
type_found->second.fn().get_step_step_scale_x(subtype_found->second.type));
|
2019-08-04 14:20:26 +00:00
|
|
|
p = obs_properties_get(props, ST_STEPSCALE_Y);
|
2019-04-02 01:05:05 +00:00
|
|
|
obs_property_set_visible(p, show_scaling);
|
2019-04-02 21:07:53 +00:00
|
|
|
obs_property_float_set_limits(p, type_found->second.fn().get_min_step_scale_x(subtype_found->second.type),
|
|
|
|
type_found->second.fn().get_max_step_scale_x(subtype_found->second.type),
|
|
|
|
type_found->second.fn().get_step_step_scale_x(subtype_found->second.type));
|
2019-04-02 01:05:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // Masking
|
2019-08-04 14:20:26 +00:00
|
|
|
bool show_mask = obs_data_get_bool(settings, ST_MASK);
|
|
|
|
mask_type mtype = static_cast<mask_type>(obs_data_get_int(settings, ST_MASK_TYPE));
|
2019-04-02 01:05:05 +00:00
|
|
|
bool show_region = (mtype == mask_type::Region) && show_mask;
|
|
|
|
bool show_image = (mtype == mask_type::Image) && show_mask;
|
|
|
|
bool show_source = (mtype == mask_type::Source) && show_mask;
|
2019-08-04 14:20:26 +00:00
|
|
|
obs_property_set_visible(obs_properties_get(props, ST_MASK_TYPE), show_mask);
|
|
|
|
obs_property_set_visible(obs_properties_get(props, ST_MASK_REGION_LEFT), show_region);
|
|
|
|
obs_property_set_visible(obs_properties_get(props, ST_MASK_REGION_TOP), show_region);
|
|
|
|
obs_property_set_visible(obs_properties_get(props, ST_MASK_REGION_RIGHT), show_region);
|
|
|
|
obs_property_set_visible(obs_properties_get(props, ST_MASK_REGION_BOTTOM), show_region);
|
|
|
|
obs_property_set_visible(obs_properties_get(props, ST_MASK_REGION_FEATHER), show_region);
|
|
|
|
obs_property_set_visible(obs_properties_get(props, ST_MASK_REGION_FEATHER_SHIFT), show_region);
|
|
|
|
obs_property_set_visible(obs_properties_get(props, ST_MASK_REGION_INVERT), show_region);
|
|
|
|
obs_property_set_visible(obs_properties_get(props, ST_MASK_IMAGE), show_image);
|
|
|
|
obs_property_set_visible(obs_properties_get(props, ST_MASK_SOURCE), show_source);
|
|
|
|
obs_property_set_visible(obs_properties_get(props, ST_MASK_COLOR), show_image || show_source);
|
|
|
|
obs_property_set_visible(obs_properties_get(props, ST_MASK_ALPHA), show_image || show_source);
|
|
|
|
obs_property_set_visible(obs_properties_get(props, ST_MASK_MULTIPLIER), show_image || show_source);
|
2019-04-02 01:05:05 +00:00
|
|
|
}
|
2019-01-25 16:54:18 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-04-02 01:05:05 +00:00
|
|
|
void filter::blur::blur_instance::translate_old_settings(obs_data_t* settings)
|
|
|
|
{
|
|
|
|
obs_data_set_default_int(settings, S_VERSION, -1);
|
|
|
|
int64_t version = obs_data_get_int(settings, S_VERSION);
|
|
|
|
|
|
|
|
// If it's the same as the current version, return.
|
|
|
|
if (version == PROJECT_VERSION) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now we use a fall-through switch to gradually upgrade each known version change.
|
|
|
|
switch (version) {
|
|
|
|
case -1:
|
|
|
|
/// Blur Type
|
|
|
|
int64_t old_blur = obs_data_get_int(settings, "Filter.Blur.Type");
|
|
|
|
if (old_blur == 0) { // Box
|
2019-08-04 14:20:26 +00:00
|
|
|
obs_data_set_string(settings, ST_TYPE, "box");
|
2019-04-02 01:05:05 +00:00
|
|
|
} else if (old_blur == 1) { // Gaussian
|
2019-08-04 14:20:26 +00:00
|
|
|
obs_data_set_string(settings, ST_TYPE, "gaussian");
|
2019-04-02 01:05:05 +00:00
|
|
|
} else if (old_blur == 2) { // Bilateral, no longer included.
|
2019-08-04 14:20:26 +00:00
|
|
|
obs_data_set_string(settings, ST_TYPE, "box");
|
2019-04-02 01:05:05 +00:00
|
|
|
} else if (old_blur == 3) { // Box Linear
|
2019-08-04 14:20:26 +00:00
|
|
|
obs_data_set_string(settings, ST_TYPE, "box_linear");
|
2019-04-02 01:05:05 +00:00
|
|
|
} else if (old_blur == 4) { // Gaussian Linear
|
2019-08-04 14:20:26 +00:00
|
|
|
obs_data_set_string(settings, ST_TYPE, "gaussian_linear");
|
2019-04-02 01:05:05 +00:00
|
|
|
} else {
|
2019-08-04 14:20:26 +00:00
|
|
|
obs_data_set_string(settings, ST_TYPE, "box");
|
2019-04-02 01:05:05 +00:00
|
|
|
}
|
|
|
|
obs_data_unset_user_value(settings, "Filter.Blur.Type");
|
|
|
|
|
|
|
|
/// Directional Blur
|
|
|
|
bool directional = obs_data_get_bool(settings, "Filter.Blur.Directional");
|
|
|
|
if (directional) {
|
2019-08-04 14:20:26 +00:00
|
|
|
obs_data_set_string(settings, ST_SUBTYPE, "directional");
|
2019-04-02 01:05:05 +00:00
|
|
|
} else {
|
2019-08-04 14:20:26 +00:00
|
|
|
obs_data_set_string(settings, ST_SUBTYPE, "area");
|
2019-04-02 01:05:05 +00:00
|
|
|
}
|
|
|
|
obs_data_unset_user_value(settings, "Filter.Blur.Directional");
|
|
|
|
|
|
|
|
/// Directional Blur Angle
|
|
|
|
double_t angle = obs_data_get_double(settings, "Filter.Blur.Directional.Angle");
|
2019-08-04 14:20:26 +00:00
|
|
|
obs_data_set_double(settings, ST_ANGLE, angle);
|
2019-04-02 01:05:05 +00:00
|
|
|
obs_data_unset_user_value(settings, "Filter.Blur.Directional.Angle");
|
|
|
|
}
|
|
|
|
|
|
|
|
obs_data_set_int(settings, S_VERSION, PROJECT_VERSION);
|
|
|
|
}
|
|
|
|
|
2019-01-27 22:33:12 +00:00
|
|
|
obs_properties_t* filter::blur::blur_instance::get_properties()
|
2019-01-25 16:54:18 +00:00
|
|
|
{
|
|
|
|
obs_properties_t* pr = obs_properties_create();
|
|
|
|
obs_property_t* p = NULL;
|
|
|
|
|
2019-04-02 01:05:05 +00:00
|
|
|
// Blur Type and Sub-Type
|
|
|
|
{
|
2019-08-04 14:20:26 +00:00
|
|
|
p = obs_properties_add_list(pr, ST_TYPE, D_TRANSLATE(ST_TYPE), OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_STRING);
|
|
|
|
obs_property_set_long_description(p, D_TRANSLATE(D_DESC(ST_TYPE)));
|
2019-04-02 01:05:05 +00:00
|
|
|
obs_property_set_modified_callback2(p, modified_properties, this);
|
2019-08-04 14:20:26 +00:00
|
|
|
obs_property_list_add_string(p, D_TRANSLATE(S_BLUR_TYPE_BOX), "box");
|
|
|
|
obs_property_list_add_string(p, D_TRANSLATE(S_BLUR_TYPE_BOX_LINEAR), "box_linear");
|
|
|
|
obs_property_list_add_string(p, D_TRANSLATE(S_BLUR_TYPE_GAUSSIAN), "gaussian");
|
|
|
|
obs_property_list_add_string(p, D_TRANSLATE(S_BLUR_TYPE_GAUSSIAN_LINEAR), "gaussian_linear");
|
|
|
|
obs_property_list_add_string(p, D_TRANSLATE(S_BLUR_TYPE_DUALFILTERING), "dual_filtering");
|
2019-04-02 01:05:05 +00:00
|
|
|
|
2019-08-04 14:20:26 +00:00
|
|
|
p = obs_properties_add_list(pr, ST_SUBTYPE, D_TRANSLATE(ST_SUBTYPE), OBS_COMBO_TYPE_LIST,
|
2019-04-02 01:05:05 +00:00
|
|
|
OBS_COMBO_FORMAT_STRING);
|
2019-08-04 14:20:26 +00:00
|
|
|
obs_property_set_long_description(p, D_TRANSLATE(D_DESC(ST_SUBTYPE)));
|
2019-04-02 01:05:05 +00:00
|
|
|
obs_property_set_modified_callback2(p, modified_properties, this);
|
2019-08-04 14:20:26 +00:00
|
|
|
obs_property_list_add_string(p, D_TRANSLATE(S_BLUR_SUBTYPE_AREA), "area");
|
|
|
|
obs_property_list_add_string(p, D_TRANSLATE(S_BLUR_SUBTYPE_DIRECTIONAL), "directional");
|
|
|
|
obs_property_list_add_string(p, D_TRANSLATE(S_BLUR_SUBTYPE_ROTATIONAL), "rotational");
|
|
|
|
obs_property_list_add_string(p, D_TRANSLATE(S_BLUR_SUBTYPE_ZOOM), "zoom");
|
2019-04-02 01:05:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Blur Parameters
|
|
|
|
{
|
2019-08-04 14:20:26 +00:00
|
|
|
p = obs_properties_add_float_slider(pr, ST_SIZE, D_TRANSLATE(ST_SIZE), 1, 32767, 1);
|
|
|
|
obs_property_set_long_description(p, D_TRANSLATE(D_DESC(ST_SIZE)));
|
2019-04-02 01:05:05 +00:00
|
|
|
|
2019-08-04 14:20:26 +00:00
|
|
|
p = obs_properties_add_float_slider(pr, ST_ANGLE, D_TRANSLATE(ST_ANGLE), -180.0, 180.0, 0.01);
|
|
|
|
obs_property_set_long_description(p, D_TRANSLATE(D_DESC(ST_ANGLE)));
|
2019-04-02 01:05:05 +00:00
|
|
|
|
2019-08-04 14:20:26 +00:00
|
|
|
p = obs_properties_add_float_slider(pr, ST_CENTER_X, D_TRANSLATE(ST_CENTER_X), 0.00, 100.0, 0.01);
|
|
|
|
obs_property_set_long_description(p, D_TRANSLATE(D_DESC(ST_CENTER_X)));
|
|
|
|
p = obs_properties_add_float_slider(pr, ST_CENTER_Y, D_TRANSLATE(ST_CENTER_Y), 0.00, 100.0, 0.01);
|
|
|
|
obs_property_set_long_description(p, D_TRANSLATE(D_DESC(ST_CENTER_Y)));
|
2019-04-02 01:05:05 +00:00
|
|
|
|
2019-08-04 14:20:26 +00:00
|
|
|
p = obs_properties_add_bool(pr, ST_STEPSCALE, D_TRANSLATE(ST_STEPSCALE));
|
|
|
|
obs_property_set_long_description(p, D_TRANSLATE(D_DESC(ST_STEPSCALE)));
|
2019-04-02 01:05:05 +00:00
|
|
|
obs_property_set_modified_callback2(p, modified_properties, this);
|
2019-08-04 14:20:26 +00:00
|
|
|
p = obs_properties_add_float_slider(pr, ST_STEPSCALE_X, D_TRANSLATE(ST_STEPSCALE_X), 0.0, 1000.0, 0.01);
|
|
|
|
obs_property_set_long_description(p, D_TRANSLATE(D_DESC(ST_STEPSCALE_X)));
|
|
|
|
p = obs_properties_add_float_slider(pr, ST_STEPSCALE_Y, D_TRANSLATE(ST_STEPSCALE_Y), 0.0, 1000.0, 0.01);
|
|
|
|
obs_property_set_long_description(p, D_TRANSLATE(D_DESC(ST_STEPSCALE_Y)));
|
2019-04-02 01:05:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Masking
|
|
|
|
{
|
2019-08-04 14:20:26 +00:00
|
|
|
p = obs_properties_add_bool(pr, ST_MASK, D_TRANSLATE(ST_MASK));
|
|
|
|
obs_property_set_long_description(p, D_TRANSLATE(D_DESC(ST_MASK)));
|
2019-04-02 01:05:05 +00:00
|
|
|
obs_property_set_modified_callback2(p, modified_properties, this);
|
2019-08-04 14:20:26 +00:00
|
|
|
p = obs_properties_add_list(pr, ST_MASK_TYPE, D_TRANSLATE(ST_MASK_TYPE), OBS_COMBO_TYPE_LIST,
|
2019-04-02 01:05:05 +00:00
|
|
|
OBS_COMBO_FORMAT_INT);
|
2019-08-04 14:20:26 +00:00
|
|
|
obs_property_set_long_description(p, D_TRANSLATE(D_DESC(ST_MASK_TYPE)));
|
2019-04-02 01:05:05 +00:00
|
|
|
obs_property_set_modified_callback2(p, modified_properties, this);
|
2019-08-04 14:20:26 +00:00
|
|
|
obs_property_list_add_int(p, D_TRANSLATE(ST_MASK_TYPE_REGION), mask_type::Region);
|
|
|
|
obs_property_list_add_int(p, D_TRANSLATE(ST_MASK_TYPE_IMAGE), mask_type::Image);
|
|
|
|
obs_property_list_add_int(p, D_TRANSLATE(ST_MASK_TYPE_SOURCE), mask_type::Source);
|
2019-04-02 01:05:05 +00:00
|
|
|
/// Region
|
2019-08-24 10:59:32 +00:00
|
|
|
p = obs_properties_add_float_slider(pr, ST_MASK_REGION_LEFT, D_TRANSLATE(ST_MASK_REGION_LEFT), 0.0, 100.0,
|
|
|
|
0.01);
|
2019-08-04 14:20:26 +00:00
|
|
|
obs_property_set_long_description(p, D_TRANSLATE(D_DESC(ST_MASK_REGION_LEFT)));
|
|
|
|
p = obs_properties_add_float_slider(pr, ST_MASK_REGION_TOP, D_TRANSLATE(ST_MASK_REGION_TOP), 0.0, 100.0, 0.01);
|
|
|
|
obs_property_set_long_description(p, D_TRANSLATE(D_DESC(ST_MASK_REGION_TOP)));
|
|
|
|
p = obs_properties_add_float_slider(pr, ST_MASK_REGION_RIGHT, D_TRANSLATE(ST_MASK_REGION_RIGHT), 0.0, 100.0,
|
2019-04-02 01:05:05 +00:00
|
|
|
0.01);
|
2019-08-04 14:20:26 +00:00
|
|
|
obs_property_set_long_description(p, D_TRANSLATE(D_DESC(ST_MASK_REGION_RIGHT)));
|
|
|
|
p = obs_properties_add_float_slider(pr, ST_MASK_REGION_BOTTOM, D_TRANSLATE(ST_MASK_REGION_BOTTOM), 0.0, 100.0,
|
2019-04-02 01:05:05 +00:00
|
|
|
0.01);
|
2019-08-04 14:20:26 +00:00
|
|
|
obs_property_set_long_description(p, D_TRANSLATE(D_DESC(ST_MASK_REGION_BOTTOM)));
|
|
|
|
p = obs_properties_add_float_slider(pr, ST_MASK_REGION_FEATHER, D_TRANSLATE(ST_MASK_REGION_FEATHER), 0.0, 50.0,
|
2019-04-02 01:05:05 +00:00
|
|
|
0.01);
|
2019-08-04 14:20:26 +00:00
|
|
|
obs_property_set_long_description(p, D_TRANSLATE(D_DESC(ST_MASK_REGION_FEATHER)));
|
|
|
|
p = obs_properties_add_float_slider(pr, ST_MASK_REGION_FEATHER_SHIFT, D_TRANSLATE(ST_MASK_REGION_FEATHER_SHIFT),
|
2019-04-02 01:05:05 +00:00
|
|
|
-100.0, 100.0, 0.01);
|
2019-08-04 14:20:26 +00:00
|
|
|
obs_property_set_long_description(p, D_TRANSLATE(D_DESC(ST_MASK_REGION_FEATHER_SHIFT)));
|
|
|
|
p = obs_properties_add_bool(pr, ST_MASK_REGION_INVERT, D_TRANSLATE(ST_MASK_REGION_INVERT));
|
|
|
|
obs_property_set_long_description(p, D_TRANSLATE(D_DESC(ST_MASK_REGION_INVERT)));
|
2019-04-02 01:05:05 +00:00
|
|
|
/// Image
|
2019-08-04 14:20:26 +00:00
|
|
|
p = obs_properties_add_path(pr, ST_MASK_IMAGE, D_TRANSLATE(ST_MASK_IMAGE), OBS_PATH_FILE,
|
2019-04-02 01:05:05 +00:00
|
|
|
filter::blur::blur_factory::get()->get_translation("image-filter").c_str(),
|
|
|
|
nullptr);
|
2019-08-04 14:20:26 +00:00
|
|
|
obs_property_set_long_description(p, D_TRANSLATE(D_DESC(ST_MASK_IMAGE)));
|
2019-04-02 01:05:05 +00:00
|
|
|
/// Source
|
2019-08-04 14:20:26 +00:00
|
|
|
p = obs_properties_add_list(pr, ST_MASK_SOURCE, D_TRANSLATE(ST_MASK_SOURCE), OBS_COMBO_TYPE_LIST,
|
2019-04-02 01:05:05 +00:00
|
|
|
OBS_COMBO_FORMAT_STRING);
|
2019-08-04 14:20:26 +00:00
|
|
|
obs_property_set_long_description(p, D_TRANSLATE(D_DESC(ST_MASK_SOURCE)));
|
2019-04-02 17:56:03 +00:00
|
|
|
obs_property_list_add_string(p, "", "");
|
2019-04-02 01:05:05 +00:00
|
|
|
obs::source_tracker::get()->enumerate(
|
2019-04-19 07:42:15 +00:00
|
|
|
[&p](std::string name, obs_source_t*) {
|
2019-04-02 01:05:05 +00:00
|
|
|
obs_property_list_add_string(p, std::string(name + " (Source)").c_str(), name.c_str());
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
obs::source_tracker::filter_video_sources);
|
|
|
|
obs::source_tracker::get()->enumerate(
|
2019-04-19 07:42:15 +00:00
|
|
|
[&p](std::string name, obs_source_t*) {
|
2019-04-02 01:05:05 +00:00
|
|
|
obs_property_list_add_string(p, std::string(name + " (Scene)").c_str(), name.c_str());
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
obs::source_tracker::filter_scenes);
|
|
|
|
|
|
|
|
/// Shared
|
2019-08-04 14:20:26 +00:00
|
|
|
p = obs_properties_add_color(pr, ST_MASK_COLOR, D_TRANSLATE(ST_MASK_COLOR));
|
|
|
|
obs_property_set_long_description(p, D_TRANSLATE(D_DESC(ST_MASK_COLOR)));
|
|
|
|
p = obs_properties_add_float_slider(pr, ST_MASK_ALPHA, D_TRANSLATE(ST_MASK_ALPHA), 0.0, 100.0, 0.1);
|
|
|
|
obs_property_set_long_description(p, D_TRANSLATE(D_DESC(ST_MASK_ALPHA)));
|
|
|
|
p = obs_properties_add_float_slider(pr, ST_MASK_MULTIPLIER, D_TRANSLATE(ST_MASK_MULTIPLIER), 0.0, 10.0, 0.01);
|
|
|
|
obs_property_set_long_description(p, D_TRANSLATE(D_DESC(ST_MASK_MULTIPLIER)));
|
2019-04-02 01:05:05 +00:00
|
|
|
}
|
2019-01-25 16:54:18 +00:00
|
|
|
|
|
|
|
return pr;
|
|
|
|
}
|
|
|
|
|
2019-01-27 22:33:12 +00:00
|
|
|
void filter::blur::blur_instance::update(obs_data_t* settings)
|
2019-01-25 16:54:18 +00:00
|
|
|
{
|
2019-04-02 01:05:05 +00:00
|
|
|
// Ensure backwards compatibility.
|
|
|
|
this->translate_old_settings(settings);
|
|
|
|
|
|
|
|
{ // Blur Type
|
2019-08-04 14:20:26 +00:00
|
|
|
const char* blur_type = obs_data_get_string(settings, ST_TYPE);
|
|
|
|
const char* blur_subtype = obs_data_get_string(settings, ST_SUBTYPE);
|
|
|
|
const char* last_blur_type = obs_data_get_string(settings, ST_TYPE ".last");
|
2019-04-02 01:05:05 +00:00
|
|
|
|
|
|
|
auto type_found = list_of_types.find(blur_type);
|
|
|
|
if (type_found != list_of_types.end()) {
|
|
|
|
auto subtype_found = list_of_subtypes.find(blur_subtype);
|
|
|
|
if (subtype_found != list_of_subtypes.end()) {
|
2019-08-04 14:20:26 +00:00
|
|
|
if ((strcmp(last_blur_type, blur_type) != 0) || (_blur->get_type() != subtype_found->second.type)) {
|
2019-04-02 01:05:05 +00:00
|
|
|
if (type_found->second.fn().is_type_supported(subtype_found->second.type)) {
|
2019-08-04 14:20:26 +00:00
|
|
|
_blur = type_found->second.fn().create(subtype_found->second.type);
|
2019-04-02 01:05:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-25 16:54:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-02 01:05:05 +00:00
|
|
|
{ // Blur Parameters
|
2019-08-04 14:20:26 +00:00
|
|
|
this->_blur_size = obs_data_get_double(settings, ST_SIZE);
|
|
|
|
this->_blur_angle = obs_data_get_double(settings, ST_ANGLE);
|
|
|
|
this->_blur_center.first = obs_data_get_double(settings, ST_CENTER_X) / 100.0;
|
|
|
|
this->_blur_center.second = obs_data_get_double(settings, ST_CENTER_Y) / 100.0;
|
2019-01-25 16:54:18 +00:00
|
|
|
|
2019-04-02 01:05:05 +00:00
|
|
|
// Scaling
|
2019-08-04 14:20:26 +00:00
|
|
|
this->_blur_step_scaling = obs_data_get_bool(settings, ST_STEPSCALE);
|
|
|
|
this->_blur_step_scale.first = obs_data_get_double(settings, ST_STEPSCALE_X) / 100.0;
|
|
|
|
this->_blur_step_scale.second = obs_data_get_double(settings, ST_STEPSCALE_Y) / 100.0;
|
2019-04-02 01:05:05 +00:00
|
|
|
}
|
2019-01-25 16:54:18 +00:00
|
|
|
|
2019-04-02 01:05:05 +00:00
|
|
|
{ // Masking
|
2019-08-04 14:20:26 +00:00
|
|
|
_mask.enabled = obs_data_get_bool(settings, ST_MASK);
|
|
|
|
if (_mask.enabled) {
|
|
|
|
_mask.type = static_cast<mask_type>(obs_data_get_int(settings, ST_MASK_TYPE));
|
|
|
|
switch (_mask.type) {
|
2019-04-02 01:05:05 +00:00
|
|
|
case mask_type::Region:
|
2019-08-04 14:20:26 +00:00
|
|
|
_mask.region.left = float_t(obs_data_get_double(settings, ST_MASK_REGION_LEFT) / 100.0);
|
|
|
|
_mask.region.top = float_t(obs_data_get_double(settings, ST_MASK_REGION_TOP) / 100.0);
|
|
|
|
_mask.region.right = 1.0f - float_t(obs_data_get_double(settings, ST_MASK_REGION_RIGHT) / 100.0);
|
|
|
|
_mask.region.bottom = 1.0f - float_t(obs_data_get_double(settings, ST_MASK_REGION_BOTTOM) / 100.0);
|
|
|
|
_mask.region.feather = float_t(obs_data_get_double(settings, ST_MASK_REGION_FEATHER) / 100.0);
|
|
|
|
_mask.region.feather_shift =
|
|
|
|
float_t(obs_data_get_double(settings, ST_MASK_REGION_FEATHER_SHIFT) / 100.0);
|
|
|
|
_mask.region.invert = obs_data_get_bool(settings, ST_MASK_REGION_INVERT);
|
2019-04-02 01:05:05 +00:00
|
|
|
break;
|
|
|
|
case mask_type::Image:
|
2019-08-04 14:20:26 +00:00
|
|
|
_mask.image.path = obs_data_get_string(settings, ST_MASK_IMAGE);
|
2019-04-02 01:05:05 +00:00
|
|
|
break;
|
|
|
|
case mask_type::Source:
|
2019-08-04 14:20:26 +00:00
|
|
|
_mask.source.name = obs_data_get_string(settings, ST_MASK_SOURCE);
|
2019-04-02 01:05:05 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-08-04 14:20:26 +00:00
|
|
|
if ((_mask.type == mask_type::Image) || (_mask.type == mask_type::Source)) {
|
2019-08-24 10:59:32 +00:00
|
|
|
uint32_t color = static_cast<uint32_t>(obs_data_get_int(settings, ST_MASK_COLOR));
|
2019-08-04 14:20:26 +00:00
|
|
|
_mask.color.r = ((color >> 0) & 0xFF) / 255.0f;
|
|
|
|
_mask.color.g = ((color >> 8) & 0xFF) / 255.0f;
|
|
|
|
_mask.color.b = ((color >> 16) & 0xFF) / 255.0f;
|
|
|
|
_mask.color.a = static_cast<float_t>(obs_data_get_double(settings, ST_MASK_ALPHA));
|
|
|
|
_mask.multiplier = float_t(obs_data_get_double(settings, ST_MASK_MULTIPLIER));
|
2019-04-02 01:05:05 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-25 16:54:18 +00:00
|
|
|
}
|
2019-01-27 23:00:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void filter::blur::blur_instance::load(obs_data_t* settings)
|
|
|
|
{
|
|
|
|
update(settings);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t filter::blur::blur_instance::get_width()
|
|
|
|
{
|
|
|
|
return uint32_t(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t filter::blur::blur_instance::get_height()
|
|
|
|
{
|
|
|
|
return uint32_t(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void filter::blur::blur_instance::activate() {}
|
|
|
|
|
|
|
|
void filter::blur::blur_instance::deactivate() {}
|
2019-01-25 16:54:18 +00:00
|
|
|
|
2019-01-27 23:00:45 +00:00
|
|
|
void filter::blur::blur_instance::video_tick(float)
|
|
|
|
{
|
2019-04-02 01:05:05 +00:00
|
|
|
// Blur
|
2019-08-04 14:20:26 +00:00
|
|
|
if (_blur) {
|
|
|
|
_blur->set_size(_blur_size);
|
|
|
|
if (_blur_step_scaling) {
|
|
|
|
_blur->set_step_scale(_blur_step_scale.first, _blur_step_scale.second);
|
2019-04-02 01:05:05 +00:00
|
|
|
} else {
|
2019-08-04 14:20:26 +00:00
|
|
|
_blur->set_step_scale(1.0, 1.0);
|
2019-04-02 01:05:05 +00:00
|
|
|
}
|
2019-08-04 14:20:26 +00:00
|
|
|
if ((_blur->get_type() == ::gfx::blur::type::Directional)
|
|
|
|
|| (_blur->get_type() == ::gfx::blur::type::Rotational)) {
|
|
|
|
auto obj = std::dynamic_pointer_cast<::gfx::blur::base_angle>(_blur);
|
|
|
|
obj->set_angle(_blur_angle);
|
2019-04-02 01:05:05 +00:00
|
|
|
}
|
2019-08-04 14:20:26 +00:00
|
|
|
if ((_blur->get_type() == ::gfx::blur::type::Zoom) || (_blur->get_type() == ::gfx::blur::type::Rotational)) {
|
|
|
|
auto obj = std::dynamic_pointer_cast<::gfx::blur::base_center>(_blur);
|
|
|
|
obj->set_center(_blur_center.first, _blur_center.second);
|
2019-04-02 01:05:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-27 22:19:09 +00:00
|
|
|
// Load Mask
|
2019-08-04 14:20:26 +00:00
|
|
|
if (_mask.type == mask_type::Image) {
|
|
|
|
if (_mask.image.path_old != _mask.image.path) {
|
2019-01-25 16:54:18 +00:00
|
|
|
try {
|
2019-08-04 14:20:26 +00:00
|
|
|
_mask.image.texture = std::make_shared<gs::texture>(_mask.image.path);
|
|
|
|
_mask.image.path_old = _mask.image.path;
|
2019-01-25 16:54:18 +00:00
|
|
|
} catch (...) {
|
2019-08-04 14:20:26 +00:00
|
|
|
P_LOG_ERROR("<filter-blur> Instance '%s' failed to load image '%s'.", obs_source_get_name(_self),
|
|
|
|
_mask.image.path.c_str());
|
2018-12-23 17:27:24 +00:00
|
|
|
}
|
2019-01-25 16:54:18 +00:00
|
|
|
}
|
2019-08-04 14:20:26 +00:00
|
|
|
} else if (_mask.type == mask_type::Source) {
|
|
|
|
if (_mask.source.name_old != _mask.source.name) {
|
2019-01-25 16:54:18 +00:00
|
|
|
try {
|
2019-08-04 14:20:26 +00:00
|
|
|
_mask.source.source_texture = std::make_shared<gfx::source_texture>(_mask.source.name, _self);
|
|
|
|
_mask.source.is_scene = (obs_scene_from_source(_mask.source.source_texture->get_object()) != nullptr);
|
|
|
|
_mask.source.name_old = _mask.source.name;
|
2019-01-25 16:54:18 +00:00
|
|
|
} catch (...) {
|
2019-08-04 14:20:26 +00:00
|
|
|
P_LOG_ERROR("<filter-blur> Instance '%s' failed to grab source '%s'.", obs_source_get_name(_self),
|
|
|
|
_mask.source.name.c_str());
|
2018-12-23 17:27:24 +00:00
|
|
|
}
|
2017-08-19 22:19:58 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-06 03:57:57 +00:00
|
|
|
|
2019-08-04 14:20:26 +00:00
|
|
|
_source_rendered = false;
|
|
|
|
_output_rendered = false;
|
2019-01-27 22:29:47 +00:00
|
|
|
}
|
|
|
|
|
2019-01-27 22:33:12 +00:00
|
|
|
void filter::blur::blur_instance::video_render(gs_effect_t* effect)
|
2019-01-25 16:54:18 +00:00
|
|
|
{
|
2019-08-04 14:20:26 +00:00
|
|
|
obs_source_t* parent = obs_filter_get_parent(this->_self);
|
|
|
|
obs_source_t* target = obs_filter_get_target(this->_self);
|
2019-04-02 01:05:05 +00:00
|
|
|
gs_effect_t* defaultEffect = obs_get_base_effect(obs_base_effect::OBS_EFFECT_DEFAULT);
|
|
|
|
uint32_t baseW = obs_source_get_base_width(target);
|
|
|
|
uint32_t baseH = obs_source_get_base_height(target);
|
2019-01-25 16:54:18 +00:00
|
|
|
|
2019-01-27 22:33:12 +00:00
|
|
|
std::shared_ptr<gs::effect> colorConversionEffect = blur_factory::get()->get_color_converter_effect();
|
2019-04-02 01:05:05 +00:00
|
|
|
vec4 black;
|
2019-01-28 00:08:13 +00:00
|
|
|
|
|
|
|
vec4_set(&black, 0, 0, 0, 0);
|
2019-01-25 16:54:18 +00:00
|
|
|
|
|
|
|
// Verify that we can actually run first.
|
2019-08-04 14:20:26 +00:00
|
|
|
if (!target || !parent || !this->_self || !this->_blur || (baseW == 0) || (baseH == 0)) {
|
|
|
|
obs_source_skip_video_filter(this->_self);
|
2019-01-25 16:54:18 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-04 14:20:26 +00:00
|
|
|
if (!_source_rendered) {
|
2019-01-27 23:00:45 +00:00
|
|
|
// Source To Texture
|
|
|
|
{
|
2019-08-04 14:20:26 +00:00
|
|
|
if (obs_source_process_filter_begin(this->_self, GS_RGBA, OBS_ALLOW_DIRECT_RENDERING)) {
|
2019-04-02 01:05:05 +00:00
|
|
|
{
|
2019-08-04 14:20:26 +00:00
|
|
|
auto op = this->_source_rt->render(baseW, baseH);
|
2019-01-27 23:00:45 +00:00
|
|
|
|
2019-04-02 01:05:05 +00:00
|
|
|
gs_blend_state_push();
|
|
|
|
gs_reset_blend_state();
|
|
|
|
gs_enable_blending(false);
|
|
|
|
gs_blend_function(GS_BLEND_ONE, GS_BLEND_ZERO);
|
2019-01-27 23:00:45 +00:00
|
|
|
|
2019-04-02 01:05:05 +00:00
|
|
|
gs_set_cull_mode(GS_NEITHER);
|
|
|
|
gs_enable_color(true, true, true, true);
|
2019-01-27 23:00:45 +00:00
|
|
|
|
2019-04-02 01:05:05 +00:00
|
|
|
gs_enable_depth_test(false);
|
|
|
|
gs_depth_function(GS_ALWAYS);
|
2019-01-27 23:00:45 +00:00
|
|
|
|
2019-04-02 01:05:05 +00:00
|
|
|
gs_enable_stencil_test(false);
|
|
|
|
gs_enable_stencil_write(false);
|
|
|
|
gs_stencil_function(GS_STENCIL_BOTH, GS_ALWAYS);
|
|
|
|
gs_stencil_op(GS_STENCIL_BOTH, GS_KEEP, GS_KEEP, GS_KEEP);
|
2019-01-27 23:00:45 +00:00
|
|
|
|
2019-04-02 01:05:05 +00:00
|
|
|
// Orthographic Camera and clear RenderTarget.
|
|
|
|
gs_ortho(0, (float)baseW, 0, (float)baseH, -1., 1.);
|
|
|
|
//gs_clear(GS_CLEAR_COLOR | GS_CLEAR_DEPTH, &black, 0, 0);
|
2019-01-27 23:00:45 +00:00
|
|
|
|
2019-04-02 01:05:05 +00:00
|
|
|
// Render
|
2019-08-04 14:20:26 +00:00
|
|
|
obs_source_process_filter_end(this->_self, defaultEffect, baseW, baseH);
|
2018-09-30 18:50:00 +00:00
|
|
|
|
2019-04-02 01:05:05 +00:00
|
|
|
gs_blend_state_pop();
|
2019-01-25 16:54:18 +00:00
|
|
|
}
|
2019-01-27 23:00:45 +00:00
|
|
|
|
2019-08-04 14:20:26 +00:00
|
|
|
_source_texture = this->_source_rt->get_texture();
|
|
|
|
if (!_source_texture) {
|
|
|
|
obs_source_skip_video_filter(this->_self);
|
2019-04-02 01:05:05 +00:00
|
|
|
return;
|
2019-01-27 23:00:45 +00:00
|
|
|
}
|
2019-04-02 01:05:05 +00:00
|
|
|
} else {
|
2019-08-04 14:20:26 +00:00
|
|
|
obs_source_skip_video_filter(this->_self);
|
2019-01-27 23:00:45 +00:00
|
|
|
return;
|
2019-01-25 16:54:18 +00:00
|
|
|
}
|
|
|
|
}
|
2018-09-30 22:54:36 +00:00
|
|
|
|
2019-08-04 14:20:26 +00:00
|
|
|
_source_rendered = true;
|
2019-04-02 01:05:05 +00:00
|
|
|
}
|
|
|
|
|
2019-08-04 14:20:26 +00:00
|
|
|
if (!_output_rendered) {
|
|
|
|
_blur->set_input(_source_texture);
|
|
|
|
_output_texture = _blur->render();
|
2019-04-02 01:05:05 +00:00
|
|
|
|
2019-01-27 23:00:45 +00:00
|
|
|
// Mask
|
2019-08-04 14:20:26 +00:00
|
|
|
if (_mask.enabled) {
|
2019-01-27 23:00:45 +00:00
|
|
|
gs_blend_state_push();
|
|
|
|
gs_reset_blend_state();
|
|
|
|
gs_enable_color(true, true, true, true);
|
|
|
|
gs_enable_blending(false);
|
|
|
|
gs_enable_depth_test(false);
|
|
|
|
gs_enable_stencil_test(false);
|
|
|
|
gs_enable_stencil_write(false);
|
|
|
|
gs_set_cull_mode(GS_NEITHER);
|
|
|
|
gs_depth_function(GS_ALWAYS);
|
|
|
|
gs_blend_function(GS_BLEND_ONE, GS_BLEND_ZERO);
|
|
|
|
gs_stencil_function(GS_STENCIL_BOTH, GS_ALWAYS);
|
|
|
|
gs_stencil_op(GS_STENCIL_BOTH, GS_ZERO, GS_ZERO, GS_ZERO);
|
|
|
|
|
|
|
|
std::string technique = "";
|
2019-08-04 14:20:26 +00:00
|
|
|
switch (this->_mask.type) {
|
2019-01-27 23:00:45 +00:00
|
|
|
case Region:
|
2019-08-04 14:20:26 +00:00
|
|
|
if (this->_mask.region.feather > std::numeric_limits<float_t>::epsilon()) {
|
|
|
|
if (this->_mask.region.invert) {
|
2019-01-27 23:00:45 +00:00
|
|
|
technique = "RegionFeatherInverted";
|
|
|
|
} else {
|
|
|
|
technique = "RegionFeather";
|
|
|
|
}
|
2019-01-25 16:54:18 +00:00
|
|
|
} else {
|
2019-08-04 14:20:26 +00:00
|
|
|
if (this->_mask.region.invert) {
|
2019-01-27 23:00:45 +00:00
|
|
|
technique = "RegionInverted";
|
|
|
|
} else {
|
|
|
|
technique = "Region";
|
|
|
|
}
|
2019-01-25 16:54:18 +00:00
|
|
|
}
|
2019-01-27 23:00:45 +00:00
|
|
|
break;
|
|
|
|
case Image:
|
|
|
|
case Source:
|
|
|
|
technique = "Image";
|
|
|
|
break;
|
2019-01-25 16:54:18 +00:00
|
|
|
}
|
2018-12-22 21:07:33 +00:00
|
|
|
|
2019-08-04 14:20:26 +00:00
|
|
|
if (_mask.source.source_texture) {
|
|
|
|
uint32_t source_width = obs_source_get_width(this->_mask.source.source_texture->get_object());
|
|
|
|
uint32_t source_height = obs_source_get_height(this->_mask.source.source_texture->get_object());
|
2018-09-30 18:50:00 +00:00
|
|
|
|
2019-01-27 23:00:45 +00:00
|
|
|
if (source_width == 0) {
|
|
|
|
source_width = baseW;
|
|
|
|
}
|
|
|
|
if (source_height == 0) {
|
|
|
|
source_height = baseH;
|
|
|
|
}
|
2019-08-04 14:20:26 +00:00
|
|
|
if (this->_mask.source.is_scene) {
|
2019-01-27 23:00:45 +00:00
|
|
|
obs_video_info ovi;
|
|
|
|
if (obs_get_video_info(&ovi)) {
|
|
|
|
source_width = ovi.base_width;
|
|
|
|
source_height = ovi.base_height;
|
|
|
|
}
|
2019-01-25 16:54:18 +00:00
|
|
|
}
|
2018-09-30 18:50:00 +00:00
|
|
|
|
2019-08-04 14:20:26 +00:00
|
|
|
this->_mask.source.texture = this->_mask.source.source_texture->render(source_width, source_height);
|
2019-01-27 23:00:45 +00:00
|
|
|
}
|
2018-09-30 20:48:47 +00:00
|
|
|
|
2019-01-27 23:00:45 +00:00
|
|
|
std::shared_ptr<gs::effect> mask_effect = blur_factory::get()->get_mask_effect();
|
2019-08-04 14:20:26 +00:00
|
|
|
apply_mask_parameters(mask_effect, _source_texture->get_object(), _output_texture->get_object());
|
2018-09-30 18:50:00 +00:00
|
|
|
|
2019-01-27 23:00:45 +00:00
|
|
|
try {
|
2019-08-04 14:20:26 +00:00
|
|
|
auto op = this->_output_rt->render(baseW, baseH);
|
2019-01-27 23:00:45 +00:00
|
|
|
gs_ortho(0, (float)baseW, 0, (float)baseH, -1, 1);
|
2018-12-23 01:00:30 +00:00
|
|
|
|
2019-01-27 23:00:45 +00:00
|
|
|
// Render
|
|
|
|
while (gs_effect_loop(mask_effect->get_object(), technique.c_str())) {
|
2019-08-04 14:20:26 +00:00
|
|
|
gs_draw_sprite(_output_texture->get_object(), 0, baseW, baseH);
|
2019-01-27 23:00:45 +00:00
|
|
|
}
|
2019-04-02 01:05:05 +00:00
|
|
|
} catch (const std::exception&) {
|
2019-01-27 23:00:45 +00:00
|
|
|
gs_blend_state_pop();
|
2019-08-04 14:20:26 +00:00
|
|
|
obs_source_skip_video_filter(this->_self);
|
2019-01-27 23:00:45 +00:00
|
|
|
return;
|
2019-01-25 16:54:18 +00:00
|
|
|
}
|
|
|
|
gs_blend_state_pop();
|
|
|
|
|
2019-08-04 14:20:26 +00:00
|
|
|
if (!(_output_texture = this->_output_rt->get_texture())) {
|
|
|
|
obs_source_skip_video_filter(this->_self);
|
2019-01-27 23:00:45 +00:00
|
|
|
return;
|
2019-01-25 16:54:18 +00:00
|
|
|
}
|
2018-09-30 22:54:36 +00:00
|
|
|
}
|
2019-01-25 16:54:18 +00:00
|
|
|
|
2019-08-04 14:20:26 +00:00
|
|
|
_output_rendered = true;
|
2018-09-30 22:54:36 +00:00
|
|
|
}
|
|
|
|
|
2019-04-02 01:05:05 +00:00
|
|
|
// Draw source
|
2019-01-25 16:54:18 +00:00
|
|
|
{
|
|
|
|
// It is important that we do not modify the blend state here, as it is set correctly by OBS
|
2019-04-02 01:05:05 +00:00
|
|
|
gs_set_cull_mode(GS_NEITHER);
|
2019-01-25 16:54:18 +00:00
|
|
|
gs_enable_color(true, true, true, true);
|
|
|
|
gs_enable_depth_test(false);
|
2019-04-02 01:05:05 +00:00
|
|
|
gs_depth_function(GS_ALWAYS);
|
2019-01-25 16:54:18 +00:00
|
|
|
gs_enable_stencil_test(false);
|
|
|
|
gs_enable_stencil_write(false);
|
|
|
|
gs_stencil_function(GS_STENCIL_BOTH, GS_ALWAYS);
|
|
|
|
gs_stencil_op(GS_STENCIL_BOTH, GS_ZERO, GS_ZERO, GS_ZERO);
|
|
|
|
|
|
|
|
gs_effect_t* finalEffect = effect ? effect : defaultEffect;
|
|
|
|
const char* technique = "Draw";
|
2018-09-30 18:50:00 +00:00
|
|
|
|
2019-01-25 16:54:18 +00:00
|
|
|
gs_eparam_t* param = gs_effect_get_param_by_name(finalEffect, "image");
|
|
|
|
if (!param) {
|
2019-08-04 14:20:26 +00:00
|
|
|
P_LOG_ERROR("<filter-blur:%s> Failed to set image param.", obs_source_get_name(this->_self));
|
|
|
|
obs_source_skip_video_filter(_self);
|
2019-04-02 01:05:05 +00:00
|
|
|
return;
|
2019-01-25 16:54:18 +00:00
|
|
|
} else {
|
2019-08-04 14:20:26 +00:00
|
|
|
gs_effect_set_texture(param, _output_texture->get_object());
|
2019-01-25 16:54:18 +00:00
|
|
|
}
|
|
|
|
while (gs_effect_loop(finalEffect, technique)) {
|
2019-08-04 14:20:26 +00:00
|
|
|
gs_draw_sprite(_output_texture->get_object(), 0, baseW, baseH);
|
2019-01-25 16:54:18 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-03 00:46:33 +00:00
|
|
|
}
|