gdkpixbufoverlay: add "alpha" property to set alpha of overlay image

.. or turn the overlay off by setting alpha to 0.0
This commit is contained in:
Tim-Philipp Müller 2012-03-25 00:00:59 +00:00
parent 2de5d0d52f
commit e780771223
3 changed files with 33 additions and 7 deletions

View File

@ -55,7 +55,7 @@ AM_PROG_LIBTOOL
dnl *** required versions of GStreamer stuff *** dnl *** required versions of GStreamer stuff ***
GST_REQ=0.10.36 GST_REQ=0.10.36
GSTPB_REQ=0.10.36 GSTPB_REQ=0.10.36.1
dnl *** autotools stuff **** dnl *** autotools stuff ****

View File

@ -82,7 +82,8 @@ enum
PROP_RELATIVE_X, PROP_RELATIVE_X,
PROP_RELATIVE_Y, PROP_RELATIVE_Y,
PROP_OVERLAY_WIDTH, PROP_OVERLAY_WIDTH,
PROP_OVERLAY_HEIGHT PROP_OVERLAY_HEIGHT,
PROP_ALPHA
}; };
#define VIDEO_CAPS \ #define VIDEO_CAPS \
@ -188,6 +189,10 @@ gst_gdk_pixbuf_overlay_class_init (GstGdkPixbufOverlayClass * klass)
G_MAXINT, 0, G_MAXINT, 0,
GST_PARAM_CONTROLLABLE | GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE GST_PARAM_CONTROLLABLE | GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS)); | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, PROP_ALPHA,
g_param_spec_double ("alpha", "Alpha", "Global alpha of overlay image",
0.0, 1.0, 1.0, GST_PARAM_CONTROLLABLE | GST_PARAM_MUTABLE_PLAYING
| G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
GST_DEBUG_CATEGORY_INIT (gdkpixbufoverlay_debug, "gdkpixbufoverlay", 0, GST_DEBUG_CATEGORY_INIT (gdkpixbufoverlay_debug, "gdkpixbufoverlay", 0,
"debug category for gdkpixbufoverlay element"); "debug category for gdkpixbufoverlay element");
@ -205,6 +210,8 @@ gst_gdk_pixbuf_overlay_init (GstGdkPixbufOverlay * overlay,
overlay->overlay_width = 0; overlay->overlay_width = 0;
overlay->overlay_height = 0; overlay->overlay_height = 0;
overlay->alpha = 1.0;
} }
void void
@ -244,6 +251,10 @@ gst_gdk_pixbuf_overlay_set_property (GObject * object, guint property_id,
overlay->overlay_height = g_value_get_int (value); overlay->overlay_height = g_value_get_int (value);
overlay->update_composition = TRUE; overlay->update_composition = TRUE;
break; break;
case PROP_ALPHA:
overlay->alpha = g_value_get_double (value);
overlay->update_composition = TRUE;
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break; break;
@ -282,6 +293,9 @@ gst_gdk_pixbuf_overlay_get_property (GObject * object, guint property_id,
case PROP_OVERLAY_HEIGHT: case PROP_OVERLAY_HEIGHT:
g_value_set_int (value, overlay->overlay_height); g_value_set_int (value, overlay->overlay_height);
break; break;
case PROP_ALPHA:
g_value_set_double (value, overlay->alpha);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break; break;
@ -438,6 +452,14 @@ gst_gdk_pixbuf_overlay_update_composition (GstGdkPixbufOverlay * overlay)
GstVideoOverlayRectangle *rect; GstVideoOverlayRectangle *rect;
gint x, y, width, height; gint x, y, width, height;
if (overlay->comp) {
gst_video_overlay_composition_unref (overlay->comp);
overlay->comp = NULL;
}
if (overlay->alpha == 0.0)
return;
x = overlay->offset_x + (overlay->relative_x * overlay->pixels_width); x = overlay->offset_x + (overlay->relative_x * overlay->pixels_width);
y = overlay->offset_y + (overlay->relative_y * overlay->pixels_height); y = overlay->offset_y + (overlay->relative_y * overlay->pixels_height);
@ -455,8 +477,8 @@ gst_gdk_pixbuf_overlay_update_composition (GstGdkPixbufOverlay * overlay)
if (height == 0) if (height == 0)
height = overlay->pixels_height; height = overlay->pixels_height;
GST_DEBUG_OBJECT (overlay, "overlay image dimensions: %d x %d", GST_DEBUG_OBJECT (overlay, "overlay image dimensions: %d x %d, alpha=%.2f",
overlay->pixels_width, overlay->pixels_height); overlay->pixels_width, overlay->pixels_height, overlay->alpha);
GST_DEBUG_OBJECT (overlay, "properties: x,y: %d,%d (%g%%,%g%%) - WxH: %dx%d", GST_DEBUG_OBJECT (overlay, "properties: x,y: %d,%d (%g%%,%g%%) - WxH: %dx%d",
overlay->offset_x, overlay->offset_y, overlay->offset_x, overlay->offset_y,
overlay->relative_x * 100.0, overlay->relative_y * 100.0, overlay->relative_x * 100.0, overlay->relative_y * 100.0,
@ -468,11 +490,12 @@ gst_gdk_pixbuf_overlay_update_composition (GstGdkPixbufOverlay * overlay)
overlay->pixels_width, overlay->pixels_height, overlay->pixels_stride, overlay->pixels_width, overlay->pixels_height, overlay->pixels_stride,
x, y, width, height, GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE); x, y, width, height, GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
if (overlay->alpha != 1.0)
gst_video_overlay_rectangle_set_global_alpha (rect, overlay->alpha);
comp = gst_video_overlay_composition_new (rect); comp = gst_video_overlay_composition_new (rect);
gst_video_overlay_rectangle_unref (rect); gst_video_overlay_rectangle_unref (rect);
if (overlay->comp)
gst_video_overlay_composition_unref (overlay->comp);
overlay->comp = comp; overlay->comp = comp;
} }
@ -503,7 +526,8 @@ gst_gdk_pixbuf_overlay_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
GST_OBJECT_UNLOCK (overlay); GST_OBJECT_UNLOCK (overlay);
gst_video_overlay_composition_blend (overlay->comp, buf); if (overlay->comp != NULL)
gst_video_overlay_composition_blend (overlay->comp, buf);
return GST_FLOW_OK; return GST_FLOW_OK;
} }

View File

@ -63,6 +63,8 @@ struct _GstGdkPixbufOverlay
gint overlay_width; gint overlay_width;
gint overlay_height; gint overlay_height;
gdouble alpha;
/* the loaded image */ /* the loaded image */
GstBuffer * pixels; GstBuffer * pixels;
guint pixels_width; guint pixels_width;