1 /* GStreamer GdkPixbuf overlay
2 * Copyright (C) 2012-2014 Tim-Philipp Müller <tim centricular net>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Suite 500,
17 * Boston, MA 02110-1335, USA.
21 * SECTION:element-gdkpixbufoverlay
22 * @title: gdkpixbufoverlay
24 * The gdkpixbufoverlay element overlays a provided GdkPixbuf or an image
25 * loaded from file onto a video stream.
27 * Changing the positioning or overlay width and height properties at runtime
28 * is supported, but it might be prudent to to protect the property setting
29 * code with GST_BASE_TRANSFORM_LOCK and GST_BASE_TRANSFORM_UNLOCK, as
30 * g_object_set() is not atomic for multiple properties passed in one go.
32 * Changing the image at runtime is supported.
34 * ## Example launch line
36 * gst-launch-1.0 -v videotestsrc ! gdkpixbufoverlay location=image.png ! autovideosink
38 * Overlays the image in image.png onto the test video picture produced by
48 #include "gstgdkpixbufoverlay.h"
50 #include "gstgdkpixbufelements.h"
51 #include <gst/video/gstvideometa.h>
53 GST_DEBUG_CATEGORY_STATIC (gdkpixbufoverlay_debug);
54 #define GST_CAT_DEFAULT gdkpixbufoverlay_debug
56 static void gst_gdk_pixbuf_overlay_set_property (GObject * object,
57 guint property_id, const GValue * value, GParamSpec * pspec);
58 static void gst_gdk_pixbuf_overlay_get_property (GObject * object,
59 guint property_id, GValue * value, GParamSpec * pspec);
60 static void gst_gdk_pixbuf_overlay_finalize (GObject * object);
62 static gboolean gst_gdk_pixbuf_overlay_start (GstBaseTransform * trans);
63 static gboolean gst_gdk_pixbuf_overlay_stop (GstBaseTransform * trans);
65 gst_gdk_pixbuf_overlay_transform_frame_ip (GstVideoFilter * filter,
66 GstVideoFrame * frame);
67 static void gst_gdk_pixbuf_overlay_before_transform (GstBaseTransform * trans,
69 static gboolean gst_gdk_pixbuf_overlay_set_info (GstVideoFilter * filter,
70 GstCaps * incaps, GstVideoInfo * in_info, GstCaps * outcaps,
71 GstVideoInfo * out_info);
73 gst_gdk_pixbuf_overlay_load_image (GstGdkPixbufOverlay * overlay,
75 static void gst_gdk_pixbuf_overlay_set_pixbuf (GstGdkPixbufOverlay * overlay,
83 PROP_POSITIONING_MODE,
95 /* FIXME 2.0: change to absolute positioning */
96 #define DEFAULT_POSITIONING_MODE \
97 GST_GDK_PIXBUF_POSITIONING_PIXELS_RELATIVE_TO_EDGES
99 static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
102 GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE
103 (GST_VIDEO_OVERLAY_COMPOSITION_BLEND_FORMATS))
106 static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
109 GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE
110 (GST_VIDEO_OVERLAY_COMPOSITION_BLEND_FORMATS))
113 G_DEFINE_TYPE (GstGdkPixbufOverlay, gst_gdk_pixbuf_overlay,
114 GST_TYPE_VIDEO_FILTER);
115 GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (gdkpixbufoverlay, "gdkpixbufoverlay",
116 GST_RANK_NONE, GST_TYPE_GDK_PIXBUF_OVERLAY,
117 gdk_pixbuf_element_init (plugin));
119 #define GST_TYPE_GDK_PIXBUF_POSITIONING_MODE \
120 (gst_gdk_pixbuf_positioning_mode_get_type())
123 gst_gdk_pixbuf_positioning_mode_get_type (void)
125 static const GEnumValue pos_modes[] = {
126 {GST_GDK_PIXBUF_POSITIONING_PIXELS_RELATIVE_TO_EDGES,
127 "pixels-relative-to-edges", "pixels-relative-to-edges"},
128 {GST_GDK_PIXBUF_POSITIONING_PIXELS_ABSOLUTE, "pixels-absolute",
133 static GType type; /* 0 */
136 type = g_enum_register_static ("GstGdkPixbufPositioningMode", pos_modes);
143 gst_gdk_pixbuf_overlay_class_init (GstGdkPixbufOverlayClass * klass)
145 GstVideoFilterClass *videofilter_class = GST_VIDEO_FILTER_CLASS (klass);
146 GstBaseTransformClass *basetrans_class = GST_BASE_TRANSFORM_CLASS (klass);
147 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
148 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
150 gobject_class->set_property = gst_gdk_pixbuf_overlay_set_property;
151 gobject_class->get_property = gst_gdk_pixbuf_overlay_get_property;
152 gobject_class->finalize = gst_gdk_pixbuf_overlay_finalize;
154 basetrans_class->start = GST_DEBUG_FUNCPTR (gst_gdk_pixbuf_overlay_start);
155 basetrans_class->stop = GST_DEBUG_FUNCPTR (gst_gdk_pixbuf_overlay_stop);
157 basetrans_class->before_transform =
158 GST_DEBUG_FUNCPTR (gst_gdk_pixbuf_overlay_before_transform);
160 videofilter_class->set_info =
161 GST_DEBUG_FUNCPTR (gst_gdk_pixbuf_overlay_set_info);
162 videofilter_class->transform_frame_ip =
163 GST_DEBUG_FUNCPTR (gst_gdk_pixbuf_overlay_transform_frame_ip);
165 g_object_class_install_property (gobject_class, PROP_LOCATION,
166 g_param_spec_string ("location", "location",
167 "Location of image file to overlay", NULL, GST_PARAM_CONTROLLABLE
168 | GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE
169 | G_PARAM_STATIC_STRINGS));
170 g_object_class_install_property (gobject_class, PROP_OFFSET_X,
171 g_param_spec_int ("offset-x", "X Offset",
172 "For positive value, horizontal offset of overlay image in pixels from"
173 " left of video image. For negative value, horizontal offset of overlay"
174 " image in pixels from right of video image", G_MININT, G_MAXINT, 0,
175 GST_PARAM_CONTROLLABLE | GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE
176 | G_PARAM_STATIC_STRINGS));
177 g_object_class_install_property (gobject_class, PROP_OFFSET_Y,
178 g_param_spec_int ("offset-y", "Y Offset",
179 "For positive value, vertical offset of overlay image in pixels from"
180 " top of video image. For negative value, vertical offset of overlay"
181 " image in pixels from bottom of video image", G_MININT, G_MAXINT, 0,
182 GST_PARAM_CONTROLLABLE | GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE
183 | G_PARAM_STATIC_STRINGS));
184 g_object_class_install_property (gobject_class, PROP_RELATIVE_X,
185 g_param_spec_double ("relative-x", "Relative X Offset",
186 "Horizontal offset of overlay image in fractions of video image "
187 "width, from top-left corner of video image"
188 " (in relative positioning)", -1.0, 1.0, 0.0,
189 GST_PARAM_CONTROLLABLE | GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE
190 | G_PARAM_STATIC_STRINGS));
191 g_object_class_install_property (gobject_class, PROP_RELATIVE_Y,
192 g_param_spec_double ("relative-y", "Relative Y Offset",
193 "Vertical offset of overlay image in fractions of video image "
194 "height, from top-left corner of video image"
195 " (in relative positioning)", -1.0, 1.0, 0.0,
196 GST_PARAM_CONTROLLABLE | GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE
197 | G_PARAM_STATIC_STRINGS));
198 g_object_class_install_property (gobject_class, PROP_OVERLAY_WIDTH,
199 g_param_spec_int ("overlay-width", "Overlay Width",
200 "Width of overlay image in pixels (0 = same as overlay image)", 0,
202 GST_PARAM_CONTROLLABLE | GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE
203 | G_PARAM_STATIC_STRINGS));
204 g_object_class_install_property (gobject_class, PROP_OVERLAY_HEIGHT,
205 g_param_spec_int ("overlay-height", "Overlay Height",
206 "Height of overlay image in pixels (0 = same as overlay image)", 0,
208 GST_PARAM_CONTROLLABLE | GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE
209 | G_PARAM_STATIC_STRINGS));
210 g_object_class_install_property (gobject_class, PROP_ALPHA,
211 g_param_spec_double ("alpha", "Alpha", "Global alpha of overlay image",
212 0.0, 1.0, 1.0, GST_PARAM_CONTROLLABLE | GST_PARAM_MUTABLE_PLAYING
213 | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
215 * GstGdkPixbufOverlay:pixbuf:
217 * GdkPixbuf object to render.
221 g_object_class_install_property (gobject_class, PROP_PIXBUF,
222 g_param_spec_object ("pixbuf", "Pixbuf", "GdkPixbuf object to render",
223 GDK_TYPE_PIXBUF, GST_PARAM_CONTROLLABLE | GST_PARAM_MUTABLE_PLAYING
224 | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
226 * GstGdkPixbufOverlay:positioning-mode:
228 * Positioning mode of offset-x and offset-y properties. Determines how
229 * negative x/y offsets will be interpreted. By default negative values
230 * are for positioning relative to the right/bottom edge of the video
231 * image, but you can use this property to select absolute positioning
232 * relative to a (0, 0) origin in the top-left corner. That way negative
233 * offsets will be to the left/above the video image, which allows you to
234 * smoothly slide logos into and out of the frame if desired.
238 g_object_class_install_property (gobject_class, PROP_POSITIONING_MODE,
239 g_param_spec_enum ("positioning-mode", "Positioning mode",
240 "Positioning mode of offset-x and offset-y properties",
241 GST_TYPE_GDK_PIXBUF_POSITIONING_MODE, DEFAULT_POSITIONING_MODE,
242 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
244 /* FIXME the following actually act as a RELATIVE_X/RELATIVE_Y,
245 * but those were already slightly mutated/abused with ABSOLUTE positioning,
246 * so let's keep that and follow suit
247 * Suffice it to say all that could do with cleanup (2.0 ??) */
249 * GstGdkPixbufOverlay:coef-x:
251 * In absolute positioning mode, the x coordinate of overlay image's
252 * top-left corner is now given by
253 * offset-x + (relative-x * overlay_width) + (coef-x * video_width).
254 * This allows to align the image absolutely and relatively
255 * to any edge or center position.
259 g_object_class_install_property (gobject_class, PROP_COEF_X,
260 g_param_spec_double ("coef-x", "Relative X Offset",
261 "Horizontal offset of overlay image in fractions of video image "
262 "width, from top-left corner of video image (absolute positioning)",
263 -1.0, 1.0, 0.0, GST_PARAM_CONTROLLABLE | GST_PARAM_MUTABLE_PLAYING
264 | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
266 * GstGdkPixbufOverlay:coef-y:
268 * In absolute positioning mode, the y coordinate of overlay image's
269 * top-left corner is now given by
270 * offset-y + (relative-y * overlay_height) + (coef-y * video_height).
271 * This allows to align the image absolutely and relatively
272 * to any edge or center position.
276 g_object_class_install_property (gobject_class, PROP_COEF_Y,
277 g_param_spec_double ("coef-y", "Relative Y Offset",
278 "Vertical offset of overlay image in fractions of video image "
279 "height, from top-left corner of video image (absolute positioning)",
280 -1.0, 1.0, 0.0, GST_PARAM_CONTROLLABLE | GST_PARAM_MUTABLE_PLAYING
281 | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
283 gst_element_class_add_static_pad_template (element_class, &sink_template);
284 gst_element_class_add_static_pad_template (element_class, &src_template);
286 gst_element_class_set_static_metadata (element_class,
287 "GdkPixbuf Overlay", "Filter/Effect/Video",
288 "Overlay an image onto a video stream",
289 "Tim-Philipp Müller <tim centricular net>");
290 GST_DEBUG_CATEGORY_INIT (gdkpixbufoverlay_debug, "gdkpixbufoverlay", 0,
291 "debug category for gdkpixbufoverlay element");
293 gst_type_mark_as_plugin_api (GST_TYPE_GDK_PIXBUF_POSITIONING_MODE, 0);
297 gst_gdk_pixbuf_overlay_init (GstGdkPixbufOverlay * overlay)
299 overlay->offset_x = 0;
300 overlay->offset_y = 0;
302 overlay->relative_x = 0.0;
303 overlay->relative_y = 0.0;
305 overlay->coef_x = 0.0;
306 overlay->coef_y = 0.0;
308 overlay->positioning_mode = DEFAULT_POSITIONING_MODE;
310 overlay->overlay_width = 0;
311 overlay->overlay_height = 0;
313 overlay->alpha = 1.0;
315 overlay->pixbuf = NULL;
319 gst_gdk_pixbuf_overlay_set_property (GObject * object, guint property_id,
320 const GValue * value, GParamSpec * pspec)
322 GstGdkPixbufOverlay *overlay = GST_GDK_PIXBUF_OVERLAY (object);
324 GST_OBJECT_LOCK (overlay);
326 switch (property_id) {
329 g_free (overlay->location);
330 overlay->location = g_value_dup_string (value);
331 if (!gst_gdk_pixbuf_overlay_load_image (overlay, &err)) {
332 GST_ERROR_OBJECT (overlay, "Could not load overlay image: %s",
339 GdkPixbuf *pixbuf = g_value_get_object (value);
341 if (overlay->pixbuf != NULL)
342 g_object_unref (overlay->pixbuf);
344 overlay->pixbuf = g_object_ref (pixbuf);
345 gst_gdk_pixbuf_overlay_set_pixbuf (overlay, g_object_ref (pixbuf));
347 overlay->pixbuf = NULL;
348 gst_buffer_replace (&overlay->pixels, NULL);
353 overlay->offset_x = g_value_get_int (value);
354 overlay->update_composition = TRUE;
357 overlay->offset_y = g_value_get_int (value);
358 overlay->update_composition = TRUE;
360 case PROP_RELATIVE_X:
361 overlay->relative_x = g_value_get_double (value);
362 overlay->update_composition = TRUE;
364 case PROP_RELATIVE_Y:
365 overlay->relative_y = g_value_get_double (value);
366 overlay->update_composition = TRUE;
369 overlay->coef_x = g_value_get_double (value);
370 overlay->update_composition = TRUE;
373 overlay->coef_y = g_value_get_double (value);
374 overlay->update_composition = TRUE;
376 case PROP_OVERLAY_WIDTH:
377 overlay->overlay_width = g_value_get_int (value);
378 overlay->update_composition = TRUE;
380 case PROP_OVERLAY_HEIGHT:
381 overlay->overlay_height = g_value_get_int (value);
382 overlay->update_composition = TRUE;
385 overlay->alpha = g_value_get_double (value);
386 overlay->update_composition = TRUE;
388 case PROP_POSITIONING_MODE:
389 overlay->positioning_mode = g_value_get_enum (value);
390 overlay->update_composition = TRUE;
393 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
397 GST_OBJECT_UNLOCK (overlay);
401 gst_gdk_pixbuf_overlay_get_property (GObject * object, guint property_id,
402 GValue * value, GParamSpec * pspec)
404 GstGdkPixbufOverlay *overlay = GST_GDK_PIXBUF_OVERLAY (object);
406 GST_OBJECT_LOCK (overlay);
408 switch (property_id) {
410 g_value_set_string (value, overlay->location);
413 g_value_set_object (value, overlay->pixbuf);
416 g_value_set_int (value, overlay->offset_x);
419 g_value_set_int (value, overlay->offset_y);
421 case PROP_RELATIVE_X:
422 g_value_set_double (value, overlay->relative_x);
424 case PROP_RELATIVE_Y:
425 g_value_set_double (value, overlay->relative_y);
428 g_value_set_double (value, overlay->coef_x);
431 g_value_set_double (value, overlay->coef_y);
433 case PROP_OVERLAY_WIDTH:
434 g_value_set_int (value, overlay->overlay_width);
436 case PROP_OVERLAY_HEIGHT:
437 g_value_set_int (value, overlay->overlay_height);
440 g_value_set_double (value, overlay->alpha);
442 case PROP_POSITIONING_MODE:
443 g_value_set_enum (value, overlay->positioning_mode);
446 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
450 GST_OBJECT_UNLOCK (overlay);
454 gst_gdk_pixbuf_overlay_finalize (GObject * object)
456 GstGdkPixbufOverlay *overlay = GST_GDK_PIXBUF_OVERLAY (object);
458 g_free (overlay->location);
459 overlay->location = NULL;
461 G_OBJECT_CLASS (gst_gdk_pixbuf_overlay_parent_class)->finalize (object);
465 gst_gdk_pixbuf_overlay_load_image (GstGdkPixbufOverlay * overlay, GError ** err)
469 pixbuf = gdk_pixbuf_new_from_file (overlay->location, err);
474 gst_gdk_pixbuf_overlay_set_pixbuf (overlay, pixbuf);
478 /* Takes ownership of pixbuf; call with OBJECT_LOCK */
480 gst_gdk_pixbuf_overlay_set_pixbuf (GstGdkPixbufOverlay * overlay,
483 GstVideoMeta *video_meta;
485 gint width, height, stride, w, h, plane;
487 if (!gdk_pixbuf_get_has_alpha (pixbuf)) {
488 GdkPixbuf *alpha_pixbuf;
490 /* FIXME: we could do this much more efficiently ourselves below, but
491 * we're lazy for now */
492 /* FIXME: perhaps expose substitute_color via properties */
493 alpha_pixbuf = gdk_pixbuf_add_alpha (pixbuf, FALSE, 0, 0, 0);
494 g_object_unref (pixbuf);
495 pixbuf = alpha_pixbuf;
498 width = gdk_pixbuf_get_width (pixbuf);
499 height = gdk_pixbuf_get_height (pixbuf);
500 stride = gdk_pixbuf_get_rowstride (pixbuf);
501 pixels = gdk_pixbuf_get_pixels (pixbuf);
503 /* the memory layout in GdkPixbuf is R-G-B-A, we want:
504 * - B-G-R-A on little-endian platforms
505 * - A-R-G-B on big-endian platforms
507 for (h = 0; h < height; ++h) {
508 p = pixels + (h * stride);
509 for (w = 0; w < width; ++w) {
512 /* R-G-B-A ==> B-G-R-A */
517 if (G_BYTE_ORDER == G_BIG_ENDIAN) {
518 /* B-G-R-A ==> A-R-G-B */
519 /* we can probably assume sane alignment */
520 *((guint32 *) p) = GUINT32_SWAP_LE_BE (*((guint32 *) p));
528 gst_buffer_unref (overlay->pixels);
530 /* assume we have row padding even for the last row */
531 /* transfer ownership of pixbuf to the buffer */
532 overlay->pixels = gst_buffer_new_wrapped_full (GST_MEMORY_FLAG_READONLY,
533 pixels, height * stride, 0, height * stride, pixbuf,
534 (GDestroyNotify) g_object_unref);
536 video_meta = gst_buffer_add_video_meta (overlay->pixels,
537 GST_VIDEO_FRAME_FLAG_NONE, GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_RGB,
540 for (plane = 0; plane < video_meta->n_planes; ++plane)
541 video_meta->stride[plane] = stride;
543 overlay->update_composition = TRUE;
545 GST_INFO_OBJECT (overlay, "Updated pixbuf, %d x %d", width, height);
549 gst_gdk_pixbuf_overlay_start (GstBaseTransform * trans)
551 GstGdkPixbufOverlay *overlay = GST_GDK_PIXBUF_OVERLAY (trans);
554 if (overlay->location != NULL) {
555 if (!gst_gdk_pixbuf_overlay_load_image (overlay, &err))
556 goto error_loading_image;
558 gst_base_transform_set_passthrough (trans, FALSE);
560 GST_WARNING_OBJECT (overlay, "no image location set, doing nothing");
561 gst_base_transform_set_passthrough (trans, TRUE);
569 GST_ELEMENT_ERROR (overlay, RESOURCE, OPEN_READ,
570 ("Could not load overlay image."), ("%s", err->message));
577 gst_gdk_pixbuf_overlay_stop (GstBaseTransform * trans)
579 GstGdkPixbufOverlay *overlay = GST_GDK_PIXBUF_OVERLAY (trans);
582 gst_video_overlay_composition_unref (overlay->comp);
583 overlay->comp = NULL;
586 gst_buffer_replace (&overlay->pixels, NULL);
592 gst_gdk_pixbuf_overlay_set_info (GstVideoFilter * filter, GstCaps * incaps,
593 GstVideoInfo * in_info, GstCaps * outcaps, GstVideoInfo * out_info)
595 GST_INFO_OBJECT (filter, "caps: %" GST_PTR_FORMAT, incaps);
600 gst_gdk_pixbuf_overlay_update_composition (GstGdkPixbufOverlay * overlay)
602 GstGdkPixbufPositioningMode positioning_mode;
603 GstVideoOverlayComposition *comp;
604 GstVideoOverlayRectangle *rect;
605 GstVideoMeta *overlay_meta;
606 gint x, y, width, height;
608 GST_VIDEO_INFO_WIDTH (&GST_VIDEO_FILTER (overlay)->in_info);
610 GST_VIDEO_INFO_HEIGHT (&GST_VIDEO_FILTER (overlay)->in_info);
613 gst_video_overlay_composition_unref (overlay->comp);
614 overlay->comp = NULL;
617 if (overlay->alpha == 0.0 || overlay->pixels == NULL)
620 overlay_meta = gst_buffer_get_video_meta (overlay->pixels);
622 positioning_mode = overlay->positioning_mode;
623 GST_DEBUG_OBJECT (overlay, "overlay positioning mode %d", positioning_mode);
625 width = overlay->overlay_width;
627 width = overlay_meta->width;
629 height = overlay->overlay_height;
631 height = overlay_meta->height;
633 if (positioning_mode == GST_GDK_PIXBUF_POSITIONING_PIXELS_ABSOLUTE) {
634 x = overlay->offset_x + (overlay->relative_x * width) +
635 (overlay->coef_x * video_width);
636 y = overlay->offset_y + (overlay->relative_y * height) +
637 (overlay->coef_y * video_height);
639 x = overlay->offset_x < 0 ?
640 video_width + overlay->offset_x - width +
641 (overlay->relative_x * video_width) :
642 overlay->offset_x + (overlay->relative_x * video_width);
643 y = overlay->offset_y < 0 ?
644 video_height + overlay->offset_y - height +
645 (overlay->relative_y * video_height) :
646 overlay->offset_y + (overlay->relative_y * video_height);
649 GST_DEBUG_OBJECT (overlay, "overlay image dimensions: %d x %d, alpha=%.2f",
650 overlay_meta->width, overlay_meta->height, overlay->alpha);
651 GST_DEBUG_OBJECT (overlay, "properties: x,y: %d,%d "
652 "(%g%%,%g%%) coef (%g%%,%g%%) - WxH: %dx%d",
653 overlay->offset_x, overlay->offset_y,
654 overlay->relative_x * 100.0, overlay->relative_y * 100.0,
655 overlay->coef_x * 100.0, overlay->coef_y * 100.0,
656 overlay->overlay_height, overlay->overlay_width);
657 GST_DEBUG_OBJECT (overlay, "overlay rendered: %d x %d @ %d,%d (onto %d x %d)",
658 width, height, x, y, video_width, video_height);
660 rect = gst_video_overlay_rectangle_new_raw (overlay->pixels,
661 x, y, width, height, GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
663 if (overlay->alpha != 1.0)
664 gst_video_overlay_rectangle_set_global_alpha (rect, overlay->alpha);
666 comp = gst_video_overlay_composition_new (rect);
667 gst_video_overlay_rectangle_unref (rect);
669 overlay->comp = comp;
673 gst_gdk_pixbuf_overlay_before_transform (GstBaseTransform * trans,
676 GstClockTime stream_time;
677 GstGdkPixbufOverlay *overlay = GST_GDK_PIXBUF_OVERLAY (trans);
678 gboolean set_passthrough = FALSE;
680 stream_time = gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
681 GST_BUFFER_TIMESTAMP (outbuf));
683 if (GST_CLOCK_TIME_IS_VALID (stream_time))
684 gst_object_sync_values (GST_OBJECT (trans), stream_time);
686 /* now properties have been sync'ed; maybe need to update composition */
687 GST_OBJECT_LOCK (overlay);
688 if (G_UNLIKELY (overlay->update_composition)) {
689 gst_gdk_pixbuf_overlay_update_composition (overlay);
690 overlay->update_composition = FALSE;
691 set_passthrough = TRUE;
693 GST_OBJECT_UNLOCK (overlay);
695 /* determine passthrough mode so the buffer is writable if needed
696 * when passed into _transform_ip */
697 if (G_UNLIKELY (set_passthrough))
698 gst_base_transform_set_passthrough (trans, overlay->comp == NULL);
702 gst_gdk_pixbuf_overlay_transform_frame_ip (GstVideoFilter * filter,
703 GstVideoFrame * frame)
705 GstGdkPixbufOverlay *overlay = GST_GDK_PIXBUF_OVERLAY (filter);
707 if (overlay->comp != NULL)
708 gst_video_overlay_composition_blend (overlay->comp, frame);