mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-06-07 16:08:51 +00:00
display: add color balance properties.
Add support for hue, saturation, brightness and contrast attributes.
This commit is contained in:
parent
4dad571526
commit
fafcf0e13c
2 changed files with 173 additions and 0 deletions
|
@ -65,6 +65,10 @@ enum {
|
||||||
PROP_HEIGHT,
|
PROP_HEIGHT,
|
||||||
PROP_RENDER_MODE,
|
PROP_RENDER_MODE,
|
||||||
PROP_ROTATION,
|
PROP_ROTATION,
|
||||||
|
PROP_HUE,
|
||||||
|
PROP_SATURATION,
|
||||||
|
PROP_BRIGHTNESS,
|
||||||
|
PROP_CONTRAST,
|
||||||
|
|
||||||
N_PROPERTIES
|
N_PROPERTIES
|
||||||
};
|
};
|
||||||
|
@ -79,6 +83,12 @@ get_attribute(GstVaapiDisplay *display, VADisplayAttribType type, gint *value);
|
||||||
static gboolean
|
static gboolean
|
||||||
set_attribute(GstVaapiDisplay *display, VADisplayAttribType type, gint value);
|
set_attribute(GstVaapiDisplay *display, VADisplayAttribType type, gint value);
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
get_color_balance(GstVaapiDisplay *display, guint prop_id, gfloat *v);
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
set_color_balance(GstVaapiDisplay *display, guint prop_id, gfloat v);
|
||||||
|
|
||||||
static inline GstVaapiDisplayCache *
|
static inline GstVaapiDisplayCache *
|
||||||
get_display_cache(void)
|
get_display_cache(void)
|
||||||
{
|
{
|
||||||
|
@ -361,6 +371,12 @@ find_property_by_type(GArray *properties, VADisplayAttribType type)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static inline const GstVaapiProperty *
|
||||||
|
find_property_by_pspec(GstVaapiDisplay *display, GParamSpec *pspec)
|
||||||
|
{
|
||||||
|
return find_property(display->priv->properties, pspec->name);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_vaapi_display_calculate_pixel_aspect_ratio(GstVaapiDisplay *display)
|
gst_vaapi_display_calculate_pixel_aspect_ratio(GstVaapiDisplay *display)
|
||||||
{
|
{
|
||||||
|
@ -608,6 +624,18 @@ gst_vaapi_display_create(GstVaapiDisplay *display)
|
||||||
case VADisplayAttribRotation:
|
case VADisplayAttribRotation:
|
||||||
prop.name = GST_VAAPI_DISPLAY_PROP_ROTATION;
|
prop.name = GST_VAAPI_DISPLAY_PROP_ROTATION;
|
||||||
break;
|
break;
|
||||||
|
case VADisplayAttribHue:
|
||||||
|
prop.name = GST_VAAPI_DISPLAY_PROP_HUE;
|
||||||
|
break;
|
||||||
|
case VADisplayAttribSaturation:
|
||||||
|
prop.name = GST_VAAPI_DISPLAY_PROP_SATURATION;
|
||||||
|
break;
|
||||||
|
case VADisplayAttribBrightness:
|
||||||
|
prop.name = GST_VAAPI_DISPLAY_PROP_BRIGHTNESS;
|
||||||
|
break;
|
||||||
|
case VADisplayAttribContrast:
|
||||||
|
prop.name = GST_VAAPI_DISPLAY_PROP_CONTRAST;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
prop.name = NULL;
|
prop.name = NULL;
|
||||||
break;
|
break;
|
||||||
|
@ -732,6 +760,12 @@ gst_vaapi_display_set_property(
|
||||||
case PROP_ROTATION:
|
case PROP_ROTATION:
|
||||||
gst_vaapi_display_set_rotation(display, g_value_get_enum(value));
|
gst_vaapi_display_set_rotation(display, g_value_get_enum(value));
|
||||||
break;
|
break;
|
||||||
|
case PROP_HUE:
|
||||||
|
case PROP_SATURATION:
|
||||||
|
case PROP_BRIGHTNESS:
|
||||||
|
case PROP_CONTRAST:
|
||||||
|
set_color_balance(display, prop_id, g_value_get_float(value));
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||||
break;
|
break;
|
||||||
|
@ -771,6 +805,16 @@ gst_vaapi_display_get_property(
|
||||||
case PROP_ROTATION:
|
case PROP_ROTATION:
|
||||||
g_value_set_enum(value, gst_vaapi_display_get_rotation(display));
|
g_value_set_enum(value, gst_vaapi_display_get_rotation(display));
|
||||||
break;
|
break;
|
||||||
|
case PROP_HUE:
|
||||||
|
case PROP_SATURATION:
|
||||||
|
case PROP_BRIGHTNESS:
|
||||||
|
case PROP_CONTRAST: {
|
||||||
|
gfloat v;
|
||||||
|
if (!get_color_balance(display, prop_id, &v))
|
||||||
|
v = G_PARAM_SPEC_FLOAT(pspec)->default_value;
|
||||||
|
g_value_set_float(value, v);
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||||
break;
|
break;
|
||||||
|
@ -864,6 +908,58 @@ gst_vaapi_display_class_init(GstVaapiDisplayClass *klass)
|
||||||
DEFAULT_ROTATION,
|
DEFAULT_ROTATION,
|
||||||
G_PARAM_READWRITE);
|
G_PARAM_READWRITE);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GstVaapiDisplay:hue:
|
||||||
|
*
|
||||||
|
* The VA display hue, expressed as a float value. Range is -180.0
|
||||||
|
* to 180.0. Default value is 0.0 and represents no modification.
|
||||||
|
*/
|
||||||
|
g_properties[PROP_HUE] =
|
||||||
|
g_param_spec_float(GST_VAAPI_DISPLAY_PROP_HUE,
|
||||||
|
"hue",
|
||||||
|
"The display hue value",
|
||||||
|
-180.0, 180.0, 0.0,
|
||||||
|
G_PARAM_READWRITE);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GstVaapiDisplay:saturation:
|
||||||
|
*
|
||||||
|
* The VA display saturation, expressed as a float value. Range is
|
||||||
|
* 0.0 to 2.0. Default value is 1.0 and represents no modification.
|
||||||
|
*/
|
||||||
|
g_properties[PROP_SATURATION] =
|
||||||
|
g_param_spec_float(GST_VAAPI_DISPLAY_PROP_SATURATION,
|
||||||
|
"saturation",
|
||||||
|
"The display saturation value",
|
||||||
|
0.0, 2.0, 1.0,
|
||||||
|
G_PARAM_READWRITE);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GstVaapiDisplay:brightness:
|
||||||
|
*
|
||||||
|
* The VA display brightness, expressed as a float value. Range is
|
||||||
|
* -1.0 to 1.0. Default value is 0.0 and represents no modification.
|
||||||
|
*/
|
||||||
|
g_properties[PROP_BRIGHTNESS] =
|
||||||
|
g_param_spec_float(GST_VAAPI_DISPLAY_PROP_BRIGHTNESS,
|
||||||
|
"brightness",
|
||||||
|
"The display brightness value",
|
||||||
|
-1.0, 1.0, 0.0,
|
||||||
|
G_PARAM_READWRITE);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GstVaapiDisplay:contrast:
|
||||||
|
*
|
||||||
|
* The VA display contrast, expressed as a float value. Range is
|
||||||
|
* 0.0 to 2.0. Default value is 1.0 and represents no modification.
|
||||||
|
*/
|
||||||
|
g_properties[PROP_CONTRAST] =
|
||||||
|
g_param_spec_float(GST_VAAPI_DISPLAY_PROP_CONTRAST,
|
||||||
|
"contrast",
|
||||||
|
"The display contrast value",
|
||||||
|
0.0, 2.0, 1.0,
|
||||||
|
G_PARAM_READWRITE);
|
||||||
|
|
||||||
g_object_class_install_properties(object_class, N_PROPERTIES, g_properties);
|
g_object_class_install_properties(object_class, N_PROPERTIES, g_properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1539,3 +1635,72 @@ gst_vaapi_display_set_rotation(
|
||||||
g_object_notify_by_pspec(G_OBJECT(display), g_properties[PROP_ROTATION]);
|
g_object_notify_by_pspec(G_OBJECT(display), g_properties[PROP_ROTATION]);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Get color balance attributes */
|
||||||
|
static gboolean
|
||||||
|
get_color_balance(GstVaapiDisplay *display, guint prop_id, gfloat *v)
|
||||||
|
{
|
||||||
|
GParamSpecFloat * const pspec = G_PARAM_SPEC_FLOAT(g_properties[prop_id]);
|
||||||
|
const GstVaapiProperty *prop;
|
||||||
|
const VADisplayAttribute *attr;
|
||||||
|
gfloat out_value;
|
||||||
|
gint value;
|
||||||
|
|
||||||
|
if (!pspec)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
prop = find_property_by_pspec(display, &pspec->parent_instance);
|
||||||
|
if (!prop)
|
||||||
|
return FALSE;
|
||||||
|
attr = &prop->attribute;
|
||||||
|
|
||||||
|
if (!get_attribute(display, attr->type, &value))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
/* Scale wrt. the medium ("default") value */
|
||||||
|
out_value = pspec->default_value;
|
||||||
|
if (value > attr->value)
|
||||||
|
out_value += ((gfloat)(value - attr->value) /
|
||||||
|
(attr->max_value - attr->value) *
|
||||||
|
(pspec->maximum - pspec->default_value));
|
||||||
|
else if (value < attr->value)
|
||||||
|
out_value -= ((gfloat)(attr->value - value) /
|
||||||
|
(attr->value - attr->min_value) *
|
||||||
|
(pspec->default_value - pspec->minimum));
|
||||||
|
*v = out_value;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set color balance attribute */
|
||||||
|
static gboolean
|
||||||
|
set_color_balance(GstVaapiDisplay *display, guint prop_id, gfloat v)
|
||||||
|
{
|
||||||
|
GParamSpecFloat * const pspec = G_PARAM_SPEC_FLOAT(g_properties[prop_id]);
|
||||||
|
const GstVaapiProperty *prop;
|
||||||
|
const VADisplayAttribute *attr;
|
||||||
|
gint value;
|
||||||
|
|
||||||
|
if (!pspec)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
prop = find_property_by_pspec(display, &pspec->parent_instance);
|
||||||
|
if (!prop)
|
||||||
|
return FALSE;
|
||||||
|
attr = &prop->attribute;
|
||||||
|
|
||||||
|
/* Scale wrt. the medium ("default") value */
|
||||||
|
value = attr->value;
|
||||||
|
if (v > pspec->default_value)
|
||||||
|
value += ((v - pspec->default_value) /
|
||||||
|
(pspec->maximum - pspec->default_value) *
|
||||||
|
(attr->max_value - attr->value));
|
||||||
|
else if (v < pspec->default_value)
|
||||||
|
value -= ((pspec->default_value - v) /
|
||||||
|
(pspec->default_value - pspec->minimum) *
|
||||||
|
(attr->value - attr->min_value));
|
||||||
|
if (!set_attribute(display, attr->type, value))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
g_object_notify_by_pspec(G_OBJECT(display), g_properties[prop_id]);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
|
@ -100,9 +100,17 @@ struct _GstVaapiDisplayInfo {
|
||||||
* GstVaapiDisplayProperties:
|
* GstVaapiDisplayProperties:
|
||||||
* @GST_VAAPI_DISPLAY_PROP_RENDER_MODE: rendering mode (#GstVaapiRenderMode).
|
* @GST_VAAPI_DISPLAY_PROP_RENDER_MODE: rendering mode (#GstVaapiRenderMode).
|
||||||
* @GST_VAAPI_DISPLAY_PROP_ROTATION: rotation angle (#GstVaapiRotation).
|
* @GST_VAAPI_DISPLAY_PROP_ROTATION: rotation angle (#GstVaapiRotation).
|
||||||
|
* @GST_VAAPI_DISPLAY_PROP_HUE: hue (float: [-180 ; 180], default: 0).
|
||||||
|
* @GST_VAAPI_DISPLAY_PROP_SATURATION: saturation (float: [0 ; 2], default: 1).
|
||||||
|
* @GST_VAAPI_DISPLAY_PROP_BRIGHTNESS: brightness (float: [-1 ; 1], default: 0).
|
||||||
|
* @GST_VAAPI_DISPLAY_PROP_CONTRAST: contrast (float: [0 ; 2], default: 1).
|
||||||
*/
|
*/
|
||||||
#define GST_VAAPI_DISPLAY_PROP_RENDER_MODE "render-mode"
|
#define GST_VAAPI_DISPLAY_PROP_RENDER_MODE "render-mode"
|
||||||
#define GST_VAAPI_DISPLAY_PROP_ROTATION "rotation"
|
#define GST_VAAPI_DISPLAY_PROP_ROTATION "rotation"
|
||||||
|
#define GST_VAAPI_DISPLAY_PROP_HUE "hue"
|
||||||
|
#define GST_VAAPI_DISPLAY_PROP_SATURATION "saturation"
|
||||||
|
#define GST_VAAPI_DISPLAY_PROP_BRIGHTNESS "brightness"
|
||||||
|
#define GST_VAAPI_DISPLAY_PROP_CONTRAST "contrast"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GstVaapiDisplay:
|
* GstVaapiDisplay:
|
||||||
|
|
Loading…
Reference in a new issue