aom_dsp_common.h 3.16 KB
Newer Older
Jingning Han's avatar
Jingning Han committed
1
/*
Yaowu Xu's avatar
Yaowu Xu committed
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Jingning Han's avatar
Jingning Han committed
3
 *
Yaowu Xu's avatar
Yaowu Xu committed
4
5
6
7
8
9
 * This source code is subject to the terms of the BSD 2 Clause License and
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
 * was not distributed with this source code in the LICENSE file, you can
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
 * Media Patent License 1.0 was not distributed with this source code in the
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
Jingning Han's avatar
Jingning Han committed
10
11
 */

Yaowu Xu's avatar
Yaowu Xu committed
12
13
#ifndef AOM_DSP_AOM_DSP_COMMON_H_
#define AOM_DSP_AOM_DSP_COMMON_H_
Jingning Han's avatar
Jingning Han committed
14

Yaowu Xu's avatar
Yaowu Xu committed
15
16
#include "./aom_config.h"
#include "aom/aom_integer.h"
17
#include "aom_ports/mem.h"
Jingning Han's avatar
Jingning Han committed
18
19
20
21
22

#ifdef __cplusplus
extern "C" {
#endif

23
#ifndef MAX_SB_SIZE
Yaowu Xu's avatar
Yaowu Xu committed
24
#if CONFIG_AV1 && CONFIG_EXT_PARTITION
clang-format's avatar
clang-format committed
25
26
27
#define MAX_SB_SIZE 128
#else
#define MAX_SB_SIZE 64
Yaowu Xu's avatar
Yaowu Xu committed
28
#endif  // CONFIG_AV1 && CONFIG_EXT_PARTITION
29
#endif  // ndef MAX_SB_SIZE
30

Yaowu Xu's avatar
Yaowu Xu committed
31
32
#define AOMMIN(x, y) (((x) < (y)) ? (x) : (y))
#define AOMMAX(x, y) (((x) > (y)) ? (x) : (y))
Jingning Han's avatar
Jingning Han committed
33

34
35
#define NELEMENTS(x) (sizeof((x)) / sizeof((x)[0]))

clang-format's avatar
clang-format committed
36
#define IMPLIES(a, b) (!(a) || (b))  //  Logical 'a implies b' (or 'a -> b')
37

clang-format's avatar
clang-format committed
38
#define IS_POWER_OF_TWO(x) (((x) & ((x)-1)) == 0)
Geza Lore's avatar
Geza Lore committed
39

40
41
42
43
44
/* Left shifting a negative value became undefined behavior in C99 (downgraded
   from merely implementation-defined in C89). This should still compile to the
   correct thing on any two's-complement machine, but avoid ubsan warnings.*/
#define AOM_SIGNED_SHL(x, shift) ((x) * (((x)*0 + 1) << (shift)))

45
46
47
48
49
// These can be used to give a hint about branch outcomes.
// This can have an effect, even if your target processor has a
// good branch predictor, as these hints can affect basic block
// ordering by the compiler.
#ifdef __GNUC__
clang-format's avatar
clang-format committed
50
51
#define LIKELY(v) __builtin_expect(v, 1)
#define UNLIKELY(v) __builtin_expect(v, 0)
52
#else
clang-format's avatar
clang-format committed
53
54
#define LIKELY(v) (v)
#define UNLIKELY(v) (v)
55
56
#endif

57
58
#if CONFIG_AOM_QM
typedef uint16_t qm_val_t;
59
#define AOM_QM_BITS 5
60
#endif
61
#if CONFIG_HIGHBITDEPTH
62
63
64
65
66
67
68
69
70
71
72
// Note:
// tran_low_t  is the datatype used for final transform coefficients.
// tran_high_t is the datatype used for intermediate transform stages.
typedef int64_t tran_high_t;
typedef int32_t tran_low_t;
#else
// Note:
// tran_low_t  is the datatype used for final transform coefficients.
// tran_high_t is the datatype used for intermediate transform stages.
typedef int32_t tran_high_t;
typedef int16_t tran_low_t;
73
#endif  // CONFIG_HIGHBITDEPTH
74

Jingning Han's avatar
Jingning Han committed
75
76
77
78
79
80
81
82
static INLINE uint8_t clip_pixel(int val) {
  return (val > 255) ? 255 : (val < 0) ? 0 : val;
}

static INLINE int clamp(int value, int low, int high) {
  return value < low ? low : (value > high ? high : value);
}

83
84
85
86
static INLINE int64_t clamp_64(int64_t value, int64_t low, int64_t high) {
  return value < low ? low : (value > high ? high : (int)value);
}

Jingning Han's avatar
Jingning Han committed
87
88
89
90
static INLINE double fclamp(double value, double low, double high) {
  return value < low ? low : (value > high ? high : value);
}

91
92
93
static INLINE uint16_t clip_pixel_highbd(int val, int bd) {
  switch (bd) {
    case 8:
clang-format's avatar
clang-format committed
94
95
96
    default: return (uint16_t)clamp(val, 0, 255);
    case 10: return (uint16_t)clamp(val, 0, 1023);
    case 12: return (uint16_t)clamp(val, 0, 4095);
97
98
99
  }
}

Jingning Han's avatar
Jingning Han committed
100
101
102
103
#ifdef __cplusplus
}  // extern "C"
#endif

Yaowu Xu's avatar
Yaowu Xu committed
104
#endif  // AOM_DSP_AOM_DSP_COMMON_H_