1*77c1e3ccSAndroid Build Coastguard Worker /*
2*77c1e3ccSAndroid Build Coastguard Worker * Copyright (c) 2016, Alliance for Open Media. All rights reserved.
3*77c1e3ccSAndroid Build Coastguard Worker *
4*77c1e3ccSAndroid Build Coastguard Worker * This source code is subject to the terms of the BSD 2 Clause License and
5*77c1e3ccSAndroid Build Coastguard Worker * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6*77c1e3ccSAndroid Build Coastguard Worker * was not distributed with this source code in the LICENSE file, you can
7*77c1e3ccSAndroid Build Coastguard Worker * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8*77c1e3ccSAndroid Build Coastguard Worker * Media Patent License 1.0 was not distributed with this source code in the
9*77c1e3ccSAndroid Build Coastguard Worker * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10*77c1e3ccSAndroid Build Coastguard Worker */
11*77c1e3ccSAndroid Build Coastguard Worker
12*77c1e3ccSAndroid Build Coastguard Worker #ifndef AOM_TEST_AV1_TXFM_TEST_H_
13*77c1e3ccSAndroid Build Coastguard Worker #define AOM_TEST_AV1_TXFM_TEST_H_
14*77c1e3ccSAndroid Build Coastguard Worker
15*77c1e3ccSAndroid Build Coastguard Worker #include <stdio.h>
16*77c1e3ccSAndroid Build Coastguard Worker #include <stdlib.h>
17*77c1e3ccSAndroid Build Coastguard Worker #ifdef _MSC_VER
18*77c1e3ccSAndroid Build Coastguard Worker #define _USE_MATH_DEFINES
19*77c1e3ccSAndroid Build Coastguard Worker #endif
20*77c1e3ccSAndroid Build Coastguard Worker #include <math.h>
21*77c1e3ccSAndroid Build Coastguard Worker
22*77c1e3ccSAndroid Build Coastguard Worker #include "config/av1_rtcd.h"
23*77c1e3ccSAndroid Build Coastguard Worker
24*77c1e3ccSAndroid Build Coastguard Worker #include "gtest/gtest.h"
25*77c1e3ccSAndroid Build Coastguard Worker
26*77c1e3ccSAndroid Build Coastguard Worker #include "test/acm_random.h"
27*77c1e3ccSAndroid Build Coastguard Worker #include "av1/common/av1_txfm.h"
28*77c1e3ccSAndroid Build Coastguard Worker #include "av1/common/blockd.h"
29*77c1e3ccSAndroid Build Coastguard Worker #include "av1/common/enums.h"
30*77c1e3ccSAndroid Build Coastguard Worker
31*77c1e3ccSAndroid Build Coastguard Worker namespace libaom_test {
32*77c1e3ccSAndroid Build Coastguard Worker
33*77c1e3ccSAndroid Build Coastguard Worker extern const char *tx_type_name[];
34*77c1e3ccSAndroid Build Coastguard Worker
35*77c1e3ccSAndroid Build Coastguard Worker enum {
36*77c1e3ccSAndroid Build Coastguard Worker TYPE_DCT = 0,
37*77c1e3ccSAndroid Build Coastguard Worker TYPE_ADST,
38*77c1e3ccSAndroid Build Coastguard Worker TYPE_IDTX,
39*77c1e3ccSAndroid Build Coastguard Worker TYPE_IDCT,
40*77c1e3ccSAndroid Build Coastguard Worker TYPE_IADST,
41*77c1e3ccSAndroid Build Coastguard Worker TYPE_LAST
42*77c1e3ccSAndroid Build Coastguard Worker } UENUM1BYTE(TYPE_TXFM);
43*77c1e3ccSAndroid Build Coastguard Worker
44*77c1e3ccSAndroid Build Coastguard Worker int get_txfm1d_size(TX_SIZE tx_size);
45*77c1e3ccSAndroid Build Coastguard Worker
46*77c1e3ccSAndroid Build Coastguard Worker void get_txfm1d_type(TX_TYPE txfm2d_type, TYPE_TXFM *type0, TYPE_TXFM *type1);
47*77c1e3ccSAndroid Build Coastguard Worker
48*77c1e3ccSAndroid Build Coastguard Worker void reference_dct_1d(const double *in, double *out, int size);
49*77c1e3ccSAndroid Build Coastguard Worker void reference_idct_1d(const double *in, double *out, int size);
50*77c1e3ccSAndroid Build Coastguard Worker
51*77c1e3ccSAndroid Build Coastguard Worker void reference_adst_1d(const double *in, double *out, int size);
52*77c1e3ccSAndroid Build Coastguard Worker
53*77c1e3ccSAndroid Build Coastguard Worker void reference_hybrid_1d(double *in, double *out, int size, int type);
54*77c1e3ccSAndroid Build Coastguard Worker
55*77c1e3ccSAndroid Build Coastguard Worker double get_amplification_factor(TX_TYPE tx_type, TX_SIZE tx_size);
56*77c1e3ccSAndroid Build Coastguard Worker
57*77c1e3ccSAndroid Build Coastguard Worker void reference_hybrid_2d(double *in, double *out, TX_TYPE tx_type,
58*77c1e3ccSAndroid Build Coastguard Worker TX_SIZE tx_size);
59*77c1e3ccSAndroid Build Coastguard Worker template <typename Type1, typename Type2>
compute_avg_abs_error(const Type1 * a,const Type2 * b,const int size)60*77c1e3ccSAndroid Build Coastguard Worker static double compute_avg_abs_error(const Type1 *a, const Type2 *b,
61*77c1e3ccSAndroid Build Coastguard Worker const int size) {
62*77c1e3ccSAndroid Build Coastguard Worker double error = 0;
63*77c1e3ccSAndroid Build Coastguard Worker for (int i = 0; i < size; i++) {
64*77c1e3ccSAndroid Build Coastguard Worker error += fabs(static_cast<double>(a[i]) - static_cast<double>(b[i]));
65*77c1e3ccSAndroid Build Coastguard Worker }
66*77c1e3ccSAndroid Build Coastguard Worker error = error / size;
67*77c1e3ccSAndroid Build Coastguard Worker return error;
68*77c1e3ccSAndroid Build Coastguard Worker }
69*77c1e3ccSAndroid Build Coastguard Worker
70*77c1e3ccSAndroid Build Coastguard Worker template <typename Type>
71*77c1e3ccSAndroid Build Coastguard Worker void fliplr(Type *dest, int width, int height, int stride);
72*77c1e3ccSAndroid Build Coastguard Worker
73*77c1e3ccSAndroid Build Coastguard Worker template <typename Type>
74*77c1e3ccSAndroid Build Coastguard Worker void flipud(Type *dest, int width, int height, int stride);
75*77c1e3ccSAndroid Build Coastguard Worker
76*77c1e3ccSAndroid Build Coastguard Worker template <typename Type>
77*77c1e3ccSAndroid Build Coastguard Worker void fliplrud(Type *dest, int width, int height, int stride);
78*77c1e3ccSAndroid Build Coastguard Worker
79*77c1e3ccSAndroid Build Coastguard Worker typedef void (*TxfmFunc)(const int32_t *in, int32_t *out, const int8_t cos_bit,
80*77c1e3ccSAndroid Build Coastguard Worker const int8_t *range_bit);
81*77c1e3ccSAndroid Build Coastguard Worker
82*77c1e3ccSAndroid Build Coastguard Worker typedef void (*InvTxfm2dFunc)(const int32_t *, uint16_t *, int, TX_TYPE, int);
83*77c1e3ccSAndroid Build Coastguard Worker typedef void (*LbdInvTxfm2dFunc)(const int32_t *, uint8_t *, int, TX_TYPE,
84*77c1e3ccSAndroid Build Coastguard Worker TX_SIZE, int);
85*77c1e3ccSAndroid Build Coastguard Worker
86*77c1e3ccSAndroid Build Coastguard Worker static const int bd = 10;
87*77c1e3ccSAndroid Build Coastguard Worker static const int input_base = (1 << bd);
88*77c1e3ccSAndroid Build Coastguard Worker
IsTxSizeTypeValid(TX_SIZE tx_size,TX_TYPE tx_type)89*77c1e3ccSAndroid Build Coastguard Worker static inline bool IsTxSizeTypeValid(TX_SIZE tx_size, TX_TYPE tx_type) {
90*77c1e3ccSAndroid Build Coastguard Worker const TX_SIZE tx_size_sqr_up = txsize_sqr_up_map[tx_size];
91*77c1e3ccSAndroid Build Coastguard Worker TxSetType tx_set_type;
92*77c1e3ccSAndroid Build Coastguard Worker if (tx_size_sqr_up > TX_32X32) {
93*77c1e3ccSAndroid Build Coastguard Worker tx_set_type = EXT_TX_SET_DCTONLY;
94*77c1e3ccSAndroid Build Coastguard Worker } else if (tx_size_sqr_up == TX_32X32) {
95*77c1e3ccSAndroid Build Coastguard Worker tx_set_type = EXT_TX_SET_DCT_IDTX;
96*77c1e3ccSAndroid Build Coastguard Worker } else {
97*77c1e3ccSAndroid Build Coastguard Worker tx_set_type = EXT_TX_SET_ALL16;
98*77c1e3ccSAndroid Build Coastguard Worker }
99*77c1e3ccSAndroid Build Coastguard Worker return av1_ext_tx_used[tx_set_type][tx_type] != 0;
100*77c1e3ccSAndroid Build Coastguard Worker }
101*77c1e3ccSAndroid Build Coastguard Worker
102*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_AV1_ENCODER
103*77c1e3ccSAndroid Build Coastguard Worker #if !CONFIG_REALTIME_ONLY
104*77c1e3ccSAndroid Build Coastguard Worker static const FwdTxfm2dFunc fwd_txfm_func_ls[TX_SIZES_ALL] = {
105*77c1e3ccSAndroid Build Coastguard Worker av1_fwd_txfm2d_4x4_c, av1_fwd_txfm2d_8x8_c, av1_fwd_txfm2d_16x16_c,
106*77c1e3ccSAndroid Build Coastguard Worker av1_fwd_txfm2d_32x32_c, av1_fwd_txfm2d_64x64_c, av1_fwd_txfm2d_4x8_c,
107*77c1e3ccSAndroid Build Coastguard Worker av1_fwd_txfm2d_8x4_c, av1_fwd_txfm2d_8x16_c, av1_fwd_txfm2d_16x8_c,
108*77c1e3ccSAndroid Build Coastguard Worker av1_fwd_txfm2d_16x32_c, av1_fwd_txfm2d_32x16_c, av1_fwd_txfm2d_32x64_c,
109*77c1e3ccSAndroid Build Coastguard Worker av1_fwd_txfm2d_64x32_c, av1_fwd_txfm2d_4x16_c, av1_fwd_txfm2d_16x4_c,
110*77c1e3ccSAndroid Build Coastguard Worker av1_fwd_txfm2d_8x32_c, av1_fwd_txfm2d_32x8_c, av1_fwd_txfm2d_16x64_c,
111*77c1e3ccSAndroid Build Coastguard Worker av1_fwd_txfm2d_64x16_c,
112*77c1e3ccSAndroid Build Coastguard Worker };
113*77c1e3ccSAndroid Build Coastguard Worker #else
114*77c1e3ccSAndroid Build Coastguard Worker static const FwdTxfm2dFunc fwd_txfm_func_ls[TX_SIZES_ALL] = {
115*77c1e3ccSAndroid Build Coastguard Worker av1_fwd_txfm2d_4x4_c,
116*77c1e3ccSAndroid Build Coastguard Worker av1_fwd_txfm2d_8x8_c,
117*77c1e3ccSAndroid Build Coastguard Worker av1_fwd_txfm2d_16x16_c,
118*77c1e3ccSAndroid Build Coastguard Worker av1_fwd_txfm2d_32x32_c,
119*77c1e3ccSAndroid Build Coastguard Worker av1_fwd_txfm2d_64x64_c,
120*77c1e3ccSAndroid Build Coastguard Worker av1_fwd_txfm2d_4x8_c,
121*77c1e3ccSAndroid Build Coastguard Worker av1_fwd_txfm2d_8x4_c,
122*77c1e3ccSAndroid Build Coastguard Worker av1_fwd_txfm2d_8x16_c,
123*77c1e3ccSAndroid Build Coastguard Worker av1_fwd_txfm2d_16x8_c,
124*77c1e3ccSAndroid Build Coastguard Worker av1_fwd_txfm2d_16x32_c,
125*77c1e3ccSAndroid Build Coastguard Worker av1_fwd_txfm2d_32x16_c,
126*77c1e3ccSAndroid Build Coastguard Worker av1_fwd_txfm2d_32x64_c,
127*77c1e3ccSAndroid Build Coastguard Worker av1_fwd_txfm2d_64x32_c,
128*77c1e3ccSAndroid Build Coastguard Worker nullptr,
129*77c1e3ccSAndroid Build Coastguard Worker av1_fwd_txfm2d_16x4_c,
130*77c1e3ccSAndroid Build Coastguard Worker nullptr,
131*77c1e3ccSAndroid Build Coastguard Worker nullptr,
132*77c1e3ccSAndroid Build Coastguard Worker nullptr,
133*77c1e3ccSAndroid Build Coastguard Worker nullptr,
134*77c1e3ccSAndroid Build Coastguard Worker };
135*77c1e3ccSAndroid Build Coastguard Worker #endif
136*77c1e3ccSAndroid Build Coastguard Worker #endif
137*77c1e3ccSAndroid Build Coastguard Worker
138*77c1e3ccSAndroid Build Coastguard Worker static const InvTxfm2dFunc inv_txfm_func_ls[TX_SIZES_ALL] = {
139*77c1e3ccSAndroid Build Coastguard Worker av1_inv_txfm2d_add_4x4_c, av1_inv_txfm2d_add_8x8_c,
140*77c1e3ccSAndroid Build Coastguard Worker av1_inv_txfm2d_add_16x16_c, av1_inv_txfm2d_add_32x32_c,
141*77c1e3ccSAndroid Build Coastguard Worker av1_inv_txfm2d_add_64x64_c, av1_inv_txfm2d_add_4x8_c,
142*77c1e3ccSAndroid Build Coastguard Worker av1_inv_txfm2d_add_8x4_c, av1_inv_txfm2d_add_8x16_c,
143*77c1e3ccSAndroid Build Coastguard Worker av1_inv_txfm2d_add_16x8_c, av1_inv_txfm2d_add_16x32_c,
144*77c1e3ccSAndroid Build Coastguard Worker av1_inv_txfm2d_add_32x16_c, av1_inv_txfm2d_add_32x64_c,
145*77c1e3ccSAndroid Build Coastguard Worker av1_inv_txfm2d_add_64x32_c, av1_inv_txfm2d_add_4x16_c,
146*77c1e3ccSAndroid Build Coastguard Worker av1_inv_txfm2d_add_16x4_c, av1_inv_txfm2d_add_8x32_c,
147*77c1e3ccSAndroid Build Coastguard Worker av1_inv_txfm2d_add_32x8_c, av1_inv_txfm2d_add_16x64_c,
148*77c1e3ccSAndroid Build Coastguard Worker av1_inv_txfm2d_add_64x16_c,
149*77c1e3ccSAndroid Build Coastguard Worker };
150*77c1e3ccSAndroid Build Coastguard Worker
151*77c1e3ccSAndroid Build Coastguard Worker #define BD_NUM 3
152*77c1e3ccSAndroid Build Coastguard Worker
153*77c1e3ccSAndroid Build Coastguard Worker extern int bd_arr[];
154*77c1e3ccSAndroid Build Coastguard Worker extern int8_t low_range_arr[];
155*77c1e3ccSAndroid Build Coastguard Worker extern int8_t high_range_arr[];
156*77c1e3ccSAndroid Build Coastguard Worker
157*77c1e3ccSAndroid Build Coastguard Worker void txfm_stage_range_check(const int8_t *stage_range, int stage_num,
158*77c1e3ccSAndroid Build Coastguard Worker const int8_t cos_bit, int low_range,
159*77c1e3ccSAndroid Build Coastguard Worker int high_range);
160*77c1e3ccSAndroid Build Coastguard Worker } // namespace libaom_test
161*77c1e3ccSAndroid Build Coastguard Worker #endif // AOM_TEST_AV1_TXFM_TEST_H_
162