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
23 * The gdkpixbufoverlay element overlays an image loaded from file onto
26 * Changing the positioning or overlay width and height properties at runtime
27 * is supported, but it might be prudent to to protect the property setting
28 * code with GST_BASE_TRANSFORM_LOCK and GST_BASE_TRANSFORM_UNLOCK, as
29 * g_object_set() is not atomic for multiple properties passed in one go.
31 * Changing the image at runtime is currently not supported.
33 * Negative offsets are also not yet supported.
36 * <title>Example launch line</title>
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 <gst/video/gstvideometa.h>
54 GST_DEBUG_CATEGORY_STATIC (gdkpixbufoverlay_debug);
55 #define GST_CAT_DEFAULT gdkpixbufoverlay_debug
57 static void gst_gdk_pixbuf_overlay_set_property (GObject * object,
58 guint property_id, const GValue * value, GParamSpec * pspec);
59 static void gst_gdk_pixbuf_overlay_get_property (GObject * object,
60 guint property_id, GValue * value, GParamSpec * pspec);
61 static void gst_gdk_pixbuf_overlay_finalize (GObject * object);
63 static gboolean gst_gdk_pixbuf_overlay_start (GstBaseTransform * trans);
64 static gboolean gst_gdk_pixbuf_overlay_stop (GstBaseTransform * trans);
66 gst_gdk_pixbuf_overlay_transform_frame_ip (GstVideoFilter * filter,
67 GstVideoFrame * frame);
68 static void gst_gdk_pixbuf_overlay_before_transform (GstBaseTransform * trans,
70 static gboolean gst_gdk_pixbuf_overlay_set_info (GstVideoFilter * filter,
71 GstCaps * incaps, GstVideoInfo * in_info, GstCaps * outcaps,
72 GstVideoInfo * out_info);
74 gst_gdk_pixbuf_overlay_load_image (GstGdkPixbufOverlay * overlay,
76 static void gst_gdk_pixbuf_overlay_set_pixbuf (GstGdkPixbufOverlay * overlay,
84 PROP_POSITIONING_MODE,
96 #define VIDEO_FORMATS "{ RGBx, RGB, BGR, BGRx, xRGB, xBGR, " \
97 "RGBA, BGRA, ARGB, ABGR, I420, YV12, AYUV, YUY2, UYVY, " \
98 "v308, v210, v216, Y41B, Y42B, Y444, YVYU, NV12, NV21, UYVP, " \
99 "RGB16, BGR16, RGB15, BGR15, UYVP, A420, YUV9, YVU9, " \
100 "IYU1, ARGB64, AYUV64, r210, I420_10LE, I420_10BE, " \
101 "GRAY8, GRAY16_BE, GRAY16_LE }"
103 /* FIXME 2.0: change to absolute positioning */
104 #define DEFAULT_POSITIONING_MODE \
105 GST_GDK_PIXBUF_POSITIONING_PIXELS_RELATIVE_TO_EDGES
107 static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
110 GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE (VIDEO_FORMATS))
113 static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
116 GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE (VIDEO_FORMATS))
119 G_DEFINE_TYPE (GstGdkPixbufOverlay, gst_gdk_pixbuf_overlay,
120 GST_TYPE_VIDEO_FILTER);
122 #define GST_TYPE_GDK_PIXBUF_POSITIONING_MODE \
123 (gst_gdk_pixbuf_positioning_mode_get_type())
126 gst_gdk_pixbuf_positioning_mode_get_type (void)
128 static const GEnumValue pos_modes[] = {
129 {GST_GDK_PIXBUF_POSITIONING_PIXELS_RELATIVE_TO_EDGES,
130 "pixels-relative-to-edges", "pixels-relative-to-edges"},
131 {GST_GDK_PIXBUF_POSITIONING_PIXELS_ABSOLUTE, "pixels-absolute",
136 static GType type; /* 0 */
139 type = g_enum_register_static ("GstGdkPixbufPositioningMode", pos_modes);
146 gst_gdk_pixbuf_overlay_class_init (GstGdkPixbufOverlayClass * klass)
148 GstVideoFilterClass *videofilter_class = GST_VIDEO_FILTER_CLASS (klass);
149 GstBaseTransformClass *basetrans_class = GST_BASE_TRANSFORM_CLASS (klass);
150 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
151 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
153 gobject_class->set_property = gst_gdk_pixbuf_overlay_set_property;
154 gobject_class->get_property = gst_gdk_pixbuf_overlay_get_property;
155 gobject_class->finalize = gst_gdk_pixbuf_overlay_finalize;
157 basetrans_class->start = GST_DEBUG_FUNCPTR (gst_gdk_pixbuf_overlay_start);
158 basetrans_class->stop = GST_DEBUG_FUNCPTR (gst_gdk_pixbuf_overlay_stop);
160 basetrans_class->before_transform =
161 GST_DEBUG_FUNCPTR (gst_gdk_pixbuf_overlay_before_transform);
163 videofilter_class->set_info =
164 GST_DEBUG_FUNCPTR (gst_gdk_pixbuf_overlay_set_info);
165 videofilter_class->transform_frame_ip =
166 GST_DEBUG_FUNCPTR (gst_gdk_pixbuf_overlay_transform_frame_ip);
168 g_object_class_install_property (gobject_class, PROP_LOCATION,
169 g_param_spec_string ("location", "location",
170 "Location of image file to overlay", NULL, GST_PARAM_CONTROLLABLE
171 | GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE
172 | G_PARAM_STATIC_STRINGS));
173 g_object_class_install_property (gobject_class, PROP_OFFSET_X,
174 g_param_spec_int ("offset-x", "X Offset",
175 "For positive value, horizontal offset of overlay image in pixels from"
176 " left of video image. For negative value, horizontal offset of overlay"
177 " image in pixels from right of video image", G_MININT, G_MAXINT, 0,
178 GST_PARAM_CONTROLLABLE | GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE
179 | G_PARAM_STATIC_STRINGS));
180 g_object_class_install_property (gobject_class, PROP_OFFSET_Y,
181 g_param_spec_int ("offset-y", "Y Offset",
182 "For positive value, vertical offset of overlay image in pixels from"
183 " top of video image. For negative value, vertical offset of overlay"
184 " image in pixels from bottom of video image", G_MININT, G_MAXINT, 0,
185 GST_PARAM_CONTROLLABLE | GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE
186 | G_PARAM_STATIC_STRINGS));
187 g_object_class_install_property (gobject_class, PROP_RELATIVE_X,
188 g_param_spec_double ("relative-x", "Relative X Offset",
189 "Horizontal offset of overlay image in fractions of video image "
190 "width, from top-left corner of video image"
191 " (in relative positioning)", -1.0, 1.0, 0.0,
192 GST_PARAM_CONTROLLABLE | GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE
193 | G_PARAM_STATIC_STRINGS));
194 g_object_class_install_property (gobject_class, PROP_RELATIVE_Y,
195 g_param_spec_double ("relative-y", "Relative Y Offset",
196 "Vertical offset of overlay image in fractions of video image "
197 "height, from top-left corner of video image"
198 " (in relative positioning)", -1.0, 1.0, 0.0,
199 GST_PARAM_CONTROLLABLE | GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE
200 | G_PARAM_STATIC_STRINGS));
201 g_object_class_install_property (gobject_class, PROP_OVERLAY_WIDTH,
202 g_param_spec_int ("overlay-width", "Overlay Width",
203 "Width of overlay image in pixels (0 = same as overlay image)", 0,
205 GST_PARAM_CONTROLLABLE | GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE
206 | G_PARAM_STATIC_STRINGS));
207 g_object_class_install_property (gobject_class, PROP_OVERLAY_HEIGHT,
208 g_param_spec_int ("overlay-height", "Overlay Height",
209 "Height of overlay image in pixels (0 = same as overlay image)", 0,
211 GST_PARAM_CONTROLLABLE | GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE
212 | G_PARAM_STATIC_STRINGS));
213 g_object_class_install_property (gobject_class, PROP_ALPHA,
214 g_param_spec_double ("alpha", "Alpha", "Global alpha of overlay image",
215 0.0, 1.0, 1.0, GST_PARAM_CONTROLLABLE | GST_PARAM_MUTABLE_PLAYING
216 | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
218 * GstGdkPixbufOverlay:pixbuf:
220 * GdkPixbuf object to render.
224 g_object_class_install_property (gobject_class, PROP_PIXBUF,
225 g_param_spec_object ("pixbuf", "Pixbuf", "GdkPixbuf object to render",
226 GDK_TYPE_PIXBUF, GST_PARAM_CONTROLLABLE | GST_PARAM_MUTABLE_PLAYING
227 | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
229 * GstGdkPixbufOverlay:positioning-mode:
231 * Positioning mode of offset-x and offset-y properties. Determines how
232 * negative x/y offsets will be interpreted. By default negative values
233 * are for positioning relative to the right/bottom edge of the video
234 * image, but you can use this property to select absolute positioning
235 * relative to a (0, 0) origin in the top-left corner. That way negative
236 * offsets will be to the left/above the video image, which allows you to
237 * smoothly slide logos into and out of the frame if desired.
241 g_object_class_install_property (gobject_class, PROP_POSITIONING_MODE,
242 g_param_spec_enum ("positioning-mode", "Positioning mode",
243 "Positioning mode of offset-x and offset-y properties",
244 GST_TYPE_GDK_PIXBUF_POSITIONING_MODE, DEFAULT_POSITIONING_MODE,
245 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
247 /* FIXME the following actually act as a RELATIVE_X/RELATIVE_Y,
248 * but those were already slightly mutated/abused with ABSOLUTE positioning,
249 * so let's keep that and follow suit
250 * Suffice it to say all that could do with cleanup (2.0 ??) */
252 * GstGdkPixbufOverlay:coef-x:
254 * In absolute positioning mode, the x coordinate of overlay image's
255 * top-left corner is now given by
256 * offset-x + (relative-x * overlay_width) + (coef-x * video_width).
257 * This allows to align the image absolutely and relatively
258 * to any edge or center position.
262 g_object_class_install_property (gobject_class, PROP_COEF_X,
263 g_param_spec_double ("coef-x", "Relative X Offset",
264 "Horizontal offset of overlay image in fractions of video image "
265 "width, from top-left corner of video image (absolute positioning)",
266 -1.0, 1.0, 0.0, GST_PARAM_CONTROLLABLE | GST_PARAM_MUTABLE_PLAYING
267 | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
269 * GstGdkPixbufOverlay:coef-y:
271 * In absolute positioning mode, the y coordinate of overlay image's
272 * top-left corner is now given by
273 * offset-y + (relative-y * overlay_height) + (coef-y * video_height).
274 * This allows to align the image absolutely and relatively
275 * to any edge or center position.
279 g_object_class_install_property (gobject_class, PROP_COEF_Y,
280 g_param_spec_double ("coef-y", "Relative Y Offset",
281 "Vertical offset of overlay image in fractions of video image "
282 "height, from top-left corner of video image (absolute positioning)",
283 -1.0, 1.0, 0.0, GST_PARAM_CONTROLLABLE | GST_PARAM_MUTABLE_PLAYING
284 | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
286 gst_element_class_add_static_pad_template (element_class, &sink_template);
287 gst_element_class_add_static_pad_template (element_class, &src_template);
289 gst_element_class_set_static_metadata (element_class,
290 "GdkPixbuf Overlay", "Filter/Effect/Video",
291 "Overlay an image onto a video stream",
292 "Tim-Philipp Müller <tim centricular net>");
293 GST_DEBUG_CATEGORY_INIT (gdkpixbufoverlay_debug, "gdkpixbufoverlay", 0,
294 "debug category for gdkpixbufoverlay element");
298 gst_gdk_pixbuf_overlay_init (GstGdkPixbufOverlay * overlay)
300 overlay->offset_x = 0;
301 overlay->offset_y = 0;
303 overlay->relative_x = 0.0;
304 overlay->relative_y = 0.0;
306 overlay->coef_x = 0.0;
307 overlay->coef_y = 0.0;
309 overlay->positioning_mode = DEFAULT_POSITIONING_MODE;
311 overlay->overlay_width = 0;
312 overlay->overlay_height = 0;
314 overlay->alpha = 1.0;
316 overlay->pixbuf = NULL;
320 gst_gdk_pixbuf_overlay_set_property (GObject * object, guint property_id,
321 const GValue * value, GParamSpec * pspec)
323 GstGdkPixbufOverlay *overlay = GST_GDK_PIXBUF_OVERLAY (object);
325 GST_OBJECT_LOCK (overlay);
327 switch (property_id) {
330 g_free (overlay->location);
331 overlay->location = g_value_dup_string (value);
332 if (!gst_gdk_pixbuf_overlay_load_image (overlay, &err)) {
333 GST_ERROR_OBJECT (overlay, "Could not load overlay image: %s",
340 GdkPixbuf *pixbuf = g_value_get_object (value);
342 if (overlay->pixbuf != NULL)
343 g_object_unref (overlay->pixbuf);
345 overlay->pixbuf = g_object_ref (pixbuf);
346 gst_gdk_pixbuf_overlay_set_pixbuf (overlay, g_object_ref (pixbuf));
348 overlay->pixbuf = NULL;
349 gst_buffer_replace (&overlay->pixels, NULL);
354 overlay->offset_x = g_value_get_int (value);
355 overlay->update_composition = TRUE;
358 overlay->offset_y = g_value_get_int (value);
359 overlay->update_composition = TRUE;
361 case PROP_RELATIVE_X:
362 overlay->relative_x = g_value_get_double (value);
363 overlay->update_composition = TRUE;
365 case PROP_RELATIVE_Y:
366 overlay->relative_y = g_value_get_double (value);
367 overlay->update_composition = TRUE;
370 overlay->coef_x = g_value_get_double (value);
371 overlay->update_composition = TRUE;
374 overlay->coef_y = g_value_get_double (value);
375 overlay->update_composition = TRUE;
377 case PROP_OVERLAY_WIDTH:
378 overlay->overlay_width = g_value_get_int (value);
379 overlay->update_composition = TRUE;
381 case PROP_OVERLAY_HEIGHT:
382 overlay->overlay_height = g_value_get_int (value);
383 overlay->update_composition = TRUE;
386 overlay->alpha = g_value_get_double (value);
387 overlay->update_composition = TRUE;
389 case PROP_POSITIONING_MODE:
390 overlay->positioning_mode = g_value_get_enum (value);
391 overlay->update_composition = TRUE;
394 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
398 GST_OBJECT_UNLOCK (overlay);
402 gst_gdk_pixbuf_overlay_get_property (GObject * object, guint property_id,
403 GValue * value, GParamSpec * pspec)
405 GstGdkPixbufOverlay *overlay = GST_GDK_PIXBUF_OVERLAY (object);
407 GST_OBJECT_LOCK (overlay);
409 switch (property_id) {
411 g_value_set_string (value, overlay->location);
414 g_value_set_object (value, overlay->pixbuf);
417 g_value_set_int (value, overlay->offset_x);
420 g_value_set_int (value, overlay->offset_y);
422 case PROP_RELATIVE_X:
423 g_value_set_double (value, overlay->relative_x);
425 case PROP_RELATIVE_Y:
426 g_value_set_double (value, overlay->relative_y);
429 g_value_set_double (value, overlay->coef_x);
432 g_value_set_double (value, overlay->coef_y);
434 case PROP_OVERLAY_WIDTH:
435 g_value_set_int (value, overlay->overlay_width);
437 case PROP_OVERLAY_HEIGHT:
438 g_value_set_int (value, overlay->overlay_height);
441 g_value_set_double (value, overlay->alpha);
443 case PROP_POSITIONING_MODE:
444 g_value_set_enum (value, overlay->positioning_mode);
447 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
451 GST_OBJECT_UNLOCK (overlay);
455 gst_gdk_pixbuf_overlay_finalize (GObject * object)
457 GstGdkPixbufOverlay *overlay = GST_GDK_PIXBUF_OVERLAY (object);
459 g_free (overlay->location);
460 overlay->location = NULL;
462 G_OBJECT_CLASS (gst_gdk_pixbuf_overlay_parent_class)->finalize (object);
466 gst_gdk_pixbuf_overlay_load_image (GstGdkPixbufOverlay * overlay, GError ** err)
470 pixbuf = gdk_pixbuf_new_from_file (overlay->location, err);
475 gst_gdk_pixbuf_overlay_set_pixbuf (overlay, pixbuf);
479 /* Takes ownership of pixbuf; call with OBJECT_LOCK */
481 gst_gdk_pixbuf_overlay_set_pixbuf (GstGdkPixbufOverlay * overlay,
484 GstVideoMeta *video_meta;
486 gint width, height, stride, w, h, plane;
488 if (!gdk_pixbuf_get_has_alpha (pixbuf)) {
489 GdkPixbuf *alpha_pixbuf;
491 /* FIXME: we could do this much more efficiently ourselves below, but
492 * we're lazy for now */
493 /* FIXME: perhaps expose substitute_color via properties */
494 alpha_pixbuf = gdk_pixbuf_add_alpha (pixbuf, FALSE, 0, 0, 0);
495 g_object_unref (pixbuf);
496 pixbuf = alpha_pixbuf;
499 width = gdk_pixbuf_get_width (pixbuf);
500 height = gdk_pixbuf_get_height (pixbuf);
501 stride = gdk_pixbuf_get_rowstride (pixbuf);
502 pixels = gdk_pixbuf_get_pixels (pixbuf);
504 /* the memory layout in GdkPixbuf is R-G-B-A, we want:
505 * - B-G-R-A on little-endian platforms
506 * - A-R-G-B on big-endian platforms
508 for (h = 0; h < height; ++h) {
509 p = pixels + (h * stride);
510 for (w = 0; w < width; ++w) {
513 /* R-G-B-A ==> B-G-R-A */
518 if (G_BYTE_ORDER == G_BIG_ENDIAN) {
519 /* B-G-R-A ==> A-R-G-B */
520 /* we can probably assume sane alignment */
521 *((guint32 *) p) = GUINT32_SWAP_LE_BE (*((guint32 *) p));
529 gst_buffer_unref (overlay->pixels);
531 /* assume we have row padding even for the last row */
532 /* transfer ownership of pixbuf to the buffer */
533 overlay->pixels = gst_buffer_new_wrapped_full (GST_MEMORY_FLAG_READONLY,
534 pixels, height * stride, 0, height * stride, pixbuf,
535 (GDestroyNotify) g_object_unref);
537 video_meta = gst_buffer_add_video_meta (overlay->pixels,
538 GST_VIDEO_FRAME_FLAG_NONE, GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_RGB,
541 for (plane = 0; plane < video_meta->n_planes; ++plane)
542 video_meta->stride[plane] = stride;
544 overlay->update_composition = TRUE;
546 GST_INFO_OBJECT (overlay, "Updated pixbuf, %d x %d", width, height);
550 gst_gdk_pixbuf_overlay_start (GstBaseTransform * trans)
552 GstGdkPixbufOverlay *overlay = GST_GDK_PIXBUF_OVERLAY (trans);
555 if (overlay->location != NULL) {
556 if (!gst_gdk_pixbuf_overlay_load_image (overlay, &err))
557 goto error_loading_image;
559 gst_base_transform_set_passthrough (trans, FALSE);
561 GST_WARNING_OBJECT (overlay, "no image location set, doing nothing");
562 gst_base_transform_set_passthrough (trans, TRUE);
570 GST_ELEMENT_ERROR (overlay, RESOURCE, OPEN_READ,
571 ("Could not load overlay image."), ("%s", err->message));
578 gst_gdk_pixbuf_overlay_stop (GstBaseTransform * trans)
580 GstGdkPixbufOverlay *overlay = GST_GDK_PIXBUF_OVERLAY (trans);
583 gst_video_overlay_composition_unref (overlay->comp);
584 overlay->comp = NULL;
587 gst_buffer_replace (&overlay->pixels, NULL);
593 gst_gdk_pixbuf_overlay_set_info (GstVideoFilter * filter, GstCaps * incaps,
594 GstVideoInfo * in_info, GstCaps * outcaps, GstVideoInfo * out_info)
596 GST_INFO_OBJECT (filter, "caps: %" GST_PTR_FORMAT, incaps);
601 gst_gdk_pixbuf_overlay_update_composition (GstGdkPixbufOverlay * overlay)
603 GstGdkPixbufPositioningMode positioning_mode;
604 GstVideoOverlayComposition *comp;
605 GstVideoOverlayRectangle *rect;
606 GstVideoMeta *overlay_meta;
607 gint x, y, width, height;
609 GST_VIDEO_INFO_WIDTH (&GST_VIDEO_FILTER (overlay)->in_info);
611 GST_VIDEO_INFO_HEIGHT (&GST_VIDEO_FILTER (overlay)->in_info);
614 gst_video_overlay_composition_unref (overlay->comp);
615 overlay->comp = NULL;
618 if (overlay->alpha == 0.0 || overlay->pixels == NULL)
621 overlay_meta = gst_buffer_get_video_meta (overlay->pixels);
623 positioning_mode = overlay->positioning_mode;
624 GST_DEBUG_OBJECT (overlay, "overlay positioning mode %d", positioning_mode);
626 width = overlay->overlay_width;
628 width = overlay_meta->width;
630 height = overlay->overlay_height;
632 height = overlay_meta->height;
634 if (positioning_mode == GST_GDK_PIXBUF_POSITIONING_PIXELS_ABSOLUTE) {
635 x = overlay->offset_x + (overlay->relative_x * width) +
636 (overlay->coef_x * video_width);
637 y = overlay->offset_y + (overlay->relative_y * height) +
638 (overlay->coef_y * video_height);
640 x = overlay->offset_x < 0 ?
641 video_width + overlay->offset_x - width +
642 (overlay->relative_x * video_width) :
643 overlay->offset_x + (overlay->relative_x * video_width);
644 y = overlay->offset_y < 0 ?
645 video_height + overlay->offset_y - height +
646 (overlay->relative_y * video_height) :
647 overlay->offset_y + (overlay->relative_y * video_height);
650 GST_DEBUG_OBJECT (overlay, "overlay image dimensions: %d x %d, alpha=%.2f",
651 overlay_meta->width, overlay_meta->height, overlay->alpha);
652 GST_DEBUG_OBJECT (overlay, "properties: x,y: %d,%d "
653 "(%g%%,%g%%) coef (%g%%,%g%%) - WxH: %dx%d",
654 overlay->offset_x, overlay->offset_y,
655 overlay->relative_x * 100.0, overlay->relative_y * 100.0,
656 overlay->coef_x * 100.0, overlay->coef_y * 100.0,
657 overlay->overlay_height, overlay->overlay_width);
658 GST_DEBUG_OBJECT (overlay, "overlay rendered: %d x %d @ %d,%d (onto %d x %d)",
659 width, height, x, y, video_width, video_height);
661 rect = gst_video_overlay_rectangle_new_raw (overlay->pixels,
662 x, y, width, height, GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
664 if (overlay->alpha != 1.0)
665 gst_video_overlay_rectangle_set_global_alpha (rect, overlay->alpha);
667 comp = gst_video_overlay_composition_new (rect);
668 gst_video_overlay_rectangle_unref (rect);
670 overlay->comp = comp;
674 gst_gdk_pixbuf_overlay_before_transform (GstBaseTransform * trans,
677 GstClockTime stream_time;
678 GstGdkPixbufOverlay *overlay = GST_GDK_PIXBUF_OVERLAY (trans);
679 gboolean set_passthrough = FALSE;
681 stream_time = gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME,
682 GST_BUFFER_TIMESTAMP (outbuf));
684 if (GST_CLOCK_TIME_IS_VALID (stream_time))
685 gst_object_sync_values (GST_OBJECT (trans), stream_time);
687 /* now properties have been sync'ed; maybe need to update composition */
688 GST_OBJECT_LOCK (overlay);
689 if (G_UNLIKELY (overlay->update_composition)) {
690 gst_gdk_pixbuf_overlay_update_composition (overlay);
691 overlay->update_composition = FALSE;
692 set_passthrough = TRUE;
694 GST_OBJECT_UNLOCK (overlay);
696 /* determine passthrough mode so the buffer is writable if needed
697 * when passed into _transform_ip */
698 if (G_UNLIKELY (set_passthrough))
699 gst_base_transform_set_passthrough (trans, overlay->comp == NULL);
703 gst_gdk_pixbuf_overlay_transform_frame_ip (GstVideoFilter * filter,
704 GstVideoFrame * frame)
706 GstGdkPixbufOverlay *overlay = GST_GDK_PIXBUF_OVERLAY (filter);
708 if (overlay->comp != NULL)
709 gst_video_overlay_composition_blend (overlay->comp, frame);