2023-02-28 01:15:26 +00:00
|
|
|
// AUTOGENERATED COPYRIGHT HEADER START
|
|
|
|
// Copyright (C) 2019-2023 Michael Fabian 'Xaymar' Dirks <info@xaymar.com>
|
|
|
|
// AUTOGENERATED COPYRIGHT HEADER END
|
2019-04-27 14:10:16 +00:00
|
|
|
|
|
|
|
#pragma once
|
2020-04-02 15:02:01 +00:00
|
|
|
#include "common.hpp"
|
2019-04-27 14:10:16 +00:00
|
|
|
#include "gfx/gfx-source-texture.hpp"
|
2022-11-28 08:11:55 +00:00
|
|
|
#include "gfx/gfx-util.hpp"
|
2019-04-27 14:10:16 +00:00
|
|
|
#include "obs/gs/gs-effect.hpp"
|
2022-10-30 01:15:41 +00:00
|
|
|
#include "obs/obs-source-active-child.hpp"
|
2022-05-28 18:17:04 +00:00
|
|
|
#include "obs/obs-source-active-reference.hpp"
|
2019-12-03 19:11:27 +00:00
|
|
|
#include "obs/obs-source-factory.hpp"
|
2022-05-28 18:17:04 +00:00
|
|
|
#include "obs/obs-source-showing-reference.hpp"
|
2019-04-27 14:10:16 +00:00
|
|
|
#include "obs/obs-source-tracker.hpp"
|
|
|
|
#include "obs/obs-source.hpp"
|
2020-11-29 03:22:42 +00:00
|
|
|
#include "obs/obs-tools.hpp"
|
2019-04-27 14:10:16 +00:00
|
|
|
|
2022-08-29 10:29:44 +00:00
|
|
|
#include "warning-disable.hpp"
|
|
|
|
#include <list>
|
|
|
|
#include <map>
|
|
|
|
#include "warning-enable.hpp"
|
|
|
|
|
2020-04-05 16:52:06 +00:00
|
|
|
namespace streamfx::filter::dynamic_mask {
|
2020-08-10 01:29:05 +00:00
|
|
|
enum class channel : int8_t { Invalid = -1, Red, Green, Blue, Alpha };
|
2019-04-27 14:10:16 +00:00
|
|
|
|
2022-10-30 01:15:41 +00:00
|
|
|
class data {
|
|
|
|
streamfx::obs::gs::effect _channel_mask_fx;
|
|
|
|
|
|
|
|
private:
|
|
|
|
data();
|
|
|
|
|
|
|
|
public:
|
|
|
|
~data();
|
|
|
|
|
|
|
|
streamfx::obs::gs::effect channel_mask_fx();
|
|
|
|
|
|
|
|
public:
|
|
|
|
static std::shared_ptr<streamfx::filter::dynamic_mask::data> get();
|
|
|
|
};
|
|
|
|
|
2020-01-13 21:40:15 +00:00
|
|
|
class dynamic_mask_instance : public obs::source_instance {
|
2022-10-30 01:15:41 +00:00
|
|
|
std::shared_ptr<streamfx::filter::dynamic_mask::data> _data;
|
2022-11-28 08:11:55 +00:00
|
|
|
std::shared_ptr<streamfx::gfx::util> _gfx_util;
|
2022-10-30 01:15:41 +00:00
|
|
|
|
2020-01-13 21:40:15 +00:00
|
|
|
std::map<std::tuple<channel, channel, std::string>, std::string> _translation_map;
|
2019-04-27 14:10:16 +00:00
|
|
|
|
2022-10-30 01:15:41 +00:00
|
|
|
streamfx::obs::weak_source _input;
|
|
|
|
std::unique_ptr<streamfx::obs::source_active_child> _input_child;
|
|
|
|
std::shared_ptr<streamfx::obs::source_showing_reference> _input_vs;
|
|
|
|
std::shared_ptr<streamfx::obs::source_active_reference> _input_ac;
|
2019-04-27 14:10:16 +00:00
|
|
|
|
2022-10-30 01:15:41 +00:00
|
|
|
// Base texture for filtering
|
|
|
|
bool _have_base;
|
|
|
|
std::shared_ptr<streamfx::obs::gs::rendertarget> _base_rt;
|
|
|
|
std::shared_ptr<streamfx::obs::gs::texture> _base_tex;
|
|
|
|
gs_color_space _base_color_space;
|
|
|
|
gs_color_format _base_color_format;
|
|
|
|
bool _base_srgb;
|
2019-04-27 14:10:16 +00:00
|
|
|
|
2022-10-30 01:15:41 +00:00
|
|
|
bool _have_input;
|
|
|
|
std::shared_ptr<streamfx::obs::gs::rendertarget> _input_rt;
|
|
|
|
std::shared_ptr<streamfx::obs::gs::texture> _input_tex;
|
|
|
|
gs_color_space _input_color_space;
|
|
|
|
gs_color_format _input_color_format;
|
|
|
|
bool _input_srgb;
|
2019-04-27 14:10:16 +00:00
|
|
|
|
2022-10-30 01:15:41 +00:00
|
|
|
bool _have_final;
|
2021-06-08 02:38:24 +00:00
|
|
|
std::shared_ptr<streamfx::obs::gs::rendertarget> _final_rt;
|
2022-10-30 01:15:41 +00:00
|
|
|
std::shared_ptr<streamfx::obs::gs::texture> _final_tex;
|
|
|
|
bool _final_srgb;
|
|
|
|
|
|
|
|
int64_t _debug_texture;
|
2019-04-27 14:10:16 +00:00
|
|
|
|
2020-01-13 21:40:15 +00:00
|
|
|
struct channel_data {
|
|
|
|
float_t value = 0.0;
|
|
|
|
float_t scale = 1.0;
|
2020-04-08 21:38:42 +00:00
|
|
|
vec4 values = {0, 0, 0, 0};
|
2020-01-13 21:40:15 +00:00
|
|
|
};
|
|
|
|
std::map<channel, channel_data> _channels;
|
2019-04-27 14:10:16 +00:00
|
|
|
|
2020-01-13 21:40:15 +00:00
|
|
|
struct _precalc {
|
|
|
|
vec4 base;
|
|
|
|
vec4 scale;
|
|
|
|
matrix4 matrix;
|
|
|
|
} _precalc;
|
2019-04-27 14:10:16 +00:00
|
|
|
|
2020-01-13 21:40:15 +00:00
|
|
|
public:
|
|
|
|
dynamic_mask_instance(obs_data_t* data, obs_source_t* self);
|
|
|
|
virtual ~dynamic_mask_instance();
|
2019-04-27 14:10:16 +00:00
|
|
|
|
2020-01-13 21:40:15 +00:00
|
|
|
virtual void load(obs_data_t* settings) override;
|
2020-08-10 01:29:05 +00:00
|
|
|
virtual void migrate(obs_data_t* data, uint64_t version) override;
|
2020-04-05 04:02:03 +00:00
|
|
|
virtual void update(obs_data_t* settings) override;
|
2020-01-13 21:40:15 +00:00
|
|
|
virtual void save(obs_data_t* settings) override;
|
2019-04-27 14:10:16 +00:00
|
|
|
|
2022-10-30 01:15:41 +00:00
|
|
|
virtual gs_color_space video_get_color_space(size_t count, const gs_color_space* preferred_spaces) override;
|
|
|
|
virtual void video_tick(float_t time) override;
|
|
|
|
virtual void video_render(gs_effect_t* effect) override;
|
2020-11-29 03:22:42 +00:00
|
|
|
|
|
|
|
void enum_active_sources(obs_source_enum_proc_t enum_callback, void* param) override;
|
|
|
|
void enum_all_sources(obs_source_enum_proc_t enum_callback, void* param) override;
|
|
|
|
|
|
|
|
void show() override;
|
|
|
|
void hide() override;
|
|
|
|
void activate() override;
|
|
|
|
void deactivate() override;
|
2021-10-17 09:39:05 +00:00
|
|
|
|
|
|
|
bool acquire(std::string_view name);
|
|
|
|
void release();
|
2020-01-13 21:40:15 +00:00
|
|
|
};
|
2019-12-03 19:11:27 +00:00
|
|
|
|
2023-05-13 12:35:46 +00:00
|
|
|
class dynamic_mask_factory : public obs::source_factory<filter::dynamic_mask::dynamic_mask_factory, filter::dynamic_mask::dynamic_mask_instance> {
|
2020-01-13 21:40:15 +00:00
|
|
|
std::list<std::string> _translation_cache;
|
2019-12-03 19:11:27 +00:00
|
|
|
|
2020-01-13 21:40:15 +00:00
|
|
|
public:
|
|
|
|
dynamic_mask_factory();
|
|
|
|
virtual ~dynamic_mask_factory() override;
|
2019-12-03 19:11:27 +00:00
|
|
|
|
2020-01-13 21:40:15 +00:00
|
|
|
virtual const char* get_name() override;
|
2019-12-03 19:11:27 +00:00
|
|
|
|
2020-01-13 21:40:15 +00:00
|
|
|
virtual void get_defaults2(obs_data_t* data) override;
|
2019-12-03 19:11:27 +00:00
|
|
|
|
2020-01-13 21:40:15 +00:00
|
|
|
virtual obs_properties_t* get_properties2(filter::dynamic_mask::dynamic_mask_instance* data) override;
|
2019-12-03 19:11:27 +00:00
|
|
|
|
2020-01-13 21:40:15 +00:00
|
|
|
std::string translate_string(const char* format, ...);
|
2020-04-05 16:52:06 +00:00
|
|
|
|
2021-04-16 23:43:30 +00:00
|
|
|
#ifdef ENABLE_FRONTEND
|
|
|
|
static bool on_manual_open(obs_properties_t* props, obs_property_t* property, void* data);
|
|
|
|
#endif
|
|
|
|
|
2020-04-05 16:52:06 +00:00
|
|
|
public: // Singleton
|
|
|
|
static void initialize();
|
|
|
|
|
|
|
|
static void finalize();
|
|
|
|
|
|
|
|
static std::shared_ptr<dynamic_mask_factory> get();
|
2020-01-13 21:40:15 +00:00
|
|
|
};
|
2020-04-05 16:52:06 +00:00
|
|
|
} // namespace streamfx::filter::dynamic_mask
|