diff options
author | Mans Rullgard <mans@mansr.com> | 2011-05-13 16:39:17 +0100 |
---|---|---|
committer | Ronald S. Bultje <rsbultje@gmail.com> | 2011-05-13 16:45:24 -0400 |
commit | 1550f45a8928f31c48f770b5ddf860c99a57687e (patch) | |
tree | ed16b9464a7955f6ed9e460e7127ebdfe360d394 /libavutil/common.h | |
parent | 2c9a5172d328259c5d76e588f2ddc12f439ffcd0 (diff) | |
download | ffmpeg-1550f45a8928f31c48f770b5ddf860c99a57687e.tar.gz |
Add av_clip_uintp2() function
Signed-off-by: Mans Rullgard <mans@mansr.com>
Diffstat (limited to 'libavutil/common.h')
-rw-r--r-- | libavutil/common.h | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/libavutil/common.h b/libavutil/common.h index e5c1dfdff5..a985fa4804 100644 --- a/libavutil/common.h +++ b/libavutil/common.h @@ -170,6 +170,18 @@ static av_always_inline av_const int32_t av_clipl_int32_c(int64_t a) } /** + * Clip a signed integer to an unsigned power of two range. + * @param a value to clip + * @param p bit position to clip at + * @return clipped value + */ +static av_always_inline av_const unsigned av_clip_uintp2_c(int a, int p) +{ + if (a & ~((1<<p) - 1)) return -a >> 31 & ((1<<p) - 1); + else return a; +} + +/** * Clip a float value into the amin-amax range. * @param a value to clip * @param amin minimum value of the clip range @@ -362,6 +374,9 @@ static av_always_inline av_const int av_popcount_c(uint32_t x) #ifndef av_clipl_int32 # define av_clipl_int32 av_clipl_int32_c #endif +#ifndef av_clip_uintp2 +# define av_clip_uintp2 av_clip_uintp2_c +#endif #ifndef av_clipf # define av_clipf av_clipf_c #endif |