]> git.sesse.net Git - ffmpeg/commitdiff
Add av_clip_uintp2() function
authorMans Rullgard <mans@mansr.com>
Fri, 13 May 2011 15:39:17 +0000 (16:39 +0100)
committerRonald S. Bultje <rsbultje@gmail.com>
Fri, 13 May 2011 20:45:24 +0000 (16:45 -0400)
Signed-off-by: Mans Rullgard <mans@mansr.com>
libavcodec/vp8.c
libavutil/common.h

index dc7eb2121ae5869aa592ca81ab4c5ebd0081d27e..38f38b7cb30274fd08fee72325806c14e33eb2b0 100644 (file)
@@ -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) {
index e5c1dfdff5c3418e283dc89241e98f4fdf40b20d..a985fa48045d52606de3fbb193c4f653aeb82501 100644 (file)
@@ -169,6 +169,18 @@ static av_always_inline av_const int32_t av_clipl_int32_c(int64_t a)
     else                                         return 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
@@ -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