Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -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 | 2ab7ff0 | 2016-09-02 12:04:54 -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_INV_TXFM_H_ |
| 13 | #define AOM_DSP_INV_TXFM_H_ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 14 | |
| 15 | #include <assert.h> |
| 16 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 17 | #include "./aom_config.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 18 | #include "aom_dsp/txfm_common.h" |
| 19 | #include "aom_ports/mem.h" |
| 20 | |
| 21 | #ifdef __cplusplus |
| 22 | extern "C" { |
| 23 | #endif |
| 24 | |
| 25 | static INLINE tran_high_t check_range(tran_high_t input) { |
| 26 | #if CONFIG_COEFFICIENT_RANGE_CHECKING |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 27 | // For valid AV1 input streams, intermediate stage coefficients should always |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 28 | // stay within the range of a signed 16 bit integer. Coefficients can go out |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 29 | // of this range for invalid/corrupt AV1 streams. However, strictly checking |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 30 | // this range for every intermediate coefficient can burdensome for a decoder, |
| 31 | // therefore the following assertion is only enabled when configured with |
| 32 | // --enable-coefficient-range-checking. |
| 33 | assert(INT16_MIN <= input); |
| 34 | assert(input <= INT16_MAX); |
| 35 | #endif // CONFIG_COEFFICIENT_RANGE_CHECKING |
| 36 | return input; |
| 37 | } |
| 38 | |
| 39 | static INLINE tran_high_t dct_const_round_shift(tran_high_t input) { |
| 40 | tran_high_t rv = ROUND_POWER_OF_TWO(input, DCT_CONST_BITS); |
| 41 | return rv; |
| 42 | } |
| 43 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 44 | #if CONFIG_AOM_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 45 | static INLINE tran_high_t highbd_check_range(tran_high_t input, int bd) { |
| 46 | #if CONFIG_COEFFICIENT_RANGE_CHECKING |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 47 | // For valid highbitdepth AV1 streams, intermediate stage coefficients will |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 48 | // stay within the ranges: |
| 49 | // - 8 bit: signed 16 bit integer |
| 50 | // - 10 bit: signed 18 bit integer |
| 51 | // - 12 bit: signed 20 bit integer |
| 52 | const int32_t int_max = (1 << (7 + bd)) - 1; |
| 53 | const int32_t int_min = -int_max - 1; |
| 54 | assert(int_min <= input); |
| 55 | assert(input <= int_max); |
| 56 | (void)int_min; |
| 57 | #endif // CONFIG_COEFFICIENT_RANGE_CHECKING |
| 58 | (void)bd; |
| 59 | return input; |
| 60 | } |
| 61 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 62 | #endif // CONFIG_AOM_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 63 | |
| 64 | #if CONFIG_EMULATE_HARDWARE |
| 65 | // When CONFIG_EMULATE_HARDWARE is 1 the transform performs a |
| 66 | // non-normative method to handle overflows. A stream that causes |
| 67 | // overflows in the inverse transform is considered invalid, |
| 68 | // and a hardware implementer is free to choose any reasonable |
| 69 | // method to handle overflows. However to aid in hardware |
| 70 | // verification they can use a specific implementation of the |
| 71 | // WRAPLOW() macro below that is identical to their intended |
| 72 | // hardware implementation (and also use configure options to trigger |
| 73 | // the C-implementation of the transform). |
| 74 | // |
| 75 | // The particular WRAPLOW implementation below performs strict |
| 76 | // overflow wrapping to match common hardware implementations. |
| 77 | // bd of 8 uses trans_low with 16bits, need to remove 16bits |
| 78 | // bd of 10 uses trans_low with 18bits, need to remove 14bits |
| 79 | // bd of 12 uses trans_low with 20bits, need to remove 12bits |
| 80 | // bd of x uses trans_low with 8+x bits, need to remove 24-x bits |
| 81 | |
| 82 | #define WRAPLOW(x) ((((int32_t)check_range(x)) << 16) >> 16) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 83 | #if CONFIG_AOM_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 84 | #define HIGHBD_WRAPLOW(x, bd) \ |
| 85 | ((((int32_t)highbd_check_range((x), bd)) << (24 - bd)) >> (24 - bd)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 86 | #endif // CONFIG_AOM_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 87 | |
| 88 | #else // CONFIG_EMULATE_HARDWARE |
| 89 | |
| 90 | #define WRAPLOW(x) ((int32_t)check_range(x)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 91 | #if CONFIG_AOM_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 92 | #define HIGHBD_WRAPLOW(x, bd) ((int32_t)highbd_check_range((x), bd)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 93 | #endif // CONFIG_AOM_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 94 | #endif // CONFIG_EMULATE_HARDWARE |
| 95 | |
Luca Barbato | f0f9857 | 2016-09-03 12:14:15 +0200 | [diff] [blame] | 96 | void aom_idct4_c(const tran_low_t *input, tran_low_t *output); |
| 97 | void aom_idct8_c(const tran_low_t *input, tran_low_t *output); |
| 98 | void aom_idct16_c(const tran_low_t *input, tran_low_t *output); |
| 99 | void aom_idct32_c(const tran_low_t *input, tran_low_t *output); |
| 100 | void aom_iadst4_c(const tran_low_t *input, tran_low_t *output); |
| 101 | void aom_iadst8_c(const tran_low_t *input, tran_low_t *output); |
| 102 | void aom_iadst16_c(const tran_low_t *input, tran_low_t *output); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 103 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 104 | #if CONFIG_AOM_HIGHBITDEPTH |
| 105 | void aom_highbd_idct4_c(const tran_low_t *input, tran_low_t *output, int bd); |
| 106 | void aom_highbd_idct8_c(const tran_low_t *input, tran_low_t *output, int bd); |
| 107 | void aom_highbd_idct16_c(const tran_low_t *input, tran_low_t *output, int bd); |
| 108 | void aom_highbd_idct32_c(const tran_low_t *input, tran_low_t *output, int bd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 109 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 110 | void aom_highbd_iadst4_c(const tran_low_t *input, tran_low_t *output, int bd); |
| 111 | void aom_highbd_iadst8_c(const tran_low_t *input, tran_low_t *output, int bd); |
| 112 | void aom_highbd_iadst16_c(const tran_low_t *input, tran_low_t *output, int bd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 113 | |
| 114 | static INLINE uint16_t highbd_clip_pixel_add(uint16_t dest, tran_high_t trans, |
| 115 | int bd) { |
| 116 | trans = HIGHBD_WRAPLOW(trans, bd); |
| 117 | return clip_pixel_highbd(dest + (int)trans, bd); |
| 118 | } |
| 119 | #endif |
| 120 | |
| 121 | static INLINE uint8_t clip_pixel_add(uint8_t dest, tran_high_t trans) { |
| 122 | trans = WRAPLOW(trans); |
| 123 | return clip_pixel(dest + (int)trans); |
| 124 | } |
| 125 | #ifdef __cplusplus |
| 126 | } // extern "C" |
| 127 | #endif |
| 128 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 129 | #endif // AOM_DSP_INV_TXFM_H_ |