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

Stefano Sabatini stefasab at gmail.com
Sun Oct 30 01:29:26 CEST 2011


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?

And patch updated (waiting feedback for the RGB path patch).

> I tried to optimise out the /255, and my code was within 1 of the
> correct result and never altered the main alpha if the overlay alpha
> was 0.
> 
> In the intervening months between writing that code and Stefano
> moulding it into something workable, I have learnt that GCC is
> better at optimising maths than I am :)
-- 
FFmpeg = Free & Fascinating Most Practical Erroneous Gadget
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0003-vf_overlay-add-support-to-alpha-pre-multiplication-i.patch
Type: text/x-diff
Size: 3462 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20111030/ed284a1a/attachment.bin>


More information about the ffmpeg-devel mailing list