[vlc-devel] [PATCH] blend: Handle alpha when blending in RGBA buffers

Felix Abecassis felix.abecassis at gmail.com
Thu Jan 16 15:54:55 CET 2014


2014/1/16 Steinar H. Gunderson <sgunderson at bigfoot.com>:
> On Thu, Jan 16, 2014 at 10:43:06PM +0800, Rémi Denis-Courmont wrote:
>> Is this patch not preventing unrolling? If so, performance will be rather
>> badly affected? (Yes, obviously this depends on the compiler)
>
> Well, obviously you won't know without testing, but ifs in general don't
> prevent unrolling. (Of course, the ideal case here is that the if is hoisted
> out of the loop.)
I don't think a "if" can prevent unrolling but it can prevent
(auto-)vectorization.
Anyway, has_alpha is a template parameter so there is no "if" left in
the generated code.

2014/1/16 Rémi Denis-Courmont <remi at remlab.net>:
> Is this patch not preventing unrolling? If so, performance will be rather
> badly affected? (Yes, obviously this depends on the compiler)
>
> --
> Rémi Denis-Courmont
> Sent from my NVIDIA Tegra-powered device
>
> ----- Reply message -----
> De : "Martin Storsjö" <martin at martin.st>
> Pour : <vlc-devel at videolan.org>
> Objet : [vlc-devel] [PATCH] blend: Handle alpha when blending in RGBA
> buffers
> Date : jeu., janv. 16, 2014 21:31
>
> Previously the alpha channel wasn't set at all, and the RGB
> components were blended without regard to the existing alpha
> value.
> ---
>  modules/video_filter/blend.cpp |   26 +++++++++++++++++++++++---
>  1 file changed, 23 insertions(+), 3 deletions(-)
>
> diff --git a/modules/video_filter/blend.cpp b/modules/video_filter/blend.cpp
> index 1f403fe..6552899 100644
> --- a/modules/video_filter/blend.cpp
> +++ b/modules/video_filter/blend.
> cpp
> @@ -297,9 +297,29 @@ public:
>      void merge(unsigned dx, const CPixel &spx, unsigned a, bool)
>      {
>          uint8_t *dst = getPointer(dx);
> -        ::merge(&dst[offset_r], spx.i, a);
> -        ::merge(&dst[offset_g], spx.j, a);
> -        ::merge(&dst[offset_b], spx.k, a);
> +        if (has_alpha) {
> +            // Handle different cases of existing alpha in the
> +            // destination buffer. If the existing alpha is 0,
> +            // the RGB components should be copied as is and
> +            // alpha set to 'a'. If the existing alpha is 255,
> +            // this should behave just as the non-alpha case below.
> +
> +            // First blend the existing color based on its
> +            // alpha with the incoming color.
> +            ::merge(&dst[offset_r], spx.i, 255 - dst[offset_a]);
> +            ::merge(&dst[offset_g], spx.j, 255 - dst[offset_a]);
> +            ::merge(&dst[offset_b], spx.k, 255 - dst[offset_a]);
> +            // Now blend in the new color on top with the normal formulas.
> +            ::merge(&dst[offset_r], spx.i, a);
> +            ::merge(&dst[offset_g], spx.j, a);
> +            ::merge(&dst[offset_b], spx.k, a);
> +            // Finally set dst_a = (255 * src_a + prev_a * (255 -
> src_a))/255.
> +            ::merge(&dst[offset_a], 255, a);
> +        } else {
> +            ::merge(&dst[offset_r], spx.i, a);
> +            ::merge(&dst[offset_g], spx.j, a);
> +            ::merge(&dst[offset_b], spx.k, a);
> +        }
>      }
>      void nextLine()
>      {
> --
> 1.7.9.4
>
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel
>
>
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel
>



-- 
Félix Abecassis
http://felix.abecassis.me



More information about the vlc-devel mailing list