Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3 | * |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -0700 | [diff] [blame] | 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. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 12 | #ifndef AOM_DSP_AOM_DSP_COMMON_H_ |
| 13 | #define AOM_DSP_AOM_DSP_COMMON_H_ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 14 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 15 | #include "./aom_config.h" |
| 16 | #include "aom/aom_integer.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 17 | #include "aom_ports/mem.h" |
| 18 | |
| 19 | #ifdef __cplusplus |
| 20 | extern "C" { |
| 21 | #endif |
| 22 | |
| 23 | #ifndef MAX_SB_SIZE |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 24 | #if CONFIG_AV1 && CONFIG_EXT_PARTITION |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 25 | #define MAX_SB_SIZE 128 |
| 26 | #else |
| 27 | #define MAX_SB_SIZE 64 |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 28 | #endif // CONFIG_AV1 && CONFIG_EXT_PARTITION |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 29 | #endif // ndef MAX_SB_SIZE |
| 30 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 31 | #define AOMMIN(x, y) (((x) < (y)) ? (x) : (y)) |
| 32 | #define AOMMAX(x, y) (((x) > (y)) ? (x) : (y)) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 33 | |
| 34 | #define IMPLIES(a, b) (!(a) || (b)) // Logical 'a implies b' (or 'a -> b') |
| 35 | |
| 36 | #define IS_POWER_OF_TWO(x) (((x) & ((x)-1)) == 0) |
| 37 | |
| 38 | // These can be used to give a hint about branch outcomes. |
| 39 | // This can have an effect, even if your target processor has a |
| 40 | // good branch predictor, as these hints can affect basic block |
| 41 | // ordering by the compiler. |
| 42 | #ifdef __GNUC__ |
| 43 | #define LIKELY(v) __builtin_expect(v, 1) |
| 44 | #define UNLIKELY(v) __builtin_expect(v, 0) |
| 45 | #else |
| 46 | #define LIKELY(v) (v) |
| 47 | #define UNLIKELY(v) (v) |
| 48 | #endif |
| 49 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 50 | #define AOM_SWAP(type, a, b) \ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 51 | do { \ |
| 52 | type c = (b); \ |
| 53 | b = a; \ |
| 54 | a = c; \ |
| 55 | } while (0) |
| 56 | |
| 57 | #if CONFIG_AOM_QM |
| 58 | typedef uint16_t qm_val_t; |
| 59 | #define AOM_QM_BITS 6 |
| 60 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 61 | #if CONFIG_AOM_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 62 | // Note: |
| 63 | // tran_low_t is the datatype used for final transform coefficients. |
| 64 | // tran_high_t is the datatype used for intermediate transform stages. |
| 65 | typedef int64_t tran_high_t; |
| 66 | typedef int32_t tran_low_t; |
| 67 | #else |
| 68 | // Note: |
| 69 | // tran_low_t is the datatype used for final transform coefficients. |
| 70 | // tran_high_t is the datatype used for intermediate transform stages. |
| 71 | typedef int32_t tran_high_t; |
| 72 | typedef int16_t tran_low_t; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 73 | #endif // CONFIG_AOM_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 74 | |
| 75 | static INLINE uint8_t clip_pixel(int val) { |
| 76 | return (val > 255) ? 255 : (val < 0) ? 0 : val; |
| 77 | } |
| 78 | |
| 79 | static INLINE int clamp(int value, int low, int high) { |
| 80 | return value < low ? low : (value > high ? high : value); |
| 81 | } |
| 82 | |
| 83 | static INLINE double fclamp(double value, double low, double high) { |
| 84 | return value < low ? low : (value > high ? high : value); |
| 85 | } |
| 86 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 87 | #if CONFIG_AOM_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 88 | static INLINE uint16_t clip_pixel_highbd(int val, int bd) { |
| 89 | switch (bd) { |
| 90 | case 8: |
| 91 | default: return (uint16_t)clamp(val, 0, 255); |
| 92 | case 10: return (uint16_t)clamp(val, 0, 1023); |
| 93 | case 12: return (uint16_t)clamp(val, 0, 4095); |
| 94 | } |
| 95 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 96 | #endif // CONFIG_AOM_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 97 | |
| 98 | #ifdef __cplusplus |
| 99 | } // extern "C" |
| 100 | #endif |
| 101 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 102 | #endif // AOM_DSP_AOM_DSP_COMMON_H_ |