From d86288904f381b0f95a0eb89a48179eac89fdd8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Manuel=20J=C3=A1quez=20Leal?= Date: Thu, 27 Jan 2022 11:22:54 +0100 Subject: [PATCH] vapostproc: Make cb max values symmetrical to their min values. Intel drivers expose some colorbalance's maximum values much more bigger than their minimum values, given their middle values (default value). This means, in practice, that the real middle point between the maximum and minimum values implies a major change in the color balance, which is not expected by the GStreamer color balance logic. This patch makes the given maximum value symmetrical to the minimum value, given the middle one (default value). Part-of: --- subprojects/gst-plugins-bad/sys/va/gstvavpp.c | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/subprojects/gst-plugins-bad/sys/va/gstvavpp.c b/subprojects/gst-plugins-bad/sys/va/gstvavpp.c index d3ff5ea120..be0453ef6b 100644 --- a/subprojects/gst-plugins-bad/sys/va/gstvavpp.c +++ b/subprojects/gst-plugins-bad/sys/va/gstvavpp.c @@ -2160,6 +2160,21 @@ gst_va_vpp_colorbalance_list_channels (GstColorBalance * balance) return self->channels; } +/* This assumes --as happens with intel drivers-- that max values are + * bigger than the simmetrical values of min values */ +static float +make_max_simmetrical (GParamSpecFloat * fpspec) +{ + gfloat max; + + if (fpspec->default_value == 0) + max = -fpspec->minimum; + else + max = fpspec->default_value + ABS (fpspec->minimum - fpspec->default_value); + + return MIN (max, fpspec->maximum); +} + static gboolean _set_cb_val (GstVaVpp * self, const gchar * name, GstColorBalanceChannel * channel, gint value, gfloat * cb) @@ -2167,7 +2182,7 @@ _set_cb_val (GstVaVpp * self, const gchar * name, GObjectClass *klass = G_OBJECT_CLASS (GST_VA_VPP_GET_CLASS (self)); GParamSpec *pspec; GParamSpecFloat *fpspec; - gfloat new_value; + gfloat new_value, max; gboolean changed; pspec = g_object_class_find_property (klass, name); @@ -2175,14 +2190,16 @@ _set_cb_val (GstVaVpp * self, const gchar * name, return FALSE; fpspec = G_PARAM_SPEC_FLOAT (pspec); - new_value = (value - channel->min_value) * (fpspec->maximum - fpspec->minimum) + max = make_max_simmetrical (fpspec); + + new_value = (value - channel->min_value) * (max - fpspec->minimum) / (channel->max_value - channel->min_value) + fpspec->minimum; GST_OBJECT_LOCK (self); changed = new_value != *cb; *cb = new_value; value = (*cb + fpspec->minimum) * (channel->max_value - channel->min_value) - / (fpspec->maximum - fpspec->minimum) + channel->min_value; + / (max - fpspec->minimum) + channel->min_value; GST_OBJECT_UNLOCK (self); if (changed) { @@ -2217,16 +2234,18 @@ _get_cb_val (GstVaVpp * self, const gchar * name, GObjectClass *klass = G_OBJECT_CLASS (GST_VA_VPP_GET_CLASS (self)); GParamSpec *pspec; GParamSpecFloat *fpspec; + gfloat max; pspec = g_object_class_find_property (klass, name); if (!pspec) return FALSE; fpspec = G_PARAM_SPEC_FLOAT (pspec); + max = make_max_simmetrical (fpspec); GST_OBJECT_LOCK (self); *val = (*cb + fpspec->minimum) * (channel->max_value - channel->min_value) - / (fpspec->maximum - fpspec->minimum) + channel->min_value; + / (max - fpspec->minimum) + channel->min_value; GST_OBJECT_UNLOCK (self); return TRUE;