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 an image loaded from file onto
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 currently not supported.
34 * Negative offsets are also not yet supported.
36 * ## Example launch line
38 * gst-launch-1.0 -v videotestsrc ! gdkpixbufoverlay location=image.png ! autovideosink
40 * Overlays the image in image.png onto the test video picture produced by
50 #include "gstgdkpixbufoverlay.h"
52 #include "gstgdkpixbufelements.h"
53 #include <gst/video/gstvideometa.h>
55 GST_DEBUG_CATEGORY_STATIC (gdkpixbufoverlay_debug);
56 #define GST_CAT_DEFAULT gdkpixbufoverlay_debug
58 static void gst_gdk_pixbuf_overlay_set_property (GObject * object,
59 guint property_id, const GValue * value, GParamSpec * pspec);
60 static void gst_gdk_pixbuf_overlay_get_property (GObject * object,
61 guint property_id, GValue * value, GParamSpec * pspec);
62 static void gst_gdk_pixbuf_overlay_finalize (GObject * object);
64 static gboolean gst_gdk_pixbuf_overlay_start (GstBaseTransform * trans);
65 static gboolean gst_gdk_pixbuf_overlay_stop (GstBaseTransform * trans);
67 gst_gdk_pixbuf_overlay_transform_frame_ip (GstVideoFilter * filter,
68 GstVideoFrame * frame);
69 static void gst_gdk_pixbuf_overlay_before_transform (GstBaseTransform * trans,
71 static gboolean gst_gdk_pixbuf_overlay_set_info (GstVideoFilter * filter,
72 GstCaps * incaps, GstVideoInfo * in_info, GstCaps * outcaps,
73 GstVideoInfo * out_info);
75 gst_gdk_pixbuf_overlay_load_image (GstGdkPixbufOverlay * overlay,
77 static void gst_gdk_pixbuf_overlay_set_pixbuf (GstGdkPixbufOverlay * overlay,
85 PROP_POSITIONING_MODE,
97 /* FIXME 2.0: change to absolute positioning */
98 #define DEFAULT_POSITIONING_MODE \
99 GST_GDK_PIXBUF_POSITIONING_PIXELS_RELATIVE_TO_EDGES
101 static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
104 GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE
105 (GST_VIDEO_OVERLAY_COMPOSITION_BLEND_FORMATS))
108 static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
111 GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE
112 (GST_VIDEO_OVERLAY_COMPOSITION_BLEND_FORMATS))
115 G_DEFINE_TYPE (GstGdkPixbufOverlay, gst_gdk_pixbuf_overlay,
116 GST_TYPE_VIDEO_FILTER);
117 GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (gdkpixbufoverlay, "gdkpixbufoverlay",
118 GST_RANK_NONE, GST_TYPE_GDK_PIXBUF_OVERLAY,
119 gdk_pixbuf_element_init (plugin));
121 #define GST_TYPE_GDK_PIXBUF_POSITIONING_MODE \
122 (gst_gdk_pixbuf_positioning_mode_get_type())
125 gst_gdk_pixbuf_positioning_mode_get_type (void)
127 static const GEnumValue pos_modes[] = {
128 {GST_GDK_PIXBUF_POSITIONING_PIXELS_RELATIVE_TO_EDGES,
129 "pixels-relative-to-edges", "pixels-relative-to-edges"},
130 {GST_GDK_PIXBUF_POSITIONING_PIXELS_ABSOLUTE, "pixels-absolute",
135 static GType type; /* 0 */
138 type = g_enum_register_static ("GstGdkPixbufPositioningMode", pos_modes);
145 gst_gdk_pixbuf_overlay_class_init (GstGdkPixbufOverlayClass * klass)
147 GstVideoFilterClass *videofilter_class = GST_VIDEO_FILTER_CLASS (klass);
148 GstBaseTransformClass *basetrans_class = GST_BASE_TRANSFORM_CLASS (klass);
149 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
150 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
152 gobject_class->set_property = gst_gdk_pixbuf_overlay_set_property;
153 gobject_class->get_property = gst_gdk_pixbuf_overlay_get_property;
154 gobject_class->finalize = gst_gdk_pixbuf_overlay_finalize;
156 basetrans_class->start = GST_DEBUG_FUNCPTR (gst_gdk_pixbuf_overlay_start);
157 basetrans_class->stop = GST_DEBUG_FUNCPTR (gst_gdk_pixbuf_overlay_stop);
159 basetrans_class->before_transform =
160 GST_DEBUG_FUNCPTR (gst_gdk_pixbuf_overlay_before_transform);
162 videofilter_class->set_info =
163 GST_DEBUG_FUNCPTR (gst_gdk_pixbuf_overlay_set_info);
164 videofilter_class->transform_frame_ip =
165 GST_DEBUG_FUNCPTR (gst_gdk_pixbuf_overlay_transform_frame_ip);
167 g_object_class_install_property (gobject_class, PROP_LOCATION,
168 g_param_spec_string ("location", "location",
169 "Location of image file to overlay", NULL, GST_PARAM_CONTROLLABLE
170 | GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE
171 | G_PARAM_STATIC_STRINGS));
172 g_object_class_install_property (gobject_class, PROP_OFFSET_X,
173 g_param_spec_int ("offset-x", "X Offset",
174 "For positive value, horizontal offset of overlay image in pixels from"
175 " left of video image. For negative value, horizontal offset of overlay"
176 " image in pixels from right of video image", G_MININT, G_MAXINT, 0,
177 GST_PARAM_CONTROLLABLE | GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE
178 | G_PARAM_STATIC_STRINGS));
179 g_object_class_install_property (gobject_class, PROP_OFFSET_Y,
180 g_param_spec_int ("offset-y", "Y Offset",
181 "For positive value, vertical offset of overlay image in pixels from"
182 " top of video image. For negative value, vertical offset of overlay"
183 " image in pixels from bottom of video image", G_MININT, G_MAXINT, 0,
184 GST_PARAM_CONTROLLABLE | GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE
185 | G_PARAM_STATIC_STRINGS));
186 g_object_class_install_property (gobject_class, PROP_RELATIVE_X,
187 g_param_spec_double ("relative-x", "Relative X Offset",
188 "Horizontal offset of overlay image in fractions of video image "
189 "width, from top-left corner of video image"
190 " (in relative positioning)", -1.0, 1.0, 0.0,
191 GST_PARAM_CONTROLLABLE | GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE
192 | G_PARAM_STATIC_STRINGS));
193 g_object_class_install_property (gobject_class, PROP_RELATIVE_Y,
194 g_param_spec_double ("relative-y", "Relative Y Offset",
195 "Vertical offset of overlay image in fractions of video image "
196 "height, from top-left corner of video image"
197 " (in relative positioning)", -1.0, 1.0, 0.0,
198 GST_PARAM_CONTROLLABLE | GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE
199 | G_PARAM_STATIC_STRINGS));
200 g_object_class_install_property (gobject_class, PROP_OVERLAY_WIDTH,
201 g_param_spec_int ("overlay-width", "Overlay Width",
202 "Width of overlay image in pixels (0 = same as overlay image)", 0,
204 GST_PARAM_CONTROLLABLE | GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE
205 | G_PARAM_STATIC_STRINGS));
206 g_object_class_install_property (gobject_class, PROP_OVERLAY_HEIGHT,
207 g_param_spec_int ("overlay-height", "Overlay Height",
208 "Height of overlay image in pixels (0 = same as overlay image)", 0,
210 GST_PARAM_CONTROLLABLE | GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE
211 | G_PARAM_STATIC_STRINGS));
212 g_object_class_install_property (gobject_class, PROP_ALPHA,
213 g_param_spec_double ("alpha", "Alpha", "Global alpha of overlay image",
214 0.0, 1.0, 1.0, GST_PARAM_CONTROLLABLE | GST_PARAM_MUTABLE_PLAYING
215 | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
217 * GstGdkPixbufOverlay:pixbuf:
219 * GdkPixbuf object to render.
223 g_object_class_install_property (gobject_class, PROP_PIXBUF,
224 g_param_spec_object ("pixbuf", "Pixbuf", "GdkPixbuf object to render",
225 GDK_TYPE_PIXBUF, GST_PARAM_CONTROLLABLE | GST_PARAM_MUTABLE_PLAYING
226 | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
228 * GstGdkPixbufOverlay:positioning-mode:
230 * Positioning mode of offset-x and offset-y properties. Determines how
231 * negative x/y offsets will be interpreted. By default negative values
232 * are for positioning relative to the right/bottom edge of the video
233 * image, but you can use this property to select absolute positioning
234 * relative to a (0, 0) origin in the top-left corner. That way negative
235 * offsets will be to the left/above the video image, which allows you to
236 * smoothly slide logos into and out of the frame if desired.
240 g_object_class_install_property (gobject_class, PROP_POSITIONING_MODE,
241 g_param_spec_enum ("positioning-mode", "Positioning mode",
242 "Positioning mode of offset-x and offset-y properties",
243 GST_TYPE_GDK_PIXBUF_POSITIONING_MODE, DEFAULT_POSITIONING_MODE,
244 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
246 /* FIXME the following actually act as a RELATIVE_X/RELATIVE_Y,
247 * but those were already slightly mutated/abused with ABSOLUTE positioning,
248 * so let's keep that and follow suit
249 * Suffice it to say all that could do with cleanup (2.0 ??) */
251 * GstGdkPixbufOverlay:coef-x:
253 * In absolute positioning mode, the x coordinate of overlay image's
254 * top-left corner is now given by
255 * offset-x + (relative-x * overlay_width) + (coef-x * video_width).
256 * This allows to align the image absolutely and relatively
257 * to any edge or center position.
261 g_object_class_install_property (gobject_class, PROP_COEF_X,
262 g_param_spec_double ("coef-x", "Relative X Offset",
263 "Horizontal offset of overlay image in fractions of video image "
264 "width, from top-left corner of video image (absolute positioning)",
265 -1.0, 1.0, 0.0, GST_PARAM_CONTROLLABLE | GST_PARAM_MUTABLE_PLAYING
266 | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
268 * GstGdkPixbufOverlay:coef-y:
270 * In absolute positioning mode, the y coordinate of overlay image's
271 * top-left corner is now given by
272 * offset-y + (relative-y * overlay_height) + (coef-y * video_height).
273 * This allows to align the image absolutely and relatively
274 * to any edge or center position.
278 g_object_class_install_property (gobject_class, PROP_COEF_Y,
279 g_param_spec_double ("coef-y", "Relative Y Offset",
280 "Vertical offset of overlay image in fractions of video image "
281 "height, from top-left corner of video image (absolute positioning)",
282 -1.0, 1.0, 0.0, GST_PARAM_CONTROLLABLE | GST_PARAM_MUTABLE_PLAYING
283 | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
285 gst_element_class_add_static_pad_template (element_class, &sink_template);
286 gst_element_class_add_static_pad_template (element_class, &src_template);
288 gst_element_class_set_static_metadata (element_class,
289 "GdkPixbuf Overlay", "Filter/Effect/Video",
290 "Overlay an image onto a video stream",
291 "Tim-Philipp Müller <tim centricular net>");
292 GST_DEBUG_CATEGORY_INIT (gdkpixbufoverlay_debug, "gdkpixbufoverlay", 0,
293 "debug category for gdkpixbufoverlay element");
295 gst_type_mark_as_plugin_api (GST_TYPE_GDK_PIXBUF_POSITIONING_MODE, 0);
299 gst_gdk_pixbuf_overlay_init (GstGdkPixbufOverlay * overlay)
301 overlay->offset_x = 0;
302 overlay->offset_y = 0;
304 overlay->relative_x = 0.0;
305 overlay->relative_y = 0.0;
307 overlay->coef_x = 0.0;
308 overlay->coef_y = 0.0;
310 overlay->positioning_mode = DEFAULT_POSITIONING_MODE;
312 overlay->overlay_width = 0;
313 overlay->overlay_height = 0;
315 overlay->alpha = 1.0;
317 overlay->pixbuf = NULL;
321 gst_gdk_pixbuf_overlay_set_property (GObject * object, guint property_id,
322 const GValue * value, GParamSpec * pspec)
324 GstGdkPixbufOverlay *overlay = GST_GDK_PIXBUF_OVERLAY (object);
326 GST_OBJECT_LOCK (overlay);
328 switch (property_id) {
331 g_free (overlay->location);
332 overlay->location = g_value_dup_string (value);
333 if (!gst_gdk_pixbuf_overlay_load_image (overlay, &err)) {
334 GST_ERROR_OBJECT (overlay, "Could not load overlay image: %s",
341 GdkPixbuf *pixbuf = g_value_get_object (value);
343 if (overlay->pixbuf != NULL)
344 g_object_unref (overlay->pixbuf);
346 overlay->pixbuf = g_object_ref (pixbuf);
347 gst_gdk_pixbuf_overlay_set_pixbuf (overlay, g_object_ref (pixbuf));
349 overlay->pixbuf = NULL;
350 gst_buffer_replace (&overlay->pixels, NULL);
355 overlay->offset_x = g_value_get_int (value);
356 overlay->update_composition = TRUE;
359 overlay->offset_y = g_value_get_int (value);
360 overlay->update_composition = TRUE;
362 case PROP_RELATIVE_X:
363 overlay->relative_x = g_value_get_double (value);
364 overlay->update_composition = TRUE;
366 case PROP_RELATIVE_Y:
367 overlay->relative_y = g_value_get_double (value);
368 overlay->update_composition = TRUE;
371 overlay->coef_x = g_value_get_double (value);
372 overlay->update_composition = TRUE;
375 overlay->coef_y = g_value_get_double (value);
376 overlay->update_composition = TRUE;
378 case PROP_OVERLAY_WIDTH:
379 overlay->overlay_width = g_value_get_int (value);
380 overlay->update_composition = TRUE;
382 case PROP_OVERLAY_HEIGHT:
383 overlay->overlay_height = g_value_get_int (value);
384 overlay->update_composition = TRUE;
387 overlay->alpha = g_value_get_double (value);
388 overlay->update_composition = TRUE;
390 case PROP_POSITIONING_MODE:
391 overlay->positioning_mode = g_value_get_enum (value);
392 overlay->update_composition = TRUE;
395 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
399 GST_OBJECT_UNLOCK (overlay);
403 gst_gdk_pixbuf_overlay_get_property (GObject * object, guint property_id,
404 GValue * value, GParamSpec * pspec)
406 GstGdkPixbufOverlay *overlay = GST_GDK_PIXBUF_OVERLAY (object);
408 GST_OBJECT_LOCK (overlay);
410 switch (property_id) {
412 g_value_set_string (value, overlay->location);
415 g_value_set_object (value, overlay->pixbuf);
418 g_value_set_int (value, overlay->offset_x);
421 g_value_set_int (value, overlay->offset_y);
423 case PROP_RELATIVE_X:
424 g_value_set_double (value, overlay->relative_x);
426 case PROP_RELATIVE_Y:
427 g_value_set_double (value, overlay->relative_y);
430 g_value_set_double (value, overlay->coef_x);
433 g_value_set_double (value, overlay->coef_y);
435 case PROP_OVERLAY_WIDTH:
436 g_value_set_int (value, overlay->overlay_width);
438 case PROP_OVERLAY_HEIGHT:
439 g_value_set_int (value, overlay->overlay_height);
442 g_value_set_double (value, overlay->alpha);
444 case PROP_POSITIONING_MODE:
445 g_value_set_enum (value, overlay->positioning_mode);
448 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
452 GST_OBJECT_UNLOCK (overlay);
456 gst_gdk_pixbuf_overlay_finalize (GObject * object)
458 GstGdkPixbufOverlay *overlay = GST_GDK_PIXBUF_OVERLAY (object);
460 g_free (overlay->location);
461 overlay->location = NULL;
463 G_OBJECT_CLASS (gst_gdk_pixbuf_overlay_parent_class)->finalize (object);
467 gst_gdk_pixbuf_overlay_load_image (GstGdkPixbufOverlay * overlay, GError ** err)
471 pixbuf = gdk_pixbuf_new_from_file (overlay->location, err);
476 gst_gdk_pixbuf_overlay_set_pixbuf (overlay, pixbuf);
480 /* Takes ownership of pixbuf; call with OBJECT_LOCK */
482 gst_gdk_pixbuf_overlay_set_pixbuf (GstGdkPixbufOverlay * overlay,
485 GstVideoMeta *video_meta;
487 gint width, height, stride, w, h, plane;
489 if (!gdk_pixbuf_get_has_alpha (pixbuf)) {
490 GdkPixbuf *alpha_pixbuf;
492 /* FIXME: we could do this much more efficiently ourselves below, but
493 * we're lazy for now */
494 /* FIXME: perhaps expose substitute_color via properties */
495 alpha_pixbuf = gdk_pixbuf_add_alpha (pixbuf, FALSE, 0, 0, 0);
496 g_object_unref (pixbuf);
497 pixbuf = alpha_pixbuf;
500 width = gdk_pixbuf_get_width (pixbuf);
501 height = gdk_pixbuf_get_height (pixbuf);
502 stride = gdk_pixbuf_get_rowstride (pixbuf);
503 pixels = gdk_pixbuf_get_pixels (pixbuf);
505 /* the memory layout in GdkPixbuf is R-G-B-A, we want:
506 * - B-G-R-A on little-endian platforms
507 * - A-R-G-B on big-endian platforms
509 for (h = 0; h < height; ++h) {
510 p = pixels + (h * stride);
511 for (w = 0; w < width; ++w) {
514 /* R-G-B-A ==> B-G-R-A */
519 if (G_BYTE_ORDER == G_BIG_ENDIAN) {
520 /* B-G-R-A ==> A-R-G-B */
521 /* we can probably assume sane alignment */
522 *((guint32 *) p) = GUINT32_SWAP_LE_BE (*((guint32 *) p));
530 gst_buffer_unref (overlay->pixels);
532 /* assume we have row padding even for the last row */
533 /* transfer ownership of pixbuf to the buffer */
534 overlay->pixels = gst_buffer_new_wrapped_full (GST_MEMORY_FLAG_READONLY,
535 pixels, height * stride, 0, height * stride, pixbuf,
536 (GDestroyNotify) g_object_unref);
538 video_meta = gst_buffer_add_video_meta (overlay->pixels,
539 GST_VIDEO_FRAME_FLAG_NONE, GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_RGB,
542 for (plane = 0; plane < video_meta->n_planes; ++plane)
543 video_meta->stride[plane] = stride;
545 overlay->update_composition = TRUE;
547 GST_INFO_OBJECT (overlay, "Updated pixbuf, %d x %d", width, height);
551 gst_gdk_pixbuf_overlay_start (GstBaseTransform * trans)
553 GstGdkPixbufOverlay *overlay = GST_GDK_PIXBUF_OVERLAY (trans);
556 if (overlay->location != NULL) {
557 if (!gst_gdk_pixbuf_overlay_load_image (overlay, &err))
558 goto error_loading_image;
560 gst_base_transform_set_passthrough (trans, FALSE);
562 GST_WARNING_OBJECT (overlay, "no image location set, doing nothing");
563 gst_base_transform_set_passthrough (trans, TRUE);
571 GST_ELEMENT_ERROR (overlay, RESOURCE, OPEN_READ,
572 ("Could not load overlay image."), ("%s", err->message));
579 gst_gdk_pixbuf_overlay_stop (GstBaseTransform * trans)
581 GstGdkPixbufOverlay *overlay = GST_GDK_PIXBUF_OVERLAY (trans);
584 gst_video_overlay_composition_unref (overlay->comp);
585 overlay->comp = NULL;
588 gst_buffer_replace (&overlay->pixels, NULL);
594 gst_gdk_pixbuf_overlay_set_info (GstVideoFilter * filter, GstCaps * incaps,
595 GstVideoInfo * in_info, GstCaps * outcaps, GstVideoInfo * out_info)
597 GST_INFO_OBJECT (filter, "caps: %" GST_PTR_FORMAT, incaps);
602 gst_gdk_pixbuf_overlay_update_composition (GstGdkPixbufOverlay * overlay)
604 GstGdkPixbufPositioningMode positioning_mode;
605 GstVideoOverlayComposition *comp;
606 GstVideoOverlayRectangle *rect;
607 GstVideoMeta *overlay_meta;
608 gint x, y, width, height;
610 GST_VIDEO_INFO_WIDTH (&GST_VIDEO_FILTER (overlay)->in_info);
612 GST_VIDEO_INFO_HEIGHT (&GST_VIDEO_FILTER (overlay)->in_info);
615 gst_video_overlay_composition_unref (overlay->comp);
616 overlay->comp = NULL;
619 if (overlay->alpha == 0.0 || overlay->pixels == NULL)
622 overlay_meta = gst_buffer_get_video_meta (overlay->pixels);
624 positioning_mode = overlay->positioning_mode;
625 GST_DEBUG_OBJECT (overlay, "overlay positioning mode %d", positioning_mode);
627 width = overlay->overlay_width;
629 width = overlay_meta->width;
631 height = overlay->overlay_height;
633 height = overlay_meta->height;
635 if (positioning_mode == GST_GDK_PIXBUF_POSITIONING_PIXELS_ABSOLUTE) {
636 x = overlay->offset_x + (overlay->relative_x * width) +
637 (overlay->coef_x * video_width);
638 y = overlay->offset_y + (overlay->relative_y * height) +
639 (overlay->coef_y * video_height);
641 x = overlay->offset_x < 0 ?
642 video_width + overlay->offset_x - width +
643 (overlay->relative_x * video_width) :
644 overlay->offset_x + (overlay->relative_x * video_width);
645 y = overlay->offset_y < 0 ?
646 video_height + overlay->offset_y - height +
647 (overlay->relative_y * video_height) :
648 overlay->offset_y + (overlay->relative_y * video_height);
651 GST_DEBUG_OBJECT (overlay, "overlay image dimensions: %d x %d, alpha=%.2f",
652 overlay_meta->width, overlay_meta->height, overlay->alpha);
653 GST_DEBUG_OBJECT (overlay, "properties: x,y: %d,%d "
654 "(%g%%,%g%%) coef (%g%%,%g%%) - WxH: %dx%d",
655 overlay->offset_x, overlay->offset_y,
656 overlay->relative_x * 100.0, overlay->relative_y * 100.0,
657 overlay->coef_x * 100.0, overlay->coef_y * 100.0,
658 overlay->overlay_height, overlay->overlay_width);
659 GST_DEBUG_OBJECT (overlay, "overlay rendered: %d x %d @ %d,%d (onto %d x %d)",
660 width, height, x, y, video_width, video_height);
662 rect = gst_video_overlay_rectangle_new_raw (overlay->pixels,
663 x, y, width, height, GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
665 if (overlay->alpha != 1.0)
666 gst_video_overlay_rectangle_set_global_alpha (rect, overlay->alpha);
668 comp = gst_video_overlay_composition_new (rect);
669 gst_video_overlay_rectangle_unref (rect);
671 overlay->comp = comp;
675 gst_gdk_pixbuf_overlay_before_transform (GstBaseTransform * trans,
678 GstClockTime stream_time;
679 GstGdkPixbufOverlay *overlay = GST_GDK_PIXBUF_OVERLAY (trans);
680 gboolean set_passthrough = FALSE;
682 stream_time = gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
683 GST_BUFFER_TIMESTAMP (outbuf));
685 if (GST_CLOCK_TIME_IS_VALID (stream_time))
686 gst_object_sync_values (GST_OBJECT (trans), stream_time);
688 /* now properties have been sync'ed; maybe need to update composition */
689 GST_OBJECT_LOCK (overlay);
690 if (G_UNLIKELY (overlay->update_composition)) {
691 gst_gdk_pixbuf_overlay_update_composition (overlay);
692 overlay->update_composition = FALSE;
693 set_passthrough = TRUE;
695 GST_OBJECT_UNLOCK (overlay);
697 /* determine passthrough mode so the buffer is writable if needed
698 * when passed into _transform_ip */
699 if (G_UNLIKELY (set_passthrough))
700 gst_base_transform_set_passthrough (trans, overlay->comp == NULL);
704 gst_gdk_pixbuf_overlay_transform_frame_ip (GstVideoFilter * filter,
705 GstVideoFrame * frame)
707 GstGdkPixbufOverlay *overlay = GST_GDK_PIXBUF_OVERLAY (filter);
709 if (overlay->comp != NULL)
710 gst_video_overlay_composition_blend (overlay->comp, frame);