[FFmpeg-devel] [PATCH] Fast half-float to float conversion
Reimar Döffinger
Reimar.Doeffinger
Wed Jul 1 13:52:42 CEST 2009
On Wed, Jul 01, 2009 at 01:15:35PM +0200, Reimar D?ffinger wrote:
> On Wed, Jul 01, 2009 at 12:52:08PM +0200, Jimmy Christensen wrote:
> > I modified for the purpose I need it for. Converting from half-float to
> > unsigned int.
> >
> > uint16_t av_halflt2uint(uint16_t v){
> > uint16_t nosign = v+v;
> > if (v>>15)
> > return 0; // negatives are not interesting so clamp it to 0
> > if (nosign >= 0xfc00)
> > return 65535; // Anything above 1 should be clamped to 65535
> > if (nosign < 0x0200)
> > return ldexp((v&0x3ff), 1-25)*65535; // denormal or 0
> > return ldexp((v&0x3ff) + (1<<10), (v>>10&0x1f)-25)*65535;
> > }
>
> Btw. a probably much faster but +-1 inaccurate version is:
> int exp = v >> 10;
> if ((v & 0x8000) || !exp)
> return 0;
More accurate would be:
if (v & 0x8000) return 0;
if (!exp) return (v>>9)&1;
Rounding could also be added, but that might just be overkill.
More information about the ffmpeg-devel
mailing list