summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorTim-Philipp Müller <tim@centricular.com>2014-11-29 13:53:03 +0000
committerTim-Philipp Müller <tim@centricular.com>2014-11-30 14:35:06 +0000
commit8c2d55d1e9daf30188e3a78eca6132703cb60a4d (patch)
tree2e22acc21ac5f9c1dca7f44669131f4e07bb4417 /ext
parent35f10e463064b2104572821582f1d1aa73f66333 (diff)
gdkpixbufoverlay: add "pixbuf" property
So we can set a GdkPixbuf directly instead of reading it from an image file on the file system.
Diffstat (limited to 'ext')
-rw-r--r--ext/gdk_pixbuf/gstgdkpixbufoverlay.c49
-rw-r--r--ext/gdk_pixbuf/gstgdkpixbufoverlay.h7
2 files changed, 48 insertions, 8 deletions
diff --git a/ext/gdk_pixbuf/gstgdkpixbufoverlay.c b/ext/gdk_pixbuf/gstgdkpixbufoverlay.c
index 6d3ba25f3..34b4f0a19 100644
--- a/ext/gdk_pixbuf/gstgdkpixbufoverlay.c
+++ b/ext/gdk_pixbuf/gstgdkpixbufoverlay.c
@@ -1,5 +1,5 @@
/* GStreamer GdkPixbuf overlay
- * Copyright (C) 2012 Tim-Philipp Müller <tim centricular net>
+ * Copyright (C) 2012-2014 Tim-Philipp Müller <tim centricular net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -73,11 +73,14 @@ static gboolean gst_gdk_pixbuf_overlay_set_info (GstVideoFilter * filter,
static gboolean
gst_gdk_pixbuf_overlay_load_image (GstGdkPixbufOverlay * overlay,
GError ** err);
+static void gst_gdk_pixbuf_overlay_set_pixbuf (GstGdkPixbufOverlay * overlay,
+ GdkPixbuf * pixbuf);
enum
{
PROP_0,
PROP_LOCATION,
+ PROP_PIXBUF,
PROP_OFFSET_X,
PROP_OFFSET_Y,
PROP_RELATIVE_X,
@@ -179,6 +182,17 @@ gst_gdk_pixbuf_overlay_class_init (GstGdkPixbufOverlayClass * klass)
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));
+ /**
+ * GstGdkPixbufOverlay:pixbuf:
+ *
+ * GdkPixbuf object to render.
+ *
+ * Since: 1.6
+ */
+ g_object_class_install_property (gobject_class, PROP_PIXBUF,
+ g_param_spec_object ("pixbuf", "Pixbuf", "GdkPixbuf object to render",
+ GDK_TYPE_PIXBUF, GST_PARAM_CONTROLLABLE | GST_PARAM_MUTABLE_PLAYING
+ | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&sink_template));
@@ -206,6 +220,8 @@ gst_gdk_pixbuf_overlay_init (GstGdkPixbufOverlay * overlay)
overlay->overlay_height = 0;
overlay->alpha = 1.0;
+
+ overlay->pixbuf = NULL;
}
void
@@ -226,8 +242,17 @@ gst_gdk_pixbuf_overlay_set_property (GObject * object, guint property_id,
err->message);
g_error_free (err);
}
+ break;
}
+ case PROP_PIXBUF:{
+ GdkPixbuf *pixbuf = g_value_get_object (value);
+
+ if (overlay->pixbuf != NULL)
+ g_object_unref (overlay->pixbuf);
+ overlay->pixbuf = g_object_ref (pixbuf);
+ gst_gdk_pixbuf_overlay_set_pixbuf (overlay, g_object_ref (pixbuf));
break;
+ }
case PROP_OFFSET_X:
overlay->offset_x = g_value_get_int (value);
overlay->update_composition = TRUE;
@@ -276,6 +301,9 @@ gst_gdk_pixbuf_overlay_get_property (GObject * object, guint property_id,
case PROP_LOCATION:
g_value_set_string (value, overlay->location);
break;
+ case PROP_PIXBUF:
+ g_value_set_object (value, overlay->pixbuf);
+ break;
case PROP_OFFSET_X:
g_value_set_int (value, overlay->offset_x);
break;
@@ -319,16 +347,26 @@ gst_gdk_pixbuf_overlay_finalize (GObject * object)
static gboolean
gst_gdk_pixbuf_overlay_load_image (GstGdkPixbufOverlay * overlay, GError ** err)
{
- GstVideoMeta *video_meta;
GdkPixbuf *pixbuf;
- guint8 *pixels, *p;
- gint width, height, stride, w, h, plane;
pixbuf = gdk_pixbuf_new_from_file (overlay->location, err);
if (pixbuf == NULL)
return FALSE;
+ gst_gdk_pixbuf_overlay_set_pixbuf (overlay, pixbuf);
+ return TRUE;
+}
+
+/* Takes ownership of pixbuf; call with OBJECT_LOCK */
+static void
+gst_gdk_pixbuf_overlay_set_pixbuf (GstGdkPixbufOverlay * overlay,
+ GdkPixbuf * pixbuf)
+{
+ GstVideoMeta *video_meta;
+ guint8 *pixels, *p;
+ gint width, height, stride, w, h, plane;
+
if (!gdk_pixbuf_get_has_alpha (pixbuf)) {
GdkPixbuf *alpha_pixbuf;
@@ -384,8 +422,7 @@ gst_gdk_pixbuf_overlay_load_image (GstGdkPixbufOverlay * overlay, GError ** err)
overlay->update_composition = TRUE;
- GST_INFO_OBJECT (overlay, "Loaded image, %d x %d", width, height);
- return TRUE;
+ GST_INFO_OBJECT (overlay, "Updated pixbuf, %d x %d", width, height);
}
static gboolean
diff --git a/ext/gdk_pixbuf/gstgdkpixbufoverlay.h b/ext/gdk_pixbuf/gstgdkpixbufoverlay.h
index 0e863df4a..2b7ab1eab 100644
--- a/ext/gdk_pixbuf/gstgdkpixbufoverlay.h
+++ b/ext/gdk_pixbuf/gstgdkpixbufoverlay.h
@@ -1,5 +1,5 @@
/* GStreamer GdkPixbuf overlay
- * Copyright (C) 2012 Tim-Philipp Müller <tim centricular net>
+ * Copyright (C) 2012-2014 Tim-Philipp Müller <tim centricular net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -49,6 +49,9 @@ struct _GstGdkPixbufOverlay
/* properties */
gchar * location;
+ /* pixbuf set via pixbuf property */
+ GdkPixbuf * pixbuf;
+
gint offset_x;
gint offset_y;
@@ -61,7 +64,7 @@ struct _GstGdkPixbufOverlay
gdouble alpha;
/* the loaded image, as BGRA/ARGB pixels, with GstVideoMeta */
- GstBuffer * pixels;
+ GstBuffer * pixels; /* OBJECT_LOCK */
GstVideoOverlayComposition * comp;