[FFmpeg-devel] [PATCH] vf_overlay: add support to RGBA packed input and output
mark at mdsh.com
Sun Oct 30 12:45:07 CET 2011
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
>>>> d[da] = ( (d[da]<< 8) + (256 - d[da]) * s[sa] )>> 8;
>>> 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
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.
More information about the ffmpeg-devel