summaryrefslogtreecommitdiff
path: root/gst-libs/gst
diff options
context:
space:
mode:
authorGwenole Beauchesne <gwenole.beauchesne@intel.com>2012-08-28 13:59:50 +0200
committerGwenole Beauchesne <gwenole.beauchesne@intel.com>2012-08-28 17:42:13 +0200
commitfafcf0e13ce75c0e0d12e935e5aac520687a0195 (patch)
tree7295f4eb4bd8a29319b340b6143c8155f369b300 /gst-libs/gst
parent4dad571526fa1bfdc39f2f91dadca81ffae94e02 (diff)
display: add color balance properties.
Add support for hue, saturation, brightness and contrast attributes.
Diffstat (limited to 'gst-libs/gst')
-rw-r--r--gst-libs/gst/vaapi/gstvaapidisplay.c165
-rw-r--r--gst-libs/gst/vaapi/gstvaapidisplay.h8
2 files changed, 173 insertions, 0 deletions
diff --git a/gst-libs/gst/vaapi/gstvaapidisplay.c b/gst-libs/gst/vaapi/gstvaapidisplay.c
index 5ae39d76..985c2811 100644
--- a/gst-libs/gst/vaapi/gstvaapidisplay.c
+++ b/gst-libs/gst/vaapi/gstvaapidisplay.c
@@ -65,6 +65,10 @@ enum {
PROP_HEIGHT,
PROP_RENDER_MODE,
PROP_ROTATION,
+ PROP_HUE,
+ PROP_SATURATION,
+ PROP_BRIGHTNESS,
+ PROP_CONTRAST,
N_PROPERTIES
};
@@ -79,6 +83,12 @@ get_attribute(GstVaapiDisplay *display, VADisplayAttribType type, gint *value);
static gboolean
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 *
get_display_cache(void)
{
@@ -361,6 +371,12 @@ find_property_by_type(GArray *properties, VADisplayAttribType type)
}
#endif
+static inline const GstVaapiProperty *
+find_property_by_pspec(GstVaapiDisplay *display, GParamSpec *pspec)
+{
+ return find_property(display->priv->properties, pspec->name);
+}
+
static void
gst_vaapi_display_calculate_pixel_aspect_ratio(GstVaapiDisplay *display)
{
@@ -608,6 +624,18 @@ gst_vaapi_display_create(GstVaapiDisplay *display)
case VADisplayAttribRotation:
prop.name = GST_VAAPI_DISPLAY_PROP_ROTATION;
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:
prop.name = NULL;
break;
@@ -732,6 +760,12 @@ gst_vaapi_display_set_property(
case PROP_ROTATION:
gst_vaapi_display_set_rotation(display, g_value_get_enum(value));
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:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
@@ -771,6 +805,16 @@ gst_vaapi_display_get_property(
case PROP_ROTATION:
g_value_set_enum(value, gst_vaapi_display_get_rotation(display));
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:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
@@ -864,6 +908,58 @@ gst_vaapi_display_class_init(GstVaapiDisplayClass *klass)
DEFAULT_ROTATION,
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);
}
@@ -1539,3 +1635,72 @@ gst_vaapi_display_set_rotation(
g_object_notify_by_pspec(G_OBJECT(display), g_properties[PROP_ROTATION]);
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;
+}
diff --git a/gst-libs/gst/vaapi/gstvaapidisplay.h b/gst-libs/gst/vaapi/gstvaapidisplay.h
index a855aee5..56ca042d 100644
--- a/gst-libs/gst/vaapi/gstvaapidisplay.h
+++ b/gst-libs/gst/vaapi/gstvaapidisplay.h
@@ -100,9 +100,17 @@ struct _GstVaapiDisplayInfo {
* GstVaapiDisplayProperties:
* @GST_VAAPI_DISPLAY_PROP_RENDER_MODE: rendering mode (#GstVaapiRenderMode).
* @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_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: