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

Nicolas George nicolas.george at normalesup.org
Mon Oct 31 12:38:12 CET 2011


Le decadi 10 brumaire, an CCXX, Mark Himsley a écrit :
> While I was testing and optimising the code I originally sent on
> 2011-03-13 I went through a number of different equations but failed
> to find ((x+128)*257)>>16.

For future reference, this trick comes from the following numerical
"coincidence": (256 - 1) (256 + 1) = 256² - 1
Therefore, x / 255 = x × 257 / (256² - 1) =~ x × 257 / 256²

Of course, this is no coincidence at all. It is related to power series: 1 /
(1-t) = 1 + t + O(t), here with t = 1/256: (256/255)x =~ (257/256)x.

Both ways to look at the formula can lead to similar tricks in other
situations.

Of course, the +128 is just the +0.5 in round(x) = floor(x + 0.5).

Regards,

-- 
  Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20111031/c322cf57/attachment.asc>


More information about the ffmpeg-devel mailing list