[MPlayer-dev-eng] [PATCH] vf_ass: avoid a division

Reimar Döffinger Reimar.Doeffinger at gmx.de
Thu Sep 16 21:17:46 CEST 2010


On Thu, Sep 16, 2010 at 06:54:59PM +0200, Nicolas George wrote:
> The histograms shows the difference between the exact value of i×j/255 and
> the rounded value using different methods, for all pairs in [0;255]². The
> mean and standard deviation are written on the right.
> 
> Obviously, the second one is the worst. Unfortunately, this is the one
> currently in use.

Changing the formula as part of an optimization is suboptimal.
You can calculate / 255 with identical values within the range like this:

(x + (x >> 8) + 1) >> 8

(gives the same value as x / 255 for x in [0; 256*256-2])
You can then easily and without speed loss change this to the second behaviour
by replacing + 1 by + 128

> - Version of the same with the reindent made.
>   (If I apply these changes myself, I'll stick to the rules and apply the
>   reindent separately.)

I think the
if (!k)
    continue;
suggestion someone made was a good one, I usually consider it
good for readability to avoid extra indentation levels.


More information about the MPlayer-dev-eng mailing list