[XviD-devel]

Christoph Lampert chl at math.uni-bonn.de
Fri Mar 28 09:31:40 CET 2003


On Fri, 28 Mar 2003, suxen_drol wrote:
> >    I'm reading the source code of xvidcore-0.9.1. There is something in src\motion\sad.c making me a little puzzled.Can anyone help me?
> >    The part annoying me is listed here:
> >    int pixel = (ptr_ref1[i] + ptr_ref2[i] + 1) / 2;
> > 
> >    if (pixel < 0) {
> >     pixel = 0;
> >    } else if (pixel > 255) {
> >     pixel = 255;
> >    }
> >     Since ptr_ref1[i] and ptr_ref2[i] are two unsigned byte,why   is it possible that pixel < 0 or pixel > 255 ?Thanks very much
> 
> this is bounds check indeed unnecessary.
> (255+255+1) / 2 = 255

Maybe it's just to test compilers' intelligence ;-) 

Just remove the check, and add a commment that overflow isn't possible. 
But this routine looks like it'll be replaced by an optimized version 
anyway as soon as I finished my exams. 

Optimizing C is so rewarding ;-) Speedup of 2 to 10 just by 5 minutes 
work...

gruel 





More information about the XviD-devel mailing list