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_INV_TXFM_H_
13 #define AOM_DSP_INV_TXFM_H_
14 
15 #include <assert.h>
16 
17 #include "./aom_config.h"
18 #include "aom_dsp/txfm_common.h"
19 #include "aom_ports/mem.h"
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
dct_const_round_shift(tran_high_t input)25 static INLINE tran_high_t dct_const_round_shift(tran_high_t input) {
26   return ROUND_POWER_OF_TWO(input, DCT_CONST_BITS);
27 }
28 
check_range(tran_high_t input,int bd)29 static INLINE tran_high_t check_range(tran_high_t input, int bd) {
30 #if CONFIG_COEFFICIENT_RANGE_CHECKING
31   // For valid AV1 input streams, intermediate stage coefficients should always
32   // stay within the range of a signed 16 bit integer. Coefficients can go out
33   // of this range for invalid/corrupt AV1 streams. However, strictly checking
34   // this range for every intermediate coefficient can burdensome for a decoder,
35   // therefore the following assertion is only enabled when configured with
36   // --enable-coefficient-range-checking.
37   // For valid highbitdepth AV1 streams, intermediate stage coefficients will
38   // stay within the ranges:
39   // - 8 bit: signed 16 bit integer
40   // - 10 bit: signed 18 bit integer
41   // - 12 bit: signed 20 bit integer
42   const int32_t int_max = (1 << (7 + bd)) - 1;
43   const int32_t int_min = -int_max - 1;
44   assert(int_min <= input);
45   assert(input <= int_max);
46   (void)int_min;
47 #endif  // CONFIG_COEFFICIENT_RANGE_CHECKING
48   (void)bd;
49   return input;
50 }
51 
52 #define WRAPLOW(x) ((int32_t)check_range(x, 8))
53 #define HIGHBD_WRAPLOW(x, bd) ((int32_t)check_range((x), bd))
54 
55 #if CONFIG_MRC_TX
56 // These each perform dct but add coefficients based on a mask
57 void aom_imrc32x32_1024_add_c(const tran_low_t *input, uint8_t *dest,
58                               int stride, uint8_t *mask);
59 
60 void aom_imrc32x32_135_add_c(const tran_low_t *input, uint8_t *dest, int stride,
61                              uint8_t *mask);
62 
63 void aom_imrc32x32_34_add_c(const tran_low_t *input, uint8_t *dest, int stride,
64                             uint8_t *mask);
65 #endif  // CONFIG_MRC_TX
66 
67 void aom_idct4_c(const tran_low_t *input, tran_low_t *output);
68 void aom_idct8_c(const tran_low_t *input, tran_low_t *output);
69 void aom_idct16_c(const tran_low_t *input, tran_low_t *output);
70 void aom_idct32_c(const tran_low_t *input, tran_low_t *output);
71 #if CONFIG_TX64X64 && CONFIG_DAALA_DCT64
72 void aom_idct64_c(const tran_low_t *input, tran_low_t *output);
73 #endif
74 void aom_iadst4_c(const tran_low_t *input, tran_low_t *output);
75 void aom_iadst8_c(const tran_low_t *input, tran_low_t *output);
76 void aom_iadst16_c(const tran_low_t *input, tran_low_t *output);
77 
78 void aom_highbd_idct4_c(const tran_low_t *input, tran_low_t *output, int bd);
79 void aom_highbd_idct8_c(const tran_low_t *input, tran_low_t *output, int bd);
80 void aom_highbd_idct16_c(const tran_low_t *input, tran_low_t *output, int bd);
81 void aom_highbd_idct32_c(const tran_low_t *input, tran_low_t *output, int bd);
82 
83 void aom_highbd_iadst4_c(const tran_low_t *input, tran_low_t *output, int bd);
84 void aom_highbd_iadst8_c(const tran_low_t *input, tran_low_t *output, int bd);
85 void aom_highbd_iadst16_c(const tran_low_t *input, tran_low_t *output, int bd);
86 
highbd_clip_pixel_add(uint16_t dest,tran_high_t trans,int bd)87 static INLINE uint16_t highbd_clip_pixel_add(uint16_t dest, tran_high_t trans,
88                                              int bd) {
89   trans = HIGHBD_WRAPLOW(trans, bd);
90   return clip_pixel_highbd(dest + (int)trans, bd);
91 }
92 
clip_pixel_add(uint8_t dest,tran_high_t trans)93 static INLINE uint8_t clip_pixel_add(uint8_t dest, tran_high_t trans) {
94   trans = WRAPLOW(trans);
95   return clip_pixel(dest + (int)trans);
96 }
97 #ifdef __cplusplus
98 }  // extern "C"
99 #endif
100 
101 #endif  // AOM_DSP_INV_TXFM_H_
102