0
0
mirror of https://github.com/obsproject/obs-studio.git synced 2024-09-20 13:08:50 +02:00

obs-filters: Add HDR bypass for color correction

Not sure how to implement controls for HDR, so skip unless SDR for now.
This commit is contained in:
jpark37 2022-07-23 01:26:28 -07:00 committed by Jim
parent 0d5ba81e32
commit 8b9fb03d06
2 changed files with 53 additions and 13 deletions

View File

@ -20,6 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/* clang-format off */
#define SETTING_SDR_ONLY_INFO "sdr_only_info"
#define SETTING_GAMMA "gamma"
#define SETTING_CONTRAST "contrast"
#define SETTING_BRIGHTNESS "brightness"
@ -30,6 +31,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define SETTING_COLOR_MULTIPLY "color_multiply"
#define SETTING_COLOR_ADD "color_add"
#define TEXT_SDR_ONLY_INFO obs_module_text("SdrOnlyInfo")
#define TEXT_GAMMA obs_module_text("Gamma")
#define TEXT_CONTRAST obs_module_text("Contrast")
#define TEXT_BRIGHTNESS obs_module_text("Brightness")
@ -599,25 +601,41 @@ static void color_correction_filter_render_v1(void *data, gs_effect_t *effect)
static void color_correction_filter_render_v2(void *data, gs_effect_t *effect)
{
UNUSED_PARAMETER(effect);
struct color_correction_filter_data_v2 *filter = data;
if (!obs_source_process_filter_begin(filter->context, GS_RGBA,
OBS_ALLOW_DIRECT_RENDERING))
return;
const enum gs_color_space preferred_spaces[] = {
GS_CS_SRGB,
GS_CS_SRGB_16F,
GS_CS_709_EXTENDED,
};
/* Now pass the interface variables to the .effect file. */
gs_effect_set_float(filter->gamma_param, filter->gamma);
gs_effect_set_matrix4(filter->final_matrix_param,
&filter->final_matrix);
const enum gs_color_space source_space = obs_source_get_color_space(
obs_filter_get_parent(filter->context),
OBS_COUNTOF(preferred_spaces), preferred_spaces);
if (source_space == GS_CS_709_EXTENDED) {
obs_source_skip_video_filter(filter->context);
} else {
const enum gs_color_format format =
gs_get_format_from_space(source_space);
if (obs_source_process_filter_begin_with_color_space(
filter->context, format, source_space,
OBS_ALLOW_DIRECT_RENDERING)) {
/* Now pass the interface variables to the .effect file. */
gs_effect_set_float(filter->gamma_param, filter->gamma);
gs_effect_set_matrix4(filter->final_matrix_param,
&filter->final_matrix);
gs_blend_state_push();
gs_blend_function(GS_BLEND_ONE, GS_BLEND_INVSRCALPHA);
gs_blend_state_push();
gs_blend_function(GS_BLEND_ONE, GS_BLEND_INVSRCALPHA);
obs_source_process_filter_end(filter->context, filter->effect, 0, 0);
obs_source_process_filter_end(filter->context,
filter->effect, 0, 0);
gs_blend_state_pop();
UNUSED_PARAMETER(effect);
gs_blend_state_pop();
}
}
}
/*
@ -654,6 +672,9 @@ static obs_properties_t *color_correction_filter_properties_v2(void *data)
{
obs_properties_t *props = obs_properties_create();
obs_properties_add_text(props, SETTING_SDR_ONLY_INFO,
TEXT_SDR_ONLY_INFO, OBS_TEXT_INFO);
obs_properties_add_float_slider(props, SETTING_GAMMA, TEXT_GAMMA, -3.0,
3.0, 0.01);
@ -706,6 +727,23 @@ static void color_correction_filter_defaults_v2(obs_data_t *settings)
obs_data_set_default_int(settings, SETTING_COLOR_ADD, 0x00000000);
}
static enum gs_color_space color_correction_filter_get_color_space(
void *data, size_t count, const enum gs_color_space *preferred_spaces)
{
const enum gs_color_space potential_spaces[] = {
GS_CS_SRGB,
GS_CS_SRGB_16F,
GS_CS_709_EXTENDED,
};
struct color_correction_filter_data_v2 *const filter = data;
const enum gs_color_space source_space = obs_source_get_color_space(
obs_filter_get_parent(filter->context),
OBS_COUNTOF(potential_spaces), potential_spaces);
return source_space;
}
/*
* So how does OBS keep track of all these plug-ins/filters? How does OBS know
* which function to call when it needs to update a setting? Or a source? Or
@ -741,4 +779,5 @@ struct obs_source_info color_filter_v2 = {
.update = color_correction_filter_update_v2,
.get_properties = color_correction_filter_properties_v2,
.get_defaults = color_correction_filter_defaults_v2,
.video_get_color_space = color_correction_filter_get_color_space,
};

View File

@ -30,6 +30,7 @@ Opacity="Opacity"
Contrast="Contrast"
Brightness="Brightness"
Gamma="Gamma"
SdrOnlyInfo="Info: Settings only apply to SDR video."
BrowsePath.Images="All Image Files"
BrowsePath.AllFiles="All Files"
KeyColorType="Key Color Type"