[MPlayer-dev-eng] Enhanced cropdetect code

Reimar Döffinger Reimar.Doeffinger at stud.uni-karlsruhe.de
Sun Jul 6 22:47:35 CEST 2008


Hello,
On Sun, Jul 06, 2008 at 03:01:48PM -0500, Roger Heflin wrote:
> but also requires a number of FP operations to do properly so is very 
> likely slower than the original cropdetect.

It certainly does not require them. Now firstly, calculation log 2 via
log 10 and a division is really wasteful, there is a log2 for a good
reason (not to mention that the division should not be in the inner
loop).
Secondly, there should be no need for any float operations, if my quick
calculations are correct, you can sum over hist[i] * av_log2(hist[i])
and subtract len * av_log2(len) and divide the whole thing by len as the
last step in floating point if necessary.
(formula is
SUM[1,n]{ (h[i]/len) * log2(h[i]/len) }
= 1/len * SUM[1,n]{ h[i] * log2(h[i]/len) }
= 1/len * SUM[1,n]{ h[i] * (log2(h[i]) - log2(len)) }
= 1/len * (SUM[1,n]{ h[i] * log2(h[i]) } - SUM[1,n] { h[i] * log2(len) })
= 1/len * (SUM[1,n]{ h[i] * log2(h[i]) } - log2(len) * SUM[1,n] { h[i] })
= 1/len * (SUM[1,n]{ h[i] * log2(h[i]) } - log2(len) * len )

Also, instead of the loops setting stuff to 0, use memset.

Greetings,
Reimar Döffinger



More information about the MPlayer-dev-eng mailing list