From 1e17414e8fe491bd67f62ef8cfb9674940d2c997 Mon Sep 17 00:00:00 2001 From: Cephas Reis Date: Tue, 3 Jan 2017 18:36:54 -0600 Subject: [PATCH] obs-filters.c: Fix color correction filter saturation The Saturation option was unbalanced, giving more weight to the color red and a TON more weight to the color blue. This patch balances the colors to provide a more even increase in saturation across the RGB channels. Closes jp9000/obs-studio#739 --- plugins/obs-filters/color-correction-filter.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/plugins/obs-filters/color-correction-filter.c b/plugins/obs-filters/color-correction-filter.c index 4d73075fb..b72927cb4 100644 --- a/plugins/obs-filters/color-correction-filter.c +++ b/plugins/obs-filters/color-correction-filter.c @@ -71,6 +71,10 @@ struct color_correction_filter_data { }; const static float root3 = 0.57735f; +const static float red_weight = 0.299f; +const static float green_weight = 0.587f; +const static float blue_weight = 0.114f; + /* * As the functions' namesake, this provides the internal name of your Filter, @@ -130,15 +134,19 @@ static void color_correction_filter_update(void *data, obs_data_t *settings) SETTING_SATURATION) + 1.0f; /* Factor in the selected color weights. */ - float one_minus_sat = (1.0f - filter->saturation) / 3.0f; - float sat_val = one_minus_sat + filter->saturation; + float one_minus_sat_red = (1.0f - filter->saturation) * red_weight; + float one_minus_sat_green = (1.0f - filter->saturation) * green_weight; + float one_minus_sat_blue = (1.0f - filter->saturation) * blue_weight; + float sat_val_red = one_minus_sat_red + filter->saturation; + float sat_val_green = one_minus_sat_green + filter->saturation; + float sat_val_blue = one_minus_sat_blue + filter->saturation; /* Now we build our Saturation matrix. */ filter->sat_matrix = (struct matrix4) { - sat_val, one_minus_sat, one_minus_sat, 0.0f, - one_minus_sat, sat_val, one_minus_sat, 0.0f, - one_minus_sat, one_minus_sat, sat_val, 0.0f, + sat_val_red, one_minus_sat_red, one_minus_sat_red, 0.0f, + one_minus_sat_green, sat_val_green, one_minus_sat_green, 0.0f, + one_minus_sat_blue, one_minus_sat_blue, sat_val_blue, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f };