From 32679e1826267a7b63a69bfbc7f0f4c9c6addb15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Sat, 24 Mar 2012 19:47:10 +0000 Subject: [PATCH] video: overlay-composition: some minor clean-ups extract_alpha and apply_global alpha always return TRUE really, so just do away with the return value. Convert a g_return_if_fail() into a g_assert(), since this is only to check internal consistency and not a guard for public API. Add some locking. https://bugzilla.gnome.org/show_bug.cgi?id=668483 --- .../gst/video/video-overlay-composition.c | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/gst-libs/gst/video/video-overlay-composition.c b/gst-libs/gst/video/video-overlay-composition.c index a1de051a46..f9f90c5bb7 100644 --- a/gst-libs/gst/video/video-overlay-composition.c +++ b/gst-libs/gst/video/video-overlay-composition.c @@ -941,7 +941,7 @@ gst_video_overlay_rectangle_unpremultiply (GstBlendVideoFormatInfo * info) } -static gboolean +static void gst_video_overlay_rectangle_extract_alpha (GstVideoOverlayRectangle * rect) { guint8 *src, *dst; @@ -954,30 +954,29 @@ gst_video_overlay_rectangle_extract_alpha (GstVideoOverlayRectangle * rect) rect->initial_alpha = g_malloc (alpha_size); src = GST_BUFFER_DATA (rect->pixels); dst = rect->initial_alpha; + /* FIXME we're accessing possibly uninitialised bytes from the row padding */ while (offset < alpha_size) { dst[offset] = src[offset * 4 + ARGB_A]; ++offset; } - return TRUE; } -static gboolean +static void gst_video_overlay_rectangle_apply_global_alpha (GstVideoOverlayRectangle * rect, float global_alpha) { guint8 *src, *dst; guint offset = 0; - g_return_val_if_fail (!(rect->applied_global_alpha != 1.0 - && rect->initial_alpha == NULL), FALSE); + g_assert (!(rect->applied_global_alpha != 1.0 + && rect->initial_alpha == NULL)); if (global_alpha == rect->applied_global_alpha) - return TRUE; + return; - if (rect->initial_alpha == NULL && - !gst_video_overlay_rectangle_extract_alpha (rect)) - return FALSE; + if (rect->initial_alpha == NULL) + gst_video_overlay_rectangle_extract_alpha (rect); src = rect->initial_alpha; rect->pixels = gst_buffer_make_writable (rect->pixels); @@ -1001,7 +1000,6 @@ gst_video_overlay_rectangle_apply_global_alpha (GstVideoOverlayRectangle * rect, } rect->applied_global_alpha = global_alpha; - return TRUE; } static GstBuffer * @@ -1112,17 +1110,18 @@ gst_video_overlay_rectangle_get_pixels_argb_internal (GstVideoOverlayRectangle * GST_RECTANGLE_UNLOCK (rectangle); done: + + GST_RECTANGLE_LOCK (rectangle); if (apply_global_alpha && scaled_rect->applied_global_alpha != rectangle->global_alpha) { - if (!gst_video_overlay_rectangle_apply_global_alpha (scaled_rect, - rectangle->global_alpha)) - return NULL; /* return original data? */ + gst_video_overlay_rectangle_apply_global_alpha (scaled_rect, + rectangle->global_alpha); gst_video_overlay_rectangle_set_global_alpha (scaled_rect, rectangle->global_alpha); } else if (revert_global_alpha && scaled_rect->applied_global_alpha != 1.0) { - if (!gst_video_overlay_rectangle_apply_global_alpha (scaled_rect, 1.0)) - return NULL; /* return original data? */ + gst_video_overlay_rectangle_apply_global_alpha (scaled_rect, 1.0); } + GST_RECTANGLE_UNLOCK (rectangle); *stride = scaled_rect->stride; return scaled_rect->pixels;