From aa3e64c71de7b072f421866c3c9c34b8969c1bd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Fri, 20 Jul 2018 16:25:02 +0300 Subject: [PATCH] compositor: Use 255 as maximum alpha instead of 256 255 will easily become 0 in the blending function as they expect the maximum value to be 255. Can be reproduce with gst-launch-1.0 videotestsrc pattern=ball ! c.sink_0 \ videotestsrc pattern=snow ! c.sink_1 \ compositor name=c \ sink_0::zorder=0 sink_1::zorder=1 sink_0::crossfade-ratio=0.5 \ background=black ! \ videoconvert ! xvimagesink crossfade-ratio +/- 0.001 makes it work correctly and the same happens at e.g. 0.25, 0.75, N*0.0625 https://bugzilla.gnome.org/show_bug.cgi?id=796846 --- gst/compositor/blend.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/gst/compositor/blend.c b/gst/compositor/blend.c index b36c164654..416f78cfb1 100644 --- a/gst/compositor/blend.c +++ b/gst/compositor/blend.c @@ -33,8 +33,6 @@ #include -#define BLEND(D,S,alpha) (((D) * (256 - (alpha)) + (S) * (alpha)) >> 8) - GST_DEBUG_CATEGORY_STATIC (gst_compositor_blend_debug); #define GST_CAT_DEFAULT gst_compositor_blend_debug @@ -61,7 +59,7 @@ method##_ ##name (GstVideoFrame * srcframe, gint xpos, gint ypos, \ dest_width = GST_VIDEO_FRAME_COMP_WIDTH (destframe, 0); \ dest_height = GST_VIDEO_FRAME_COMP_HEIGHT (destframe, 0); \ \ - s_alpha = CLAMP ((gint) (src_alpha * 256), 0, 256); \ + s_alpha = CLAMP ((gint) (src_alpha * 255), 0, 255); \ \ /* If it's completely transparent... we just return */ \ if (G_UNLIKELY (s_alpha == 0)) \ @@ -247,7 +245,7 @@ _blend_##format_name (const guint8 * src, guint8 * dest, \ return; \ } \ \ - b_alpha = CLAMP ((gint) (src_alpha * 256), 0, 256); \ + b_alpha = CLAMP ((gint) (src_alpha * 255), 0, 255); \ \ BLENDLOOP(dest, dest_stride, src, src_stride, b_alpha, src_width, src_height);\ } \ @@ -492,7 +490,7 @@ _blend_##format_name (const guint8 * src, guint8 * dest, \ return; \ } \ \ - b_alpha = CLAMP ((gint) (src_alpha * 256), 0, 256); \ + b_alpha = CLAMP ((gint) (src_alpha * 255), 0, 255); \ \ BLENDLOOP(dest, dest_stride, src, src_stride, b_alpha, src_width, src_height); \ } \ @@ -691,7 +689,7 @@ blend_##name (GstVideoFrame * srcframe, gint xpos, gint ypos, \ src_stride = GST_VIDEO_FRAME_COMP_STRIDE (srcframe, 0); \ dest_stride = GST_VIDEO_FRAME_COMP_STRIDE (destframe, 0); \ \ - b_alpha = CLAMP ((gint) (src_alpha * 256), 0, 256); \ + b_alpha = CLAMP ((gint) (src_alpha * 255), 0, 255); \ \ /* adjust src pointers for negative sizes */ \ if (xpos < 0) { \ @@ -857,7 +855,7 @@ blend_##name (GstVideoFrame * srcframe, gint xpos, gint ypos, \ src_stride = GST_VIDEO_FRAME_COMP_STRIDE (srcframe, 0); \ dest_stride = GST_VIDEO_FRAME_COMP_STRIDE (destframe, 0); \ \ - b_alpha = CLAMP ((gint) (src_alpha * 256), 0, 256); \ + b_alpha = CLAMP ((gint) (src_alpha * 255), 0, 255); \ \ xpos = GST_ROUND_UP_2 (xpos); \ \