# [FFmpeg-devel] [PATCH] vf_overlay: add support to RGBA packed input and output

Stefano Sabatini stefasab at gmail.com
Sun Oct 30 22:43:58 CET 2011

On date Sunday 2011-10-30 11:45:07 +0000, Mark Himsley encoded:
> On 30/10/2011 00:29, Stefano Sabatini wrote:
> >On date Saturday 2011-10-29 17:27:16 +0100, Mark Himsley encoded:
> >>On 29/10/2011 16:26, Michael Niedermayer wrote:
> >>>On Sat, Oct 29, 2011 at 04:47:41PM +0200, Stefano Sabatini wrote:
> >>
> >>>>Regarding the second patch, I kept Mark's code but after some time
> >>>>spent tinkering on it I couldn't figure out the meaning of the
> >>>>equation:
> >>>
> >>>>     d[da] = ( (d[da]<<   8) + (256 - d[da]) * s[sa] )>>   8;
> >>>
> >>>correcter:
> >>>d += ((255 - d) * s + 128) / 255;
> >>>
> >>>and /255 can be done by multiplication and shift
> >>
> >>Sure, Michael is right.
> >
> >What I was asking, was an explanation of the formula, I would naively
> >expect something like:
> >main_alpha = (1-alpha) * main_alpha + alpha * overlay_alpha
> >
> >like for the other components.
> >
> >Now the equation I see is something along the lines of an obfuscated
> >version of:
> >main_alpha += (1-main_alpha) * overlay_alpha
> >
> >Can you give explanation of it?
>
> Sorry for my misunderstanding.
>
> Yes, in this form of overlay, the calculation of alpha is:
> output_alpha = main_alpha + (1-main_alpha) * overlay_alpha
>
> which, with the reuse of buffers in ffmpeg filter chains turns into:
> main_alpha += (1-main_alpha) * overlay_alpha
>
> The reason for this calculation is that in this form of overlay,
> alpha combination is proportionality additive. For every pixel you
> can never output less alpha than you put in on either the main or
> the overlay inputs. So:
>
>
> main    overlay output
> 0.5     0       0.5
> 0       0.5     0.5
> 0.5     0.5     0.75
>
> http://en.wikipedia.org/wiki/Alpha_compositing agrees with this
> equation for output alpha.

Thank you, that was exactly the kind of explanation I was looking for.

Patch updated.
--
FFmpeg = Fantastic & Fantastic Minimal Portentous Elastic Guide
-------------- next part --------------
A non-text attachment was scrubbed...