From 45a1b86a0504c598b542b676f028e743bba7a2ba Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Tue, 22 Jun 2010 19:11:33 +0000 Subject: [PATCH] Add av_clip_int8(), used in the upcoming VP8 decoder. Originally committed as revision 23713 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavutil/common.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libavutil/common.h b/libavutil/common.h index ba67b4a559..ee4417558c 100644 --- a/libavutil/common.h +++ b/libavutil/common.h @@ -122,6 +122,17 @@ static inline av_const uint8_t av_clip_uint8(int a) else return a; } +/** + * Clips a signed integer value into the -128,127 range. + * @param a value to clip + * @return clipped value + */ +static inline av_const int8_t av_clip_int8(int a) +{ + if ((a+0x80) & ~0xFF) return (a>>31) ^ 0x7F; + else return a; +} + /** * Clips a signed integer value into the 0-65535 range. * @param a value to clip