vf_ass: Optimize alpha multiply
commit4dab4347f5d7bb3642a2c5918fc29855f8f62482
authorUoti Urpala <uau@symbol.nonexistent.invalid>
Tue, 22 Jul 2008 22:47:30 +0000 (23 01:47 +0300)
committerUoti Urpala <uau@symbol.nonexistent.invalid>
Tue, 22 Jul 2008 23:05:55 +0000 (23 02:05 +0300)
tree4f1f572dcd5cfee177658d28de3e1c3ce015dd65
parent2d4656e070697cebe8cb66568b3e8dd8919b5eed
vf_ass: Optimize alpha multiply

The effect of alpha blending was calculated as
color = orig_color * alpha / 255
where alpha and color range from 0 to 255.
Change this to
color = (orig_color * alpha + 255) / 256
where the "/ 256" can be expressed as a shift whereas the compiler
would probably generate a multiply+shift for the original "/ 255".
This formula gives a result that is too high by 1 for some inputs.
However it gives the exact result if alpha is 0 or 255 which is
probably the case where small errors would matter most.
libmpcodecs/vf_ass.c