#ifndef WELSVP_UTIL_H
#define WELSVP_UTIL_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <assert.h>
#include "typedef.h"
#include "memory.h"
#include "IWelsVP.h"
WELSVP_NAMESPACE_BEGIN
#define MAX_MBS_PER_FRAME 36864
#define MB_WIDTH_LUMA (16)
#define PESN (1e-6)
#define AQ_INT_MULTIPLY 10000000
#define AQ_TIME_INT_MULTIPLY 10000
#define AQ_QSTEP_INT_MULTIPLY 100
#define AQ_PESN 10
#define MB_TYPE_INTRA4x4 0x00000001
#define MB_TYPE_INTRA16x16 0x00000002
#define MB_TYPE_INTRA_PCM 0x00000004
#define MB_TYPE_INTRA (MB_TYPE_INTRA4x4 | MB_TYPE_INTRA16x16 | MB_TYPE_INTRA_PCM)
#define IS_INTRA(type) ((type)&MB_TYPE_INTRA)
#define WELS_MAX(x, y) ((x) > (y) ? (x) : (y))
#define WELS_MIN(x, y) ((x) < (y) ? (x) : (y))
#ifndef WELS_SIGN
#define WELS_SIGN(a) ((int32_t)(a) >> 31)
#endif
#ifndef WELS_ABS
#define WELS_ABS(a) ((WELS_SIGN(a) ^ (int32_t)(a)) - WELS_SIGN(a))
#endif
#define WELS_CLAMP(x, minv, maxv) WELS_MIN(WELS_MAX(x, minv), maxv)
#define ALIGNBYTES (16)
#define WelsCastFromPointer(p) (reinterpret_cast<intptr_t>(p))
#define WelsStaticCast(type, p) (static_cast<type>(p))
#define WelsDynamicCast(type, p) (dynamic_cast<type>(p))
#define GET_METHOD(x) ((x) & 0xff)
#define GET_SPECIAL(x) (((x) >> 8) & 0xff)
inline EMethods WelsVpGetValidMethod (int32_t a) {
int32_t iMethod = GET_METHOD (a);
return WelsStaticCast (EMethods, WELS_CLAMP (iMethod, METHOD_NULL + 1, METHOD_MASK - 1));
}
WELSVP_NAMESPACE_END
#endif