[FFmpeg-devel] [PATCH] [SOCIS] [WIP] libavfilter: add vf_hue.c

Nicolas George nicolas.george at normalesup.org
Mon Aug 6 17:33:54 CEST 2012


Le decadi 20 thermidor, an CCXX, Stefano Sabatini a écrit :
> > +            if (new_u & 768)
> > +                new_u = (-new_u) >> 31;
> > +            if (new_v & 768)
> > +                new_v = (-new_v) >> 31;
> I'm not sure about this: these should handle overflow (right now you
> have 16 bits values which need to be expressed in the 8-bits range).
> 
> Indeed what this seems to do is to convert the overflowing values to
> 0, but maybe I'm wrong.

As far as I understand it:

If new_u is between 256 and 1023 or between -1 and -768, new_u & 768 is not
0, so this is a cheap test for overflows in both directions, as long as the
overflow is not too large.

And then, because of the sign extensions:

new_u = 256 + 42 -> (-new_u) >> 31 = (int)0xFFFFFFFF;
new_u =   0 - 42 -> (-new_u) >> 31 = (int)0;

It relies on two's complement arithmetic, as, quoting the C standard:

# [ E1 >> E2 ] If E1 has a signed type and a negative value, the resulting
# value is implementation-defined.

Regards,

-- 
  Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120806/59a257df/attachment.asc>


More information about the ffmpeg-devel mailing list