[Ffmpeg-devel] clip_uint8

Michael Niedermayer michaelni
Sun Apr 30 22:18:25 CEST 2006


Hi

On Sun, Apr 30, 2006 at 07:49:30PM +0200, Aurelien Jacobs wrote:
> On Fri, 28 Apr 2006 17:58:56 +0200
> Panagiotis Issaris <takis.issaris at uhasselt.be> wrote:
> 
> > Hi,
> > 
> > The clip function clips between the amin and amax values given as parameters, 
> > the clip_uint8 function, actually behaves a bit differently. The lower bound
> > is indeed 0 as the uint8 postfix in the name implies, but upper values (values 
> > higher then 255) are returned as -1. This works if the value which stores the 
> > returned value is uint8, but in other cases will cause strange behavior imho.
> > 
> > [...]
> > 
> > Changing the return type to uint8_t fixes this, or was the -1 
> > return value intentional?
> > 
> > diff --git a/libavutil/common.h b/libavutil/common.h
> > index d8f2c40..92c0d08 100644
> > --- a/libavutil/common.h
> > +++ b/libavutil/common.h
> > @@ -437,7 +437,7 @@ static inline int clip(int a, int amin,
> >          return a;
> >  }
> > 
> > -static inline int clip_uint8(int a)
> > +static inline uint8_t clip_uint8(int a)
> >  {
> >      if (a&(~255)) return (-a)>>31;
> >      else          return a;
> 
> I verified the issue, tested your patch and applied it.

i assume theres a missunderstanding, my reply that the code was ok ad not
slow meant the original code not that the change is acceptable, it
obviously is not without extensive benchmarking 
IMHO the behaviour should be documented and not changed or the cast to
uint8_t could be done only on the overflow side of the if()


[...]
-- 
Michael

In the past you could go to a library and read, borrow or copy any book
Today you'd get arrested for mere telling someone where the library is





More information about the ffmpeg-devel mailing list