#ifndef AVUTIL_COMMON_H
#define AVUTIL_COMMON_H
-#include <ctype.h>
#include <errno.h>
#include <inttypes.h>
#include <limits.h>
#include <math.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define FFALIGN(x, a) (((x)+(a)-1)&~((a)-1))
/* misc math functions */
-extern const uint8_t ff_log2_tab[256];
#if FF_API_AV_REVERSE
extern attribute_deprecated const uint8_t av_reverse[256];
#endif
-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;
-}
-
#ifdef HAVE_AV_CONFIG_H
# include "config.h"
# include "intmath.h"
/* 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
else return a;
}
+/**
+ * Clip a signed integer into the -(2^p),(2^p-1) range.
+ * @param a value to clip
+ * @param p bit position to clip at
+ * @return clipped value
+ */
+static av_always_inline av_const int av_clip_intp2_c(int a, int p)
+{
+ if ((a + (1 << p)) & ~((1 << (p + 1)) - 1))
+ return (a >> 31) ^ ((1 << p) - 1);
+ else
+ return a;
+}
+
/**
* Clip a signed integer to an unsigned power of two range.
* @param a value to clip
#define GET_UTF8(val, GET_BYTE, ERROR)\
val= GET_BYTE;\
{\
- int ones= 7 - av_log2(val ^ 255);\
- if(ones==1)\
+ uint32_t top = (val & 128) >> 1;\
+ if ((val & 0xc0) == 0x80)\
ERROR\
- val&= 127>>ones;\
- while(--ones > 0){\
+ while (val & top) {\
int tmp= GET_BYTE - 128;\
if(tmp>>6)\
ERROR\
val= (val<<6) + tmp;\
+ top <<= 5;\
}\
+ val &= (top << 1) - 1;\
}
/**
* 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_clipl_int32
# define av_clipl_int32 av_clipl_int32_c
#endif
+#ifndef av_clip_intp2
+# define av_clip_intp2 av_clip_intp2_c
+#endif
#ifndef av_clip_uintp2
# define av_clip_uintp2 av_clip_uintp2_c
#endif