michael@0: /* michael@0: * Copyright (c) 2010 The WebM project authors. All Rights Reserved. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license michael@0: * that can be found in the LICENSE file in the root of the source michael@0: * tree. An additional intellectual property rights grant can be found michael@0: * in the file PATENTS. All contributing project authors may michael@0: * be found in the AUTHORS file in the root of the source tree. michael@0: */ michael@0: michael@0: #ifndef VP9_COMMON_VP9_COMMON_H_ michael@0: #define VP9_COMMON_VP9_COMMON_H_ michael@0: michael@0: /* Interface header for common constant data structures and lookup tables */ michael@0: michael@0: #include michael@0: michael@0: #include "./vpx_config.h" michael@0: #include "vpx_mem/vpx_mem.h" michael@0: #include "vpx/vpx_integer.h" michael@0: michael@0: #define MIN(x, y) (((x) < (y)) ? (x) : (y)) michael@0: #define MAX(x, y) (((x) > (y)) ? (x) : (y)) michael@0: michael@0: #define ROUND_POWER_OF_TWO(value, n) \ michael@0: (((value) + (1 << ((n) - 1))) >> (n)) michael@0: michael@0: #define ALIGN_POWER_OF_TWO(value, n) \ michael@0: (((value) + ((1 << (n)) - 1)) & ~((1 << (n)) - 1)) michael@0: michael@0: // Only need this for fixed-size arrays, for structs just assign. michael@0: #define vp9_copy(dest, src) { \ michael@0: assert(sizeof(dest) == sizeof(src)); \ michael@0: vpx_memcpy(dest, src, sizeof(src)); \ michael@0: } michael@0: michael@0: // Use this for variably-sized arrays. michael@0: #define vp9_copy_array(dest, src, n) { \ michael@0: assert(sizeof(*dest) == sizeof(*src)); \ michael@0: vpx_memcpy(dest, src, n * sizeof(*src)); \ michael@0: } michael@0: michael@0: #define vp9_zero(dest) vpx_memset(&dest, 0, sizeof(dest)) michael@0: #define vp9_zero_array(dest, n) vpx_memset(dest, 0, n * sizeof(*dest)) michael@0: michael@0: static INLINE uint8_t clip_pixel(int val) { michael@0: return (val > 255) ? 255u : (val < 0) ? 0u : val; michael@0: } michael@0: michael@0: static INLINE int clamp(int value, int low, int high) { michael@0: return value < low ? low : (value > high ? high : value); michael@0: } michael@0: michael@0: static INLINE double fclamp(double value, double low, double high) { michael@0: return value < low ? low : (value > high ? high : value); michael@0: } michael@0: michael@0: static int get_unsigned_bits(unsigned int num_values) { michael@0: int cat = 0; michael@0: if (num_values <= 1) michael@0: return 0; michael@0: num_values--; michael@0: while (num_values > 0) { michael@0: cat++; michael@0: num_values >>= 1; michael@0: } michael@0: return cat; michael@0: } michael@0: michael@0: #if CONFIG_DEBUG michael@0: #define CHECK_MEM_ERROR(cm, lval, expr) do { \ michael@0: lval = (expr); \ michael@0: if (!lval) \ michael@0: vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, \ michael@0: "Failed to allocate "#lval" at %s:%d", \ michael@0: __FILE__, __LINE__); \ michael@0: } while (0) michael@0: #else michael@0: #define CHECK_MEM_ERROR(cm, lval, expr) do { \ michael@0: lval = (expr); \ michael@0: if (!lval) \ michael@0: vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, \ michael@0: "Failed to allocate "#lval); \ michael@0: } while (0) michael@0: #endif michael@0: michael@0: #define VP9_SYNC_CODE_0 0x49 michael@0: #define VP9_SYNC_CODE_1 0x83 michael@0: #define VP9_SYNC_CODE_2 0x42 michael@0: michael@0: #define VP9_FRAME_MARKER 0x2 michael@0: michael@0: michael@0: #endif // VP9_COMMON_VP9_COMMON_H_