]> git.sesse.net Git - ffmpeg/blobdiff - libavutil/common.h
Merge commit '8ac0f6767bf63d3e6b308ee6648ff02598b81e03'
[ffmpeg] / libavutil / common.h
index 3e3baab3a13d4bdd03aabf071a41c5b3cd47c327..03a2354db4a30974fa08ef5a55e95250a6dd759c 100644 (file)
@@ -34,7 +34,9 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+
 #include "attributes.h"
+#include "version.h"
 #include "libavutil/avconfig.h"
 
 #if AV_HAVE_BIGENDIAN
 #define FFALIGN(x, a) (((x)+(a)-1)&~((a)-1))
 
 /* misc math functions */
-extern const uint8_t ff_log2_tab[256];
 
 /**
  * Reverse the order of the bits of an 8-bits unsigned integer.
  */
-extern const uint8_t av_reverse[256];
-
-static av_always_inline av_const int av_log2_c(unsigned int v)
-{
-    int n = 0;
-    if (v & 0xffff0000) {
-        v >>= 16;
-        n += 16;
-    }
-    if (v & 0xff00) {
-        v >>= 8;
-        n += 8;
-    }
-    n += ff_log2_tab[v];
-
-    return n;
-}
-
-static av_always_inline av_const int av_log2_16bit_c(unsigned int v)
-{
-    int n = 0;
-    if (v & 0xff00) {
-        v >>= 8;
-        n += 8;
-    }
-    n += ff_log2_tab[v];
-
-    return n;
-}
+#if FF_API_AV_REVERSE
+extern attribute_deprecated const uint8_t av_reverse[256];
+#endif
 
 #ifdef HAVE_AV_CONFIG_H
 #   include "config.h"
@@ -105,6 +80,14 @@ static av_always_inline av_const int av_log2_16bit_c(unsigned int v)
 /* Pull in unguarded fallback defines at the end of this file. */
 #include "common.h"
 
+#ifndef av_log2
+av_const int av_log2(unsigned v);
+#endif
+
+#ifndef av_log2_16bit
+av_const int av_log2_16bit(unsigned v);
+#endif
+
 /**
  * Clip a signed integer value into the amin-amax range.
  * @param a value to clip
@@ -119,6 +102,20 @@ static av_always_inline av_const int av_clip_c(int a, int amin, int amax)
     else               return a;
 }
 
+/**
+ * Clip a signed 64bit integer value into the amin-amax range.
+ * @param a value to clip
+ * @param amin minimum value of the clip range
+ * @param amax maximum value of the clip range
+ * @return clipped value
+ */
+static av_always_inline av_const int64_t av_clip64_c(int64_t a, int64_t amin, int64_t amax)
+{
+    if      (a < amin) return amin;
+    else if (a > amax) return amax;
+    else               return a;
+}
+
 /**
  * Clip a signed integer value into the 0-255 range.
  * @param a value to clip
@@ -386,18 +383,15 @@ static av_always_inline av_const int av_popcount64_c(uint64_t x)
  * to ensure they are immediately available in intmath.h.
  */
 
-#ifndef av_log2
-#   define av_log2       av_log2_c
-#endif
-#ifndef av_log2_16bit
-#   define av_log2_16bit av_log2_16bit_c
-#endif
 #ifndef av_ceil_log2
 #   define av_ceil_log2     av_ceil_log2_c
 #endif
 #ifndef av_clip
 #   define av_clip          av_clip_c
 #endif
+#ifndef av_clip64
+#   define av_clip64        av_clip64_c
+#endif
 #ifndef av_clip_uint8
 #   define av_clip_uint8    av_clip_uint8_c
 #endif