video-blend: fix clipping of overlay images on the left

Fix clipping of images that are partially left of the video
surface, they would get clipped on the right side instead of
the left side, because the video unpack functions currently
ignore the x offset parameter. Work around that until that
is implemented.

https://bugzilla.gnome.org/show_bug.cgi?id=739281
This commit is contained in:
Tim-Philipp Müller 2014-11-16 16:34:31 +00:00
parent 2fae23c318
commit 9396d843d6

View file

@ -292,6 +292,9 @@ gst_video_blend (GstVideoFrame * dest,
ensure_debug_category (); ensure_debug_category ();
GST_LOG ("blend src %dx%d onto dest %dx%d @ %d,%d", src_width, src_height,
dest_width, dest_height, x, y);
/* In case overlay is completely outside the video, dont render */ /* In case overlay is completely outside the video, dont render */
if (x + src_width <= 0 || y + src_height <= 0 if (x + src_width <= 0 || y + src_height <= 0
|| x >= dest_width || y >= dest_height) { || x >= dest_width || y >= dest_height) {
@ -334,6 +337,7 @@ gst_video_blend (GstVideoFrame * dest,
/* If we're here we know that the overlay image fully or /* If we're here we know that the overlay image fully or
* partially overlaps with the video frame */ * partially overlaps with the video frame */
/* adjust src image for negative offsets */ /* adjust src image for negative offsets */
if (x < 0) { if (x < 0) {
src_xoff = -x; src_xoff = -x;
@ -347,7 +351,8 @@ gst_video_blend (GstVideoFrame * dest,
y = 0; y = 0;
} }
/* adjust width/height if the src is bigger than dest */ /* adjust width/height to render (i.e. clip source image) if the source
* image extends beyond the right or bottom border of the video surface */
if (x + src_width > dest_width) if (x + src_width > dest_width)
src_width = dest_width - x; src_width = dest_width - x;
@ -360,11 +365,13 @@ gst_video_blend (GstVideoFrame * dest,
dinfo->unpack_func (dinfo, 0, tmpdestline, dest->data, dest->info.stride, dinfo->unpack_func (dinfo, 0, tmpdestline, dest->data, dest->info.stride,
0, i, dest_width); 0, i, dest_width);
sinfo->unpack_func (sinfo, 0, tmpsrcline, src->data, src->info.stride, sinfo->unpack_func (sinfo, 0, tmpsrcline, src->data, src->info.stride,
src_xoff, src_yoff, src_width); 0, src_yoff, src_width + src_xoff);
matrix (tmpsrcline, src_width); matrix (tmpsrcline, src_width);
/* FIXME: use the x parameter of the unpack func once implemented */
tmpdestline += 4 * x; tmpdestline += 4 * x;
tmpsrcline += 4 * src_xoff;
/* Here dest and src are both either in AYUV or ARGB /* Here dest and src are both either in AYUV or ARGB
* TODO: Make the orc version working properly*/ * TODO: Make the orc version working properly*/
@ -405,7 +412,9 @@ gst_video_blend (GstVideoFrame * dest,
#undef BLENDLOOP #undef BLENDLOOP
/* undo previous pointer adjustments to pass right pointer to g_free */
tmpdestline -= 4 * x; tmpdestline -= 4 * x;
tmpsrcline -= 4 * src_xoff;
/* FIXME /* FIXME
* #if G_BYTE_ORDER == LITTLE_ENDIAN * #if G_BYTE_ORDER == LITTLE_ENDIAN