vp9_common.h 1.76 KB
Newer Older
John Koleszar's avatar
John Koleszar committed
1
/*
2
 *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
John Koleszar's avatar
John Koleszar committed
3
 *
4
 *  Use of this source code is governed by a BSD-style license
5
6
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
7
 *  in the file PATENTS.  All contributing project authors may
8
 *  be found in the AUTHORS file in the root of the source tree.
John Koleszar's avatar
John Koleszar committed
9
10
 */

11
12
#ifndef VP9_COMMON_VP9_COMMON_H_
#define VP9_COMMON_VP9_COMMON_H_
John Koleszar's avatar
John Koleszar committed
13
14
15

/* Interface header for common constant data structures and lookup tables */

Dmitry Kovalev's avatar
Dmitry Kovalev committed
16
17
18
#include <assert.h>

#include "./vpx_config.h"
John Koleszar's avatar
John Koleszar committed
19
#include "vpx_mem/vpx_mem.h"
20
#include "vpx/vpx_integer.h"
21
22
23

#define TRUE    1
#define FALSE   0
John Koleszar's avatar
John Koleszar committed
24

Ronald S. Bultje's avatar
Ronald S. Bultje committed
25
26
27
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
#define MAX(x, y) (((x) > (y)) ? (x) : (y))

28
#define ROUND_POWER_OF_TWO(value, n) (((value) + (1 << ((n) - 1))) >> (n))
John Koleszar's avatar
John Koleszar committed
29

30
31
32
33
/* If we don't want to use ROUND_POWER_OF_TWO macro
static INLINE int16_t round_power_of_two(int16_t value, int n) {
  return (value + (1 << (n - 1))) >> n;
}*/
John Koleszar's avatar
John Koleszar committed
34

35
36
37
38
// Only need this for fixed-size arrays, for structs just assign.
#define vp9_copy(dest, src) {            \
    assert(sizeof(dest) == sizeof(src)); \
    vpx_memcpy(dest, src, sizeof(src));  \
John Koleszar's avatar
John Koleszar committed
39
  }
John Koleszar's avatar
John Koleszar committed
40

41
42
43
44
45
// Use this for variably-sized arrays.
#define vp9_copy_array(dest, src, n) {       \
    assert(sizeof(*dest) == sizeof(*src));   \
    vpx_memcpy(dest, src, n * sizeof(*src)); \
  }
John Koleszar's avatar
John Koleszar committed
46

47
48
#define vp9_zero(dest) vpx_memset(&dest, 0, sizeof(dest));
#define vp9_zero_array(dest, n) vpx_memset(dest, 0, n * sizeof(*dest));
John Koleszar's avatar
John Koleszar committed
49

50
static INLINE uint8_t clip_pixel(int val) {
51
52
53
  return (val > 255) ? 255u : (val < 0) ? 0u : val;
}

Dmitry Kovalev's avatar
Dmitry Kovalev committed
54
55
56
57
static INLINE int clamp(int value, int low, int high) {
  return value < low ? low : (value > high ? high : value);
}

58
#endif  // VP9_COMMON_VP9_COMMON_H_