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: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1580>
This commit is contained in:
Víctor Manuel Jáquez Leal 2022-01-27 11:22:54 +01:00 committed by GStreamer Marge Bot
parent 673b742751
commit d86288904f

View file

@ -2160,6 +2160,21 @@ gst_va_vpp_colorbalance_list_channels (GstColorBalance * balance)
return self->channels; 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 static gboolean
_set_cb_val (GstVaVpp * self, const gchar * name, _set_cb_val (GstVaVpp * self, const gchar * name,
GstColorBalanceChannel * channel, gint value, gfloat * cb) 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)); GObjectClass *klass = G_OBJECT_CLASS (GST_VA_VPP_GET_CLASS (self));
GParamSpec *pspec; GParamSpec *pspec;
GParamSpecFloat *fpspec; GParamSpecFloat *fpspec;
gfloat new_value; gfloat new_value, max;
gboolean changed; gboolean changed;
pspec = g_object_class_find_property (klass, name); pspec = g_object_class_find_property (klass, name);
@ -2175,14 +2190,16 @@ _set_cb_val (GstVaVpp * self, const gchar * name,
return FALSE; return FALSE;
fpspec = G_PARAM_SPEC_FLOAT (pspec); 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; / (channel->max_value - channel->min_value) + fpspec->minimum;
GST_OBJECT_LOCK (self); GST_OBJECT_LOCK (self);
changed = new_value != *cb; changed = new_value != *cb;
*cb = new_value; *cb = new_value;
value = (*cb + fpspec->minimum) * (channel->max_value - channel->min_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); GST_OBJECT_UNLOCK (self);
if (changed) { 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)); GObjectClass *klass = G_OBJECT_CLASS (GST_VA_VPP_GET_CLASS (self));
GParamSpec *pspec; GParamSpec *pspec;
GParamSpecFloat *fpspec; GParamSpecFloat *fpspec;
gfloat max;
pspec = g_object_class_find_property (klass, name); pspec = g_object_class_find_property (klass, name);
if (!pspec) if (!pspec)
return FALSE; return FALSE;
fpspec = G_PARAM_SPEC_FLOAT (pspec); fpspec = G_PARAM_SPEC_FLOAT (pspec);
max = make_max_simmetrical (fpspec);
GST_OBJECT_LOCK (self); GST_OBJECT_LOCK (self);
*val = (*cb + fpspec->minimum) * (channel->max_value - channel->min_value) *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); GST_OBJECT_UNLOCK (self);
return TRUE; return TRUE;