1233d2500723e5594f3e7c70896ffeeef32b9c950ywan/* 2233d2500723e5594f3e7c70896ffeeef32b9c950ywan * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 3233d2500723e5594f3e7c70896ffeeef32b9c950ywan * 4233d2500723e5594f3e7c70896ffeeef32b9c950ywan * Use of this source code is governed by a BSD-style license 5233d2500723e5594f3e7c70896ffeeef32b9c950ywan * that can be found in the LICENSE file in the root of the source 6233d2500723e5594f3e7c70896ffeeef32b9c950ywan * tree. An additional intellectual property rights grant can be found 7233d2500723e5594f3e7c70896ffeeef32b9c950ywan * in the file PATENTS. All contributing project authors may 8233d2500723e5594f3e7c70896ffeeef32b9c950ywan * be found in the AUTHORS file in the root of the source tree. 9233d2500723e5594f3e7c70896ffeeef32b9c950ywan */ 10233d2500723e5594f3e7c70896ffeeef32b9c950ywan 11233d2500723e5594f3e7c70896ffeeef32b9c950ywan#ifndef VP9_COMMON_VP9_COMMON_H_ 12233d2500723e5594f3e7c70896ffeeef32b9c950ywan#define VP9_COMMON_VP9_COMMON_H_ 13233d2500723e5594f3e7c70896ffeeef32b9c950ywan 14233d2500723e5594f3e7c70896ffeeef32b9c950ywan/* Interface header for common constant data structures and lookup tables */ 15233d2500723e5594f3e7c70896ffeeef32b9c950ywan 16233d2500723e5594f3e7c70896ffeeef32b9c950ywan#include <assert.h> 17233d2500723e5594f3e7c70896ffeeef32b9c950ywan 18233d2500723e5594f3e7c70896ffeeef32b9c950ywan#include "./vpx_config.h" 19233d2500723e5594f3e7c70896ffeeef32b9c950ywan#include "vpx_mem/vpx_mem.h" 20233d2500723e5594f3e7c70896ffeeef32b9c950ywan#include "vpx/vpx_integer.h" 21233d2500723e5594f3e7c70896ffeeef32b9c950ywan#include "vp9/common/vp9_systemdependent.h" 22233d2500723e5594f3e7c70896ffeeef32b9c950ywan 23233d2500723e5594f3e7c70896ffeeef32b9c950ywan#ifdef __cplusplus 24233d2500723e5594f3e7c70896ffeeef32b9c950ywanextern "C" { 25233d2500723e5594f3e7c70896ffeeef32b9c950ywan#endif 26233d2500723e5594f3e7c70896ffeeef32b9c950ywan 27233d2500723e5594f3e7c70896ffeeef32b9c950ywan#define MIN(x, y) (((x) < (y)) ? (x) : (y)) 28233d2500723e5594f3e7c70896ffeeef32b9c950ywan#define MAX(x, y) (((x) > (y)) ? (x) : (y)) 29233d2500723e5594f3e7c70896ffeeef32b9c950ywan 30233d2500723e5594f3e7c70896ffeeef32b9c950ywan#define ROUND_POWER_OF_TWO(value, n) \ 31233d2500723e5594f3e7c70896ffeeef32b9c950ywan (((value) + (1 << ((n) - 1))) >> (n)) 32233d2500723e5594f3e7c70896ffeeef32b9c950ywan 33233d2500723e5594f3e7c70896ffeeef32b9c950ywan#define ALIGN_POWER_OF_TWO(value, n) \ 34233d2500723e5594f3e7c70896ffeeef32b9c950ywan (((value) + ((1 << (n)) - 1)) & ~((1 << (n)) - 1)) 35233d2500723e5594f3e7c70896ffeeef32b9c950ywan 36233d2500723e5594f3e7c70896ffeeef32b9c950ywan// Only need this for fixed-size arrays, for structs just assign. 37233d2500723e5594f3e7c70896ffeeef32b9c950ywan#define vp9_copy(dest, src) { \ 38233d2500723e5594f3e7c70896ffeeef32b9c950ywan assert(sizeof(dest) == sizeof(src)); \ 39233d2500723e5594f3e7c70896ffeeef32b9c950ywan vpx_memcpy(dest, src, sizeof(src)); \ 40233d2500723e5594f3e7c70896ffeeef32b9c950ywan } 41233d2500723e5594f3e7c70896ffeeef32b9c950ywan 42233d2500723e5594f3e7c70896ffeeef32b9c950ywan// Use this for variably-sized arrays. 43233d2500723e5594f3e7c70896ffeeef32b9c950ywan#define vp9_copy_array(dest, src, n) { \ 44233d2500723e5594f3e7c70896ffeeef32b9c950ywan assert(sizeof(*dest) == sizeof(*src)); \ 45233d2500723e5594f3e7c70896ffeeef32b9c950ywan vpx_memcpy(dest, src, n * sizeof(*src)); \ 46233d2500723e5594f3e7c70896ffeeef32b9c950ywan } 47233d2500723e5594f3e7c70896ffeeef32b9c950ywan 48233d2500723e5594f3e7c70896ffeeef32b9c950ywan#define vp9_zero(dest) vpx_memset(&dest, 0, sizeof(dest)) 49233d2500723e5594f3e7c70896ffeeef32b9c950ywan#define vp9_zero_array(dest, n) vpx_memset(dest, 0, n * sizeof(*dest)) 50233d2500723e5594f3e7c70896ffeeef32b9c950ywan 51233d2500723e5594f3e7c70896ffeeef32b9c950ywanstatic INLINE uint8_t clip_pixel(int val) { 52233d2500723e5594f3e7c70896ffeeef32b9c950ywan return (val > 255) ? 255 : (val < 0) ? 0 : val; 53233d2500723e5594f3e7c70896ffeeef32b9c950ywan} 54233d2500723e5594f3e7c70896ffeeef32b9c950ywan 55233d2500723e5594f3e7c70896ffeeef32b9c950ywanstatic INLINE int clamp(int value, int low, int high) { 56233d2500723e5594f3e7c70896ffeeef32b9c950ywan return value < low ? low : (value > high ? high : value); 57233d2500723e5594f3e7c70896ffeeef32b9c950ywan} 58233d2500723e5594f3e7c70896ffeeef32b9c950ywan 59233d2500723e5594f3e7c70896ffeeef32b9c950ywanstatic INLINE double fclamp(double value, double low, double high) { 60233d2500723e5594f3e7c70896ffeeef32b9c950ywan return value < low ? low : (value > high ? high : value); 61233d2500723e5594f3e7c70896ffeeef32b9c950ywan} 62233d2500723e5594f3e7c70896ffeeef32b9c950ywan 63233d2500723e5594f3e7c70896ffeeef32b9c950ywanstatic INLINE int get_unsigned_bits(unsigned int num_values) { 64233d2500723e5594f3e7c70896ffeeef32b9c950ywan return num_values > 0 ? get_msb(num_values) + 1 : 0; 65233d2500723e5594f3e7c70896ffeeef32b9c950ywan} 66233d2500723e5594f3e7c70896ffeeef32b9c950ywan 67233d2500723e5594f3e7c70896ffeeef32b9c950ywan#if CONFIG_DEBUG 68233d2500723e5594f3e7c70896ffeeef32b9c950ywan#define CHECK_MEM_ERROR(cm, lval, expr) do { \ 69233d2500723e5594f3e7c70896ffeeef32b9c950ywan lval = (expr); \ 70233d2500723e5594f3e7c70896ffeeef32b9c950ywan if (!lval) \ 71233d2500723e5594f3e7c70896ffeeef32b9c950ywan vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, \ 72233d2500723e5594f3e7c70896ffeeef32b9c950ywan "Failed to allocate "#lval" at %s:%d", \ 73233d2500723e5594f3e7c70896ffeeef32b9c950ywan __FILE__, __LINE__); \ 74233d2500723e5594f3e7c70896ffeeef32b9c950ywan } while (0) 75233d2500723e5594f3e7c70896ffeeef32b9c950ywan#else 76233d2500723e5594f3e7c70896ffeeef32b9c950ywan#define CHECK_MEM_ERROR(cm, lval, expr) do { \ 77233d2500723e5594f3e7c70896ffeeef32b9c950ywan lval = (expr); \ 78233d2500723e5594f3e7c70896ffeeef32b9c950ywan if (!lval) \ 79233d2500723e5594f3e7c70896ffeeef32b9c950ywan vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, \ 80233d2500723e5594f3e7c70896ffeeef32b9c950ywan "Failed to allocate "#lval); \ 81233d2500723e5594f3e7c70896ffeeef32b9c950ywan } while (0) 82233d2500723e5594f3e7c70896ffeeef32b9c950ywan#endif 83233d2500723e5594f3e7c70896ffeeef32b9c950ywan 84233d2500723e5594f3e7c70896ffeeef32b9c950ywan#define VP9_SYNC_CODE_0 0x49 85233d2500723e5594f3e7c70896ffeeef32b9c950ywan#define VP9_SYNC_CODE_1 0x83 86233d2500723e5594f3e7c70896ffeeef32b9c950ywan#define VP9_SYNC_CODE_2 0x42 87233d2500723e5594f3e7c70896ffeeef32b9c950ywan 88233d2500723e5594f3e7c70896ffeeef32b9c950ywan#define VP9_FRAME_MARKER 0x2 89233d2500723e5594f3e7c70896ffeeef32b9c950ywan 90233d2500723e5594f3e7c70896ffeeef32b9c950ywan 91233d2500723e5594f3e7c70896ffeeef32b9c950ywan#ifdef __cplusplus 92233d2500723e5594f3e7c70896ffeeef32b9c950ywan} // extern "C" 93233d2500723e5594f3e7c70896ffeeef32b9c950ywan#endif 94233d2500723e5594f3e7c70896ffeeef32b9c950ywan 95233d2500723e5594f3e7c70896ffeeef32b9c950ywan#endif // VP9_COMMON_VP9_COMMON_H_ 96