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_TEST_AV1_TXFM_TEST_H_
13 #define AOM_TEST_AV1_TXFM_TEST_H_
14
15 #include <stdio.h>
16 #include <stdlib.h>
17 #ifdef _MSC_VER
18 #define _USE_MATH_DEFINES
19 #endif
20 #include <math.h>
21
22 #include "config/av1_rtcd.h"
23
24 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
25
26 #include "test/acm_random.h"
27 #include "av1/common/av1_txfm.h"
28 #include "av1/common/blockd.h"
29 #include "av1/common/enums.h"
30
31 namespace libaom_test {
32 enum {
33 TYPE_DCT = 0,
34 TYPE_ADST,
35 TYPE_IDTX,
36 TYPE_IDCT,
37 TYPE_IADST,
38 TYPE_LAST
39 } UENUM1BYTE(TYPE_TXFM);
40
41 int get_txfm1d_size(TX_SIZE tx_size);
42
43 void get_txfm1d_type(TX_TYPE txfm2d_type, TYPE_TXFM *type0, TYPE_TXFM *type1);
44
45 void reference_dct_1d(const double *in, double *out, int size);
46 void reference_idct_1d(const double *in, double *out, int size);
47
48 void reference_adst_1d(const double *in, double *out, int size);
49
50 void reference_hybrid_1d(double *in, double *out, int size, int type);
51
52 double get_amplification_factor(TX_TYPE tx_type, TX_SIZE tx_size);
53
54 void reference_hybrid_2d(double *in, double *out, TX_TYPE tx_type,
55 TX_SIZE tx_size);
56 template <typename Type1, typename Type2>
compute_avg_abs_error(const Type1 * a,const Type2 * b,const int size)57 static double compute_avg_abs_error(const Type1 *a, const Type2 *b,
58 const int size) {
59 double error = 0;
60 for (int i = 0; i < size; i++) {
61 error += fabs(static_cast<double>(a[i]) - static_cast<double>(b[i]));
62 }
63 error = error / size;
64 return error;
65 }
66
67 template <typename Type>
68 void fliplr(Type *dest, int width, int height, int stride);
69
70 template <typename Type>
71 void flipud(Type *dest, int width, int height, int stride);
72
73 template <typename Type>
74 void fliplrud(Type *dest, int width, int height, int stride);
75
76 typedef void (*TxfmFunc)(const int32_t *in, int32_t *out, const int8_t cos_bit,
77 const int8_t *range_bit);
78
79 typedef void (*InvTxfm2dFunc)(const int32_t *, uint16_t *, int, TX_TYPE, int);
80 typedef void (*LbdInvTxfm2dFunc)(const int32_t *, uint8_t *, int, TX_TYPE,
81 TX_SIZE, int);
82
83 static const int bd = 10;
84 static const int input_base = (1 << bd);
85
IsTxSizeTypeValid(TX_SIZE tx_size,TX_TYPE tx_type)86 static INLINE bool IsTxSizeTypeValid(TX_SIZE tx_size, TX_TYPE tx_type) {
87 const TX_SIZE tx_size_sqr_up = txsize_sqr_up_map[tx_size];
88 TxSetType tx_set_type;
89 if (tx_size_sqr_up > TX_32X32) {
90 tx_set_type = EXT_TX_SET_DCTONLY;
91 } else if (tx_size_sqr_up == TX_32X32) {
92 tx_set_type = EXT_TX_SET_DCT_IDTX;
93 } else {
94 tx_set_type = EXT_TX_SET_ALL16;
95 }
96 return av1_ext_tx_used[tx_set_type][tx_type] != 0;
97 }
98
99 #if CONFIG_AV1_ENCODER
100
101 static const FwdTxfm2dFunc fwd_txfm_func_ls[TX_SIZES_ALL] = {
102 av1_fwd_txfm2d_4x4_c, av1_fwd_txfm2d_8x8_c, av1_fwd_txfm2d_16x16_c,
103 av1_fwd_txfm2d_32x32_c, av1_fwd_txfm2d_64x64_c, av1_fwd_txfm2d_4x8_c,
104 av1_fwd_txfm2d_8x4_c, av1_fwd_txfm2d_8x16_c, av1_fwd_txfm2d_16x8_c,
105 av1_fwd_txfm2d_16x32_c, av1_fwd_txfm2d_32x16_c, av1_fwd_txfm2d_32x64_c,
106 av1_fwd_txfm2d_64x32_c, av1_fwd_txfm2d_4x16_c, av1_fwd_txfm2d_16x4_c,
107 av1_fwd_txfm2d_8x32_c, av1_fwd_txfm2d_32x8_c, av1_fwd_txfm2d_16x64_c,
108 av1_fwd_txfm2d_64x16_c,
109 };
110 #endif
111
112 static const InvTxfm2dFunc inv_txfm_func_ls[TX_SIZES_ALL] = {
113 av1_inv_txfm2d_add_4x4_c, av1_inv_txfm2d_add_8x8_c,
114 av1_inv_txfm2d_add_16x16_c, av1_inv_txfm2d_add_32x32_c,
115 av1_inv_txfm2d_add_64x64_c, av1_inv_txfm2d_add_4x8_c,
116 av1_inv_txfm2d_add_8x4_c, av1_inv_txfm2d_add_8x16_c,
117 av1_inv_txfm2d_add_16x8_c, av1_inv_txfm2d_add_16x32_c,
118 av1_inv_txfm2d_add_32x16_c, av1_inv_txfm2d_add_32x64_c,
119 av1_inv_txfm2d_add_64x32_c, av1_inv_txfm2d_add_4x16_c,
120 av1_inv_txfm2d_add_16x4_c, av1_inv_txfm2d_add_8x32_c,
121 av1_inv_txfm2d_add_32x8_c, av1_inv_txfm2d_add_16x64_c,
122 av1_inv_txfm2d_add_64x16_c,
123 };
124
125 #define BD_NUM 3
126
127 extern int bd_arr[];
128 extern int8_t low_range_arr[];
129 extern int8_t high_range_arr[];
130
131 void txfm_stage_range_check(const int8_t *stage_range, int stage_num,
132 const int8_t cos_bit, int low_range,
133 int high_range);
134 } // namespace libaom_test
135 #endif // AOM_TEST_AV1_TXFM_TEST_H_
136