[FFmpeg-cvslog] Add av_clip_uintp2() function

Mans Rullgard git at videolan.org
Sat May 14 02:29:49 CEST 2011


ffmpeg | branch: master | Mans Rullgard <mans at mansr.com> | Fri May 13 16:39:17 2011 +0100| [1550f45a8928f31c48f770b5ddf860c99a57687e] | committer: Ronald S. Bultje

Add av_clip_uintp2() function

Signed-off-by: Mans Rullgard <mans at mansr.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1550f45a8928f31c48f770b5ddf860c99a57687e
---

 libavcodec/vp8.c   |    4 +---
 libavutil/common.h |   15 +++++++++++++++
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/libavcodec/vp8.c b/libavcodec/vp8.c
index dc7eb21..38f38b7 100644
--- a/libavcodec/vp8.c
+++ b/libavcodec/vp8.c
@@ -1329,9 +1329,7 @@ static av_always_inline void filter_level_for_mb(VP8Context *s, VP8Macroblock *m
         filter_level += s->lf_delta.mode[mb->mode];
     }
 
-/* Like av_clip for inputs 0 and max, where max is equal to (2^n-1) */
-#define POW2CLIP(x,max) (((x) & ~max) ? (-(x))>>31 & max : (x));
-    filter_level = POW2CLIP(filter_level, 63);
+    filter_level = av_clip_uintp2(filter_level, 6);
 
     interior_limit = filter_level;
     if (s->filter.sharpness) {
diff --git a/libavutil/common.h b/libavutil/common.h
index e5c1dfd..a985fa4 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



More information about the ffmpeg-cvslog mailing list