blob: fd084f04c909a74d25f92da52123b27ce91be30f [file] [log] [blame]
Angie Chiang716f1bd2016-05-11 16:41:36 -07001/*
Yaowu Xubde4ac82016-11-28 15:26:06 -08002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Angie Chiang716f1bd2016-05-11 16:41:36 -07003 *
Yaowu Xubde4ac82016-11-28 15:26:06 -08004 * 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.
Angie Chiang716f1bd2016-05-11 16:41:36 -070010 */
11
12#include <stdio.h>
Yaowu Xuf883b422016-08-30 14:01:10 -070013#include "test/av1_txfm_test.h"
Angie Chiang716f1bd2016-05-11 16:41:36 -070014
Yaowu Xuc27fc142016-08-22 16:08:15 -070015namespace libaom_test {
Angie Chiang716f1bd2016-05-11 16:41:36 -070016
clang-format3a826f12016-08-11 17:46:05 -070017int get_txfm1d_size(TX_SIZE tx_size) { return 1 << (tx_size + 2); }
Angie Chiang716f1bd2016-05-11 16:41:36 -070018
clang-format3a826f12016-08-11 17:46:05 -070019void get_txfm1d_type(TX_TYPE txfm2d_type, TYPE_TXFM *type0, TYPE_TXFM *type1) {
Angie Chiang716f1bd2016-05-11 16:41:36 -070020 switch (txfm2d_type) {
21 case DCT_DCT:
22 *type0 = TYPE_DCT;
23 *type1 = TYPE_DCT;
24 break;
25 case ADST_DCT:
26 *type0 = TYPE_ADST;
27 *type1 = TYPE_DCT;
28 break;
29 case DCT_ADST:
30 *type0 = TYPE_DCT;
31 *type1 = TYPE_ADST;
32 break;
33 case ADST_ADST:
34 *type0 = TYPE_ADST;
35 *type1 = TYPE_ADST;
36 break;
Angie Chiang6a752532016-05-11 18:50:47 -070037#if CONFIG_EXT_TX
38 case FLIPADST_DCT:
39 *type0 = TYPE_ADST;
40 *type1 = TYPE_DCT;
41 break;
42 case DCT_FLIPADST:
43 *type0 = TYPE_DCT;
44 *type1 = TYPE_ADST;
45 break;
46 case FLIPADST_FLIPADST:
47 *type0 = TYPE_ADST;
48 *type1 = TYPE_ADST;
49 break;
50 case ADST_FLIPADST:
51 *type0 = TYPE_ADST;
52 *type1 = TYPE_ADST;
53 break;
54 case FLIPADST_ADST:
55 *type0 = TYPE_ADST;
56 *type1 = TYPE_ADST;
57 break;
58#endif // CONFIG_EXT_TX
Angie Chiang716f1bd2016-05-11 16:41:36 -070059 default:
60 *type0 = TYPE_DCT;
61 *type1 = TYPE_DCT;
62 assert(0);
63 break;
64 }
65}
66
67double invSqrt2 = 1 / pow(2, 0.5);
68
clang-format3a826f12016-08-11 17:46:05 -070069void reference_dct_1d(const double *in, double *out, int size) {
Angie Chiang716f1bd2016-05-11 16:41:36 -070070 for (int k = 0; k < size; ++k) {
71 out[k] = 0;
72 for (int n = 0; n < size; ++n) {
73 out[k] += in[n] * cos(M_PI * (2 * n + 1) * k / (2 * size));
74 }
75 if (k == 0) out[k] = out[k] * invSqrt2;
76 }
77}
78
clang-format3a826f12016-08-11 17:46:05 -070079void reference_adst_1d(const double *in, double *out, int size) {
Angie Chiang716f1bd2016-05-11 16:41:36 -070080 for (int k = 0; k < size; ++k) {
81 out[k] = 0;
82 for (int n = 0; n < size; ++n) {
83 out[k] += in[n] * sin(M_PI * (2 * n + 1) * (2 * k + 1) / (4 * size));
84 }
85 }
86}
87
clang-format3a826f12016-08-11 17:46:05 -070088void reference_hybrid_1d(double *in, double *out, int size, int type) {
Angie Chiang716f1bd2016-05-11 16:41:36 -070089 if (type == TYPE_DCT)
90 reference_dct_1d(in, out, size);
91 else
92 reference_adst_1d(in, out, size);
93}
94
clang-format3a826f12016-08-11 17:46:05 -070095void reference_hybrid_2d(double *in, double *out, int size, int type0,
96 int type1) {
97 double *tempOut = new double[size * size];
Angie Chiang716f1bd2016-05-11 16:41:36 -070098
99 for (int r = 0; r < size; r++) {
100 // out ->tempOut
101 for (int c = 0; c < size; c++) {
102 tempOut[r * size + c] = in[c * size + r];
103 }
104 }
105
106 // dct each row: in -> out
107 for (int r = 0; r < size; r++) {
108 reference_hybrid_1d(tempOut + r * size, out + r * size, size, type0);
109 }
110
111 for (int r = 0; r < size; r++) {
112 // out ->tempOut
113 for (int c = 0; c < size; c++) {
114 tempOut[r * size + c] = out[c * size + r];
115 }
116 }
117
118 for (int r = 0; r < size; r++) {
119 reference_hybrid_1d(tempOut + r * size, out + r * size, size, type1);
120 }
121 delete[] tempOut;
122}
Angie Chiang6a752532016-05-11 18:50:47 -0700123
clang-format3a826f12016-08-11 17:46:05 -0700124template <typename Type>
Angie Chiang6a752532016-05-11 18:50:47 -0700125void fliplr(Type *dest, int stride, int length) {
126 int i, j;
127 for (i = 0; i < length; ++i) {
128 for (j = 0; j < length / 2; ++j) {
129 const Type tmp = dest[i * stride + j];
130 dest[i * stride + j] = dest[i * stride + length - 1 - j];
131 dest[i * stride + length - 1 - j] = tmp;
132 }
133 }
134}
135
clang-format3a826f12016-08-11 17:46:05 -0700136template <typename Type>
Angie Chiang6a752532016-05-11 18:50:47 -0700137void flipud(Type *dest, int stride, int length) {
138 int i, j;
139 for (j = 0; j < length; ++j) {
140 for (i = 0; i < length / 2; ++i) {
141 const Type tmp = dest[i * stride + j];
142 dest[i * stride + j] = dest[(length - 1 - i) * stride + j];
143 dest[(length - 1 - i) * stride + j] = tmp;
144 }
145 }
146}
147
clang-format3a826f12016-08-11 17:46:05 -0700148template <typename Type>
Angie Chiang6a752532016-05-11 18:50:47 -0700149void fliplrud(Type *dest, int stride, int length) {
150 int i, j;
151 for (i = 0; i < length / 2; ++i) {
152 for (j = 0; j < length; ++j) {
153 const Type tmp = dest[i * stride + j];
154 dest[i * stride + j] = dest[(length - 1 - i) * stride + length - 1 - j];
155 dest[(length - 1 - i) * stride + length - 1 - j] = tmp;
156 }
157 }
158}
159
160template void fliplr<double>(double *dest, int stride, int length);
161template void flipud<double>(double *dest, int stride, int length);
162template void fliplrud<double>(double *dest, int stride, int length);
163
Yaowu Xuc27fc142016-08-22 16:08:15 -0700164} // namespace libaom_test