From: Lane Brooks Date: Tue, 11 Jan 2011 17:34:33 +0000 (-0700) Subject: textoverlay: converted AYUV to use 'A OVER B' alpha compositing X-Git-Tag: RELEASE-0.10.33~95 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e2150b11ff8a98a3b7081d8106bca496a91c6b2b;p=platform%2Fupstream%2Fgst-plugins-base.git textoverlay: converted AYUV to use 'A OVER B' alpha compositing 'A OVER B' compositing is explained at http://en.wikipedia.org/wiki/Alpha_compositing. Previously, overlaying text on a transparent background image left the text overlay also transparent. This pipeline shows such an example: gst-launch videotestsrc pattern=white ! video/x-raw-yuv,format=\(fourcc\)AYUV ! alpha alpha=0.0 ! textoverlay text=Testing auto-resize=False font-desc=60px ! videomixer ! ffmpegcolorspace ! autovideosink With this patch, text is composited "OVER" the background image and thus is visible regardless of the alpha of the background image. The overlay in the above pipeline works after applying this patch. --- diff --git a/ext/pango/gsttextoverlay.c b/ext/pango/gsttextoverlay.c index ca38dc1..6cd9db7 100644 --- a/ext/pango/gsttextoverlay.c +++ b/ext/pango/gsttextoverlay.c @@ -143,6 +143,12 @@ GST_DEBUG_CATEGORY (pango_debug); ret = (v0 * alpha + v1 * (255 - alpha)) / 255; \ } +#define OVER(ret, alphaA, Ca, alphaB, Cb, alphaNew) \ +{ \ + ret = (Ca * alphaA + Cb * alphaB * (255 - alphaA) / 255) / alphaNew; \ + ret = CLAMP (ret, 0, 255); \ +} + #if G_BYTE_ORDER == G_LITTLE_ENDIAN # define CAIRO_ARGB_A 3 # define CAIRO_ARGB_R 2 @@ -1617,7 +1623,7 @@ static inline void gst_text_overlay_blit_AYUV (GstTextOverlay * overlay, guint8 * rgb_pixels, gint xpos, gint ypos) { - int a, r, g, b; + int a, r, g, b, a1; int y, u, v; int i, j; int h, w; @@ -1649,14 +1655,17 @@ gst_text_overlay_blit_AYUV (GstTextOverlay * overlay, CAIRO_UNPREMULTIPLY (a, r, g, b); + // convert background to yuv COMP_Y (y, r, g, b); COMP_U (u, r, g, b); COMP_V (v, r, g, b); - a = (a * dest[0] + 128) >> 8; - BLEND (dest[1], a, y, dest[1]); - BLEND (dest[2], a, u, dest[2]); - BLEND (dest[3], a, v, dest[3]); + // preform text "OVER" background alpha compositing + a1 = a + (dest[0] * (255 - a)) / 255 + 1; // add 1 to prevent divide by 0 + OVER (dest[1], a, y, dest[0], dest[1], a1); + OVER (dest[2], a, u, dest[0], dest[2], a1); + OVER (dest[3], a, v, dest[0], dest[3], a1); + dest[0] = a1 - 1; // remove the temporary 1 we added pimage += 4; dest += 4;