Line data Source code
1 : /*
2 : * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3 : *
4 : * This source code is subject to the terms of the BSD 2 Clause License and
5 : * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 : * was not distributed with this source code in the LICENSE file, you can
7 : * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 : * Media Patent License 1.0 was not distributed with this source code in the
9 : * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10 : */
11 :
12 : #ifndef AOM_DSP_AOM_DSP_COMMON_H_
13 : #define AOM_DSP_AOM_DSP_COMMON_H_
14 :
15 : #include "./aom_config.h"
16 : #include "aom/aom_integer.h"
17 : #include "aom_ports/mem.h"
18 :
19 : #ifdef __cplusplus
20 : extern "C" {
21 : #endif
22 :
23 : #ifndef MAX_SB_SIZE
24 : #if CONFIG_AV1 && CONFIG_EXT_PARTITION
25 : #define MAX_SB_SIZE 128
26 : #else
27 : #define MAX_SB_SIZE 64
28 : #endif // CONFIG_AV1 && CONFIG_EXT_PARTITION
29 : #endif // ndef MAX_SB_SIZE
30 :
31 : #define AOMMIN(x, y) (((x) < (y)) ? (x) : (y))
32 : #define AOMMAX(x, y) (((x) > (y)) ? (x) : (y))
33 :
34 : #define NELEMENTS(x) (sizeof((x)) / sizeof((x)[0]))
35 :
36 : #define IMPLIES(a, b) (!(a) || (b)) // Logical 'a implies b' (or 'a -> b')
37 :
38 : #define IS_POWER_OF_TWO(x) (((x) & ((x)-1)) == 0)
39 :
40 : /* Left shifting a negative value became undefined behavior in C99 (downgraded
41 : from merely implementation-defined in C89). This should still compile to the
42 : correct thing on any two's-complement machine, but avoid ubsan warnings.*/
43 : #define AOM_SIGNED_SHL(x, shift) ((x) * (((x)*0 + 1) << (shift)))
44 :
45 : // These can be used to give a hint about branch outcomes.
46 : // This can have an effect, even if your target processor has a
47 : // good branch predictor, as these hints can affect basic block
48 : // ordering by the compiler.
49 : #ifdef __GNUC__
50 : #define LIKELY(v) __builtin_expect(v, 1)
51 : #define UNLIKELY(v) __builtin_expect(v, 0)
52 : #else
53 : #define LIKELY(v) (v)
54 : #define UNLIKELY(v) (v)
55 : #endif
56 :
57 : #define AOM_SWAP(type, a, b) \
58 : do { \
59 : type c = (b); \
60 : b = a; \
61 : a = c; \
62 : } while (0)
63 :
64 : #if CONFIG_AOM_QM
65 : typedef uint16_t qm_val_t;
66 : #define AOM_QM_BITS 6
67 : #endif
68 : #if CONFIG_HIGHBITDEPTH
69 : // Note:
70 : // tran_low_t is the datatype used for final transform coefficients.
71 : // tran_high_t is the datatype used for intermediate transform stages.
72 : typedef int64_t tran_high_t;
73 : typedef int32_t tran_low_t;
74 : #else
75 : // Note:
76 : // tran_low_t is the datatype used for final transform coefficients.
77 : // tran_high_t is the datatype used for intermediate transform stages.
78 : typedef int32_t tran_high_t;
79 : typedef int16_t tran_low_t;
80 : #endif // CONFIG_HIGHBITDEPTH
81 :
82 0 : static INLINE uint8_t clip_pixel(int val) {
83 0 : return (val > 255) ? 255 : (val < 0) ? 0 : val;
84 : }
85 :
86 0 : static INLINE int clamp(int value, int low, int high) {
87 0 : return value < low ? low : (value > high ? high : value);
88 : }
89 :
90 0 : static INLINE double fclamp(double value, double low, double high) {
91 0 : return value < low ? low : (value > high ? high : value);
92 : }
93 :
94 : #if CONFIG_HIGHBITDEPTH
95 0 : static INLINE uint16_t clip_pixel_highbd(int val, int bd) {
96 0 : switch (bd) {
97 : case 8:
98 0 : default: return (uint16_t)clamp(val, 0, 255);
99 0 : case 10: return (uint16_t)clamp(val, 0, 1023);
100 0 : case 12: return (uint16_t)clamp(val, 0, 4095);
101 : }
102 : }
103 : #endif // CONFIG_HIGHBITDEPTH
104 :
105 : #ifdef __cplusplus
106 : } // extern "C"
107 : #endif
108 :
109 : #endif // AOM_DSP_AOM_DSP_COMMON_H_
|