[FFmpeg-devel] [PATCH][RFC] Lagarith Decoder.

Reimar Döffinger Reimar.Doeffinger
Sat Aug 15 10:53:46 CEST 2009


On Fri, Aug 14, 2009 at 09:15:04PM -0600, Nathan Caldwell wrote:
> 2009/8/14 Reimar D?ffinger <Reimar.Doeffinger at gmx.de>:
> > On Fri, Aug 14, 2009 at 02:25:44PM -0600, Nathan Caldwell wrote:
> What I used was just naive fixed point.
> 
> uint64_t scale_factor;
> scale_factor = ((uint64_t) cumulative_target << 32) / cumul_prob;
> 
> for (i = 1; i < 257; i++) {
>     rac->prob[i] = (unsigned int) ((rac->prob[i] * scale_factor) >> 32);

Speedwise it is horrible, but an exact way should be:
rac->prob[i] = ((uint64_t)rac->prob[i] << (av_log2(cumul_prob-1)+1)) / cumul_prob;
A few notes though:
I think it is worth adding a skip in case prob is 0, as well as checking
if cumul_prob is already a power of two (the later is a simple
if (!(cumul_prob & (cumul_prob - 1))) and allows simplifying
the av_log2 by removing the -1).



More information about the ffmpeg-devel mailing list