blob: 92976e14ccccd45431c546822023316b16755dde [file] [log] [blame]
Daniel Kangfed8a182012-08-02 17:03:14 -07001/*
2 * Copyright (c) 2012 The WebM project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include <math.h>
12#include <stdlib.h>
13#include <string.h>
14
15#include "third_party/googletest/src/include/gtest/gtest.h"
Jingning Han8f92a7e2013-09-05 12:44:03 -070016#include "test/acm_random.h"
17#include "test/clear_system_state.h"
18#include "test/register_state_check.h"
19#include "test/util.h"
Daniel Kangfed8a182012-08-02 17:03:14 -070020
Yaowu Xuafffa3d2013-09-05 08:45:56 -070021#include "./vp9_rtcd.h"
James Zern002ad402014-01-18 13:03:31 -080022#include "vp9/common/vp9_entropy.h"
23#include "vpx/vpx_integer.h"
24
25extern "C" {
Dmitry Kovalev65f118d2013-10-11 18:27:12 -070026void vp9_idct16x16_256_add_c(const int16_t *input, uint8_t *output, int pitch);
Daniel Kangfed8a182012-08-02 17:03:14 -070027}
Daniel Kangfed8a182012-08-02 17:03:14 -070028
29using libvpx_test::ACMRandom;
30
31namespace {
32
Yaowu Xu77f889b2013-02-04 15:22:55 -080033#ifdef _MSC_VER
34static int round(double x) {
35 if (x < 0)
Yaowu Xuafffa3d2013-09-05 08:45:56 -070036 return static_cast<int>(ceil(x - 0.5));
Yaowu Xu77f889b2013-02-04 15:22:55 -080037 else
Yaowu Xuafffa3d2013-09-05 08:45:56 -070038 return static_cast<int>(floor(x + 0.5));
Yaowu Xu77f889b2013-02-04 15:22:55 -080039}
40#endif
41
Jingning Han8f92a7e2013-09-05 12:44:03 -070042const int kNumCoeffs = 256;
Daniel Kangfed8a182012-08-02 17:03:14 -070043const double PI = 3.1415926535898;
44void reference2_16x16_idct_2d(double *input, double *output) {
45 double x;
46 for (int l = 0; l < 16; ++l) {
47 for (int k = 0; k < 16; ++k) {
48 double s = 0;
49 for (int i = 0; i < 16; ++i) {
50 for (int j = 0; j < 16; ++j) {
Yaowu Xuafffa3d2013-09-05 08:45:56 -070051 x = cos(PI * j * (l + 0.5) / 16.0) *
52 cos(PI * i * (k + 0.5) / 16.0) *
53 input[i * 16 + j] / 256;
Daniel Kangfed8a182012-08-02 17:03:14 -070054 if (i != 0)
55 x *= sqrt(2.0);
56 if (j != 0)
57 x *= sqrt(2.0);
58 s += x;
59 }
60 }
61 output[k*16+l] = s;
62 }
63 }
64}
65
Yaowu Xu0b17ea62012-08-07 13:55:49 -070066
Jingning Han8f92a7e2013-09-05 12:44:03 -070067const double C1 = 0.995184726672197;
68const double C2 = 0.98078528040323;
69const double C3 = 0.956940335732209;
70const double C4 = 0.923879532511287;
71const double C5 = 0.881921264348355;
72const double C6 = 0.831469612302545;
73const double C7 = 0.773010453362737;
74const double C8 = 0.707106781186548;
75const double C9 = 0.634393284163646;
76const double C10 = 0.555570233019602;
77const double C11 = 0.471396736825998;
78const double C12 = 0.38268343236509;
79const double C13 = 0.290284677254462;
80const double C14 = 0.195090322016128;
81const double C15 = 0.098017140329561;
Yaowu Xu0b17ea62012-08-07 13:55:49 -070082
Jingning Hanec4b2742013-08-27 17:03:46 -070083void butterfly_16x16_dct_1d(double input[16], double output[16]) {
Daniel Kangfed8a182012-08-02 17:03:14 -070084 double step[16];
85 double intermediate[16];
86 double temp1, temp2;
87
Daniel Kangfed8a182012-08-02 17:03:14 -070088 // step 1
89 step[ 0] = input[0] + input[15];
90 step[ 1] = input[1] + input[14];
91 step[ 2] = input[2] + input[13];
92 step[ 3] = input[3] + input[12];
93 step[ 4] = input[4] + input[11];
94 step[ 5] = input[5] + input[10];
95 step[ 6] = input[6] + input[ 9];
96 step[ 7] = input[7] + input[ 8];
97 step[ 8] = input[7] - input[ 8];
98 step[ 9] = input[6] - input[ 9];
99 step[10] = input[5] - input[10];
100 step[11] = input[4] - input[11];
101 step[12] = input[3] - input[12];
102 step[13] = input[2] - input[13];
103 step[14] = input[1] - input[14];
104 step[15] = input[0] - input[15];
105
106 // step 2
107 output[0] = step[0] + step[7];
108 output[1] = step[1] + step[6];
109 output[2] = step[2] + step[5];
110 output[3] = step[3] + step[4];
111 output[4] = step[3] - step[4];
112 output[5] = step[2] - step[5];
113 output[6] = step[1] - step[6];
114 output[7] = step[0] - step[7];
115
Jingning Han8f92a7e2013-09-05 12:44:03 -0700116 temp1 = step[ 8] * C7;
117 temp2 = step[15] * C9;
Daniel Kangfed8a182012-08-02 17:03:14 -0700118 output[ 8] = temp1 + temp2;
119
Jingning Han8f92a7e2013-09-05 12:44:03 -0700120 temp1 = step[ 9] * C11;
121 temp2 = step[14] * C5;
Daniel Kangfed8a182012-08-02 17:03:14 -0700122 output[ 9] = temp1 - temp2;
123
Jingning Han8f92a7e2013-09-05 12:44:03 -0700124 temp1 = step[10] * C3;
125 temp2 = step[13] * C13;
Daniel Kangfed8a182012-08-02 17:03:14 -0700126 output[10] = temp1 + temp2;
127
Jingning Han8f92a7e2013-09-05 12:44:03 -0700128 temp1 = step[11] * C15;
129 temp2 = step[12] * C1;
Daniel Kangfed8a182012-08-02 17:03:14 -0700130 output[11] = temp1 - temp2;
131
Jingning Han8f92a7e2013-09-05 12:44:03 -0700132 temp1 = step[11] * C1;
133 temp2 = step[12] * C15;
Daniel Kangfed8a182012-08-02 17:03:14 -0700134 output[12] = temp2 + temp1;
135
Jingning Han8f92a7e2013-09-05 12:44:03 -0700136 temp1 = step[10] * C13;
137 temp2 = step[13] * C3;
Daniel Kangfed8a182012-08-02 17:03:14 -0700138 output[13] = temp2 - temp1;
139
Jingning Han8f92a7e2013-09-05 12:44:03 -0700140 temp1 = step[ 9] * C5;
141 temp2 = step[14] * C11;
Daniel Kangfed8a182012-08-02 17:03:14 -0700142 output[14] = temp2 + temp1;
143
Jingning Han8f92a7e2013-09-05 12:44:03 -0700144 temp1 = step[ 8] * C9;
145 temp2 = step[15] * C7;
Daniel Kangfed8a182012-08-02 17:03:14 -0700146 output[15] = temp2 - temp1;
147
148 // step 3
149 step[ 0] = output[0] + output[3];
150 step[ 1] = output[1] + output[2];
151 step[ 2] = output[1] - output[2];
152 step[ 3] = output[0] - output[3];
153
Jingning Han8f92a7e2013-09-05 12:44:03 -0700154 temp1 = output[4] * C14;
155 temp2 = output[7] * C2;
Daniel Kangfed8a182012-08-02 17:03:14 -0700156 step[ 4] = temp1 + temp2;
157
Jingning Han8f92a7e2013-09-05 12:44:03 -0700158 temp1 = output[5] * C10;
159 temp2 = output[6] * C6;
Daniel Kangfed8a182012-08-02 17:03:14 -0700160 step[ 5] = temp1 + temp2;
161
Jingning Han8f92a7e2013-09-05 12:44:03 -0700162 temp1 = output[5] * C6;
163 temp2 = output[6] * C10;
Daniel Kangfed8a182012-08-02 17:03:14 -0700164 step[ 6] = temp2 - temp1;
165
Jingning Han8f92a7e2013-09-05 12:44:03 -0700166 temp1 = output[4] * C2;
167 temp2 = output[7] * C14;
Daniel Kangfed8a182012-08-02 17:03:14 -0700168 step[ 7] = temp2 - temp1;
169
170 step[ 8] = output[ 8] + output[11];
171 step[ 9] = output[ 9] + output[10];
172 step[10] = output[ 9] - output[10];
173 step[11] = output[ 8] - output[11];
174
175 step[12] = output[12] + output[15];
176 step[13] = output[13] + output[14];
177 step[14] = output[13] - output[14];
178 step[15] = output[12] - output[15];
179
180 // step 4
181 output[ 0] = (step[ 0] + step[ 1]);
182 output[ 8] = (step[ 0] - step[ 1]);
183
Jingning Han8f92a7e2013-09-05 12:44:03 -0700184 temp1 = step[2] * C12;
185 temp2 = step[3] * C4;
Daniel Kangfed8a182012-08-02 17:03:14 -0700186 temp1 = temp1 + temp2;
Jingning Han8f92a7e2013-09-05 12:44:03 -0700187 output[ 4] = 2*(temp1 * C8);
Daniel Kangfed8a182012-08-02 17:03:14 -0700188
Jingning Han8f92a7e2013-09-05 12:44:03 -0700189 temp1 = step[2] * C4;
190 temp2 = step[3] * C12;
Daniel Kangfed8a182012-08-02 17:03:14 -0700191 temp1 = temp2 - temp1;
Jingning Han8f92a7e2013-09-05 12:44:03 -0700192 output[12] = 2 * (temp1 * C8);
Daniel Kangfed8a182012-08-02 17:03:14 -0700193
Jingning Han8f92a7e2013-09-05 12:44:03 -0700194 output[ 2] = 2 * ((step[4] + step[ 5]) * C8);
195 output[14] = 2 * ((step[7] - step[ 6]) * C8);
Daniel Kangfed8a182012-08-02 17:03:14 -0700196
197 temp1 = step[4] - step[5];
198 temp2 = step[6] + step[7];
199 output[ 6] = (temp1 + temp2);
200 output[10] = (temp1 - temp2);
201
202 intermediate[8] = step[8] + step[14];
203 intermediate[9] = step[9] + step[15];
204
Jingning Han8f92a7e2013-09-05 12:44:03 -0700205 temp1 = intermediate[8] * C12;
206 temp2 = intermediate[9] * C4;
Daniel Kangfed8a182012-08-02 17:03:14 -0700207 temp1 = temp1 - temp2;
Jingning Han8f92a7e2013-09-05 12:44:03 -0700208 output[3] = 2 * (temp1 * C8);
Daniel Kangfed8a182012-08-02 17:03:14 -0700209
Jingning Han8f92a7e2013-09-05 12:44:03 -0700210 temp1 = intermediate[8] * C4;
211 temp2 = intermediate[9] * C12;
Daniel Kangfed8a182012-08-02 17:03:14 -0700212 temp1 = temp2 + temp1;
Jingning Han8f92a7e2013-09-05 12:44:03 -0700213 output[13] = 2 * (temp1 * C8);
Daniel Kangfed8a182012-08-02 17:03:14 -0700214
Jingning Han8f92a7e2013-09-05 12:44:03 -0700215 output[ 9] = 2 * ((step[10] + step[11]) * C8);
Daniel Kangfed8a182012-08-02 17:03:14 -0700216
217 intermediate[11] = step[10] - step[11];
218 intermediate[12] = step[12] + step[13];
219 intermediate[13] = step[12] - step[13];
220 intermediate[14] = step[ 8] - step[14];
221 intermediate[15] = step[ 9] - step[15];
222
223 output[15] = (intermediate[11] + intermediate[12]);
224 output[ 1] = -(intermediate[11] - intermediate[12]);
225
Jingning Han8f92a7e2013-09-05 12:44:03 -0700226 output[ 7] = 2 * (intermediate[13] * C8);
Daniel Kangfed8a182012-08-02 17:03:14 -0700227
Jingning Han8f92a7e2013-09-05 12:44:03 -0700228 temp1 = intermediate[14] * C12;
229 temp2 = intermediate[15] * C4;
Daniel Kangfed8a182012-08-02 17:03:14 -0700230 temp1 = temp1 - temp2;
Jingning Han8f92a7e2013-09-05 12:44:03 -0700231 output[11] = -2 * (temp1 * C8);
Daniel Kangfed8a182012-08-02 17:03:14 -0700232
Jingning Han8f92a7e2013-09-05 12:44:03 -0700233 temp1 = intermediate[14] * C4;
234 temp2 = intermediate[15] * C12;
Daniel Kangfed8a182012-08-02 17:03:14 -0700235 temp1 = temp2 + temp1;
Jingning Han8f92a7e2013-09-05 12:44:03 -0700236 output[ 5] = 2 * (temp1 * C8);
Daniel Kangfed8a182012-08-02 17:03:14 -0700237}
238
Jingning Han8f92a7e2013-09-05 12:44:03 -0700239void reference_16x16_dct_2d(int16_t input[256], double output[256]) {
Daniel Kangfed8a182012-08-02 17:03:14 -0700240 // First transform columns
241 for (int i = 0; i < 16; ++i) {
242 double temp_in[16], temp_out[16];
243 for (int j = 0; j < 16; ++j)
Jingning Han8f92a7e2013-09-05 12:44:03 -0700244 temp_in[j] = input[j * 16 + i];
Daniel Kangfed8a182012-08-02 17:03:14 -0700245 butterfly_16x16_dct_1d(temp_in, temp_out);
246 for (int j = 0; j < 16; ++j)
Jingning Han8f92a7e2013-09-05 12:44:03 -0700247 output[j * 16 + i] = temp_out[j];
Daniel Kangfed8a182012-08-02 17:03:14 -0700248 }
249 // Then transform rows
250 for (int i = 0; i < 16; ++i) {
251 double temp_in[16], temp_out[16];
252 for (int j = 0; j < 16; ++j)
Jingning Han8f92a7e2013-09-05 12:44:03 -0700253 temp_in[j] = output[j + i * 16];
Daniel Kangfed8a182012-08-02 17:03:14 -0700254 butterfly_16x16_dct_1d(temp_in, temp_out);
255 // Scale by some magic number
256 for (int j = 0; j < 16; ++j)
Jingning Han8f92a7e2013-09-05 12:44:03 -0700257 output[j + i * 16] = temp_out[j]/2;
Daniel Kangfed8a182012-08-02 17:03:14 -0700258 }
259}
260
Dmitry Kovalev600a3862013-10-24 11:48:25 -0700261typedef void (*fdct_t)(const int16_t *in, int16_t *out, int stride);
262typedef void (*idct_t)(const int16_t *in, uint8_t *out, int stride);
263typedef void (*fht_t) (const int16_t *in, int16_t *out, int stride,
264 int tx_type);
265typedef void (*iht_t) (const int16_t *in, uint8_t *out, int stride,
Dmitry Kovalev65f118d2013-10-11 18:27:12 -0700266 int tx_type);
Jingning Hancf768b22013-07-09 16:16:49 -0700267
Joshua Litt51490e52013-11-18 17:07:55 -0800268typedef std::tr1::tuple<fdct_t, idct_t, int> dct_16x16_param_t;
269typedef std::tr1::tuple<fht_t, iht_t, int> ht_16x16_param_t;
270
Dmitry Kovalev600a3862013-10-24 11:48:25 -0700271void fdct16x16_ref(const int16_t *in, int16_t *out, int stride, int tx_type) {
Dmitry Kovalev02feb632013-10-23 10:57:12 -0700272 vp9_fdct16x16_c(in, out, stride);
Jingning Han37705a32013-09-09 17:07:55 -0700273}
274
Jingning Han49b4a272014-05-29 12:50:54 -0700275void idct16x16_ref(const int16_t *in, uint8_t *dest, int stride, int tx_type) {
276 vp9_idct16x16_256_add_c(in, dest, stride);
277}
278
Dmitry Kovalev600a3862013-10-24 11:48:25 -0700279void fht16x16_ref(const int16_t *in, int16_t *out, int stride, int tx_type) {
Dmitry Kovalev005fc692014-02-06 11:54:15 -0800280 vp9_fht16x16_c(in, out, stride, tx_type);
Jingning Han37705a32013-09-09 17:07:55 -0700281}
282
Jingning Han49b4a272014-05-29 12:50:54 -0700283void iht16x16_ref(const int16_t *in, uint8_t *dest, int stride, int tx_type) {
284 vp9_iht16x16_256_add_c(in, dest, stride, tx_type);
285}
286
Jingning Han8f92a7e2013-09-05 12:44:03 -0700287class Trans16x16TestBase {
Jingning Hancf768b22013-07-09 16:16:49 -0700288 public:
Jingning Han8f92a7e2013-09-05 12:44:03 -0700289 virtual ~Trans16x16TestBase() {}
Jingning Hancf768b22013-07-09 16:16:49 -0700290
Jingning Han8f92a7e2013-09-05 12:44:03 -0700291 protected:
Jingning Han37705a32013-09-09 17:07:55 -0700292 virtual void RunFwdTxfm(int16_t *in, int16_t *out, int stride) = 0;
Jingning Han8f92a7e2013-09-05 12:44:03 -0700293
Jingning Han37705a32013-09-09 17:07:55 -0700294 virtual void RunInvTxfm(int16_t *out, uint8_t *dst, int stride) = 0;
Jingning Han8f92a7e2013-09-05 12:44:03 -0700295
296 void RunAccuracyCheck() {
297 ACMRandom rnd(ACMRandom::DeterministicSeed());
Jingning Han37705a32013-09-09 17:07:55 -0700298 uint32_t max_error = 0;
299 int64_t total_error = 0;
Jingning Han8f92a7e2013-09-05 12:44:03 -0700300 const int count_test_block = 10000;
301 for (int i = 0; i < count_test_block; ++i) {
302 DECLARE_ALIGNED_ARRAY(16, int16_t, test_input_block, kNumCoeffs);
303 DECLARE_ALIGNED_ARRAY(16, int16_t, test_temp_block, kNumCoeffs);
304 DECLARE_ALIGNED_ARRAY(16, uint8_t, dst, kNumCoeffs);
305 DECLARE_ALIGNED_ARRAY(16, uint8_t, src, kNumCoeffs);
306
Jingning Han37705a32013-09-09 17:07:55 -0700307 // Initialize a test block with input range [-255, 255].
Jingning Han8f92a7e2013-09-05 12:44:03 -0700308 for (int j = 0; j < kNumCoeffs; ++j) {
309 src[j] = rnd.Rand8();
310 dst[j] = rnd.Rand8();
Jingning Han8f92a7e2013-09-05 12:44:03 -0700311 test_input_block[j] = src[j] - dst[j];
312 }
313
Jingning Han37705a32013-09-09 17:07:55 -0700314 REGISTER_STATE_CHECK(RunFwdTxfm(test_input_block,
315 test_temp_block, pitch_));
316 REGISTER_STATE_CHECK(RunInvTxfm(test_temp_block, dst, pitch_));
Jingning Han8f92a7e2013-09-05 12:44:03 -0700317
318 for (int j = 0; j < kNumCoeffs; ++j) {
Jingning Han37705a32013-09-09 17:07:55 -0700319 const uint32_t diff = dst[j] - src[j];
320 const uint32_t error = diff * diff;
Jingning Han8f92a7e2013-09-05 12:44:03 -0700321 if (max_error < error)
322 max_error = error;
323 total_error += error;
324 }
325 }
326
Jingning Han37705a32013-09-09 17:07:55 -0700327 EXPECT_GE(1u, max_error)
Jingning Han8f92a7e2013-09-05 12:44:03 -0700328 << "Error: 16x16 FHT/IHT has an individual round trip error > 1";
329
330 EXPECT_GE(count_test_block , total_error)
331 << "Error: 16x16 FHT/IHT has average round trip error > 1 per block";
332 }
333
Jingning Han37705a32013-09-09 17:07:55 -0700334 void RunCoeffCheck() {
Jingning Han8f92a7e2013-09-05 12:44:03 -0700335 ACMRandom rnd(ACMRandom::DeterministicSeed());
336 const int count_test_block = 1000;
Jingning Han37705a32013-09-09 17:07:55 -0700337 DECLARE_ALIGNED_ARRAY(16, int16_t, input_block, kNumCoeffs);
338 DECLARE_ALIGNED_ARRAY(16, int16_t, output_ref_block, kNumCoeffs);
339 DECLARE_ALIGNED_ARRAY(16, int16_t, output_block, kNumCoeffs);
Jingning Han8f92a7e2013-09-05 12:44:03 -0700340
Jingning Han37705a32013-09-09 17:07:55 -0700341 for (int i = 0; i < count_test_block; ++i) {
342 // Initialize a test block with input range [-255, 255].
343 for (int j = 0; j < kNumCoeffs; ++j)
344 input_block[j] = rnd.Rand8() - rnd.Rand8();
345
346 fwd_txfm_ref(input_block, output_ref_block, pitch_, tx_type_);
347 REGISTER_STATE_CHECK(RunFwdTxfm(input_block, output_block, pitch_));
348
349 // The minimum quant value is 4.
350 for (int j = 0; j < kNumCoeffs; ++j)
351 EXPECT_EQ(output_block[j], output_ref_block[j]);
352 }
353 }
354
355 void RunMemCheck() {
356 ACMRandom rnd(ACMRandom::DeterministicSeed());
357 const int count_test_block = 1000;
358 DECLARE_ALIGNED_ARRAY(16, int16_t, input_block, kNumCoeffs);
359 DECLARE_ALIGNED_ARRAY(16, int16_t, input_extreme_block, kNumCoeffs);
360 DECLARE_ALIGNED_ARRAY(16, int16_t, output_ref_block, kNumCoeffs);
361 DECLARE_ALIGNED_ARRAY(16, int16_t, output_block, kNumCoeffs);
362
363 for (int i = 0; i < count_test_block; ++i) {
Jingning Han8f92a7e2013-09-05 12:44:03 -0700364 // Initialize a test block with input range [-255, 255].
365 for (int j = 0; j < kNumCoeffs; ++j) {
366 input_block[j] = rnd.Rand8() - rnd.Rand8();
367 input_extreme_block[j] = rnd.Rand8() % 2 ? 255 : -255;
368 }
369 if (i == 0)
370 for (int j = 0; j < kNumCoeffs; ++j)
371 input_extreme_block[j] = 255;
Jingning Han37705a32013-09-09 17:07:55 -0700372 if (i == 1)
373 for (int j = 0; j < kNumCoeffs; ++j)
374 input_extreme_block[j] = -255;
Jingning Han8f92a7e2013-09-05 12:44:03 -0700375
Jingning Han37705a32013-09-09 17:07:55 -0700376 fwd_txfm_ref(input_extreme_block, output_ref_block, pitch_, tx_type_);
Jingning Han8f92a7e2013-09-05 12:44:03 -0700377 REGISTER_STATE_CHECK(RunFwdTxfm(input_extreme_block,
Jingning Han37705a32013-09-09 17:07:55 -0700378 output_block, pitch_));
Jingning Han8f92a7e2013-09-05 12:44:03 -0700379
380 // The minimum quant value is 4.
381 for (int j = 0; j < kNumCoeffs; ++j) {
Jingning Han37705a32013-09-09 17:07:55 -0700382 EXPECT_EQ(output_block[j], output_ref_block[j]);
Jingning Han8f92a7e2013-09-05 12:44:03 -0700383 EXPECT_GE(4 * DCT_MAX_VALUE, abs(output_block[j]))
384 << "Error: 16x16 FDCT has coefficient larger than 4*DCT_MAX_VALUE";
Jingning Han8f92a7e2013-09-05 12:44:03 -0700385 }
Jingning Hancf768b22013-07-09 16:16:49 -0700386 }
387 }
388
Jingning Han49b4a272014-05-29 12:50:54 -0700389 void RunQuantCheck(int dc_thred, int ac_thred) {
390 ACMRandom rnd(ACMRandom::DeterministicSeed());
391 const int count_test_block = 1000;
392 DECLARE_ALIGNED_ARRAY(16, int16_t, input_block, kNumCoeffs);
393 DECLARE_ALIGNED_ARRAY(16, int16_t, input_extreme_block, kNumCoeffs);
394 DECLARE_ALIGNED_ARRAY(16, int16_t, output_ref_block, kNumCoeffs);
395
396 DECLARE_ALIGNED_ARRAY(16, uint8_t, dst, kNumCoeffs);
397 DECLARE_ALIGNED_ARRAY(16, uint8_t, ref, kNumCoeffs);
398
399 for (int i = 0; i < count_test_block; ++i) {
400 // Initialize a test block with input range [-255, 255].
401 for (int j = 0; j < kNumCoeffs; ++j) {
402 input_block[j] = rnd.Rand8() - rnd.Rand8();
403 input_extreme_block[j] = rnd.Rand8() % 2 ? 255 : -255;
404 }
405 if (i == 0)
406 for (int j = 0; j < kNumCoeffs; ++j)
407 input_extreme_block[j] = 255;
408 if (i == 1)
409 for (int j = 0; j < kNumCoeffs; ++j)
410 input_extreme_block[j] = -255;
411
412 fwd_txfm_ref(input_extreme_block, output_ref_block, pitch_, tx_type_);
413
414 // clear reconstructed pixel buffers
415 vpx_memset(dst, 0, kNumCoeffs * sizeof(uint8_t));
416 vpx_memset(ref, 0, kNumCoeffs * sizeof(uint8_t));
417
418 // quantization with maximum allowed step sizes
419 output_ref_block[0] = (output_ref_block[0] / dc_thred) * dc_thred;
420 for (int j = 1; j < kNumCoeffs; ++j)
421 output_ref_block[j] = (output_ref_block[j] / ac_thred) * ac_thred;
422 inv_txfm_ref(output_ref_block, ref, pitch_, tx_type_);
423 REGISTER_STATE_CHECK(RunInvTxfm(output_ref_block, dst, pitch_));
424
425 for (int j = 0; j < kNumCoeffs; ++j)
426 EXPECT_EQ(ref[j], dst[j]);
427 }
428 }
429
Jingning Han8f92a7e2013-09-05 12:44:03 -0700430 void RunInvAccuracyCheck() {
431 ACMRandom rnd(ACMRandom::DeterministicSeed());
432 const int count_test_block = 1000;
Jingning Han37705a32013-09-09 17:07:55 -0700433 DECLARE_ALIGNED_ARRAY(16, int16_t, in, kNumCoeffs);
434 DECLARE_ALIGNED_ARRAY(16, int16_t, coeff, kNumCoeffs);
435 DECLARE_ALIGNED_ARRAY(16, uint8_t, dst, kNumCoeffs);
436 DECLARE_ALIGNED_ARRAY(16, uint8_t, src, kNumCoeffs);
Jingning Han8f92a7e2013-09-05 12:44:03 -0700437
438 for (int i = 0; i < count_test_block; ++i) {
Jingning Han8f92a7e2013-09-05 12:44:03 -0700439 double out_r[kNumCoeffs];
440
441 // Initialize a test block with input range [-255, 255].
442 for (int j = 0; j < kNumCoeffs; ++j) {
443 src[j] = rnd.Rand8();
444 dst[j] = rnd.Rand8();
445 in[j] = src[j] - dst[j];
446 }
447
448 reference_16x16_dct_2d(in, out_r);
449 for (int j = 0; j < kNumCoeffs; ++j)
450 coeff[j] = round(out_r[j]);
451
Dmitry Kovalev1aa7fd52013-10-18 11:49:33 -0700452 REGISTER_STATE_CHECK(RunInvTxfm(coeff, dst, 16));
Jingning Han8f92a7e2013-09-05 12:44:03 -0700453
454 for (int j = 0; j < kNumCoeffs; ++j) {
Jingning Han37705a32013-09-09 17:07:55 -0700455 const uint32_t diff = dst[j] - src[j];
456 const uint32_t error = diff * diff;
457 EXPECT_GE(1u, error)
Jingning Han8f92a7e2013-09-05 12:44:03 -0700458 << "Error: 16x16 IDCT has error " << error
459 << " at index " << j;
460 }
461 }
Jingning Hancf768b22013-07-09 16:16:49 -0700462 }
Jingning Han37705a32013-09-09 17:07:55 -0700463 int pitch_;
464 int tx_type_;
465 fht_t fwd_txfm_ref;
Jingning Han49b4a272014-05-29 12:50:54 -0700466 iht_t inv_txfm_ref;
Jingning Han8f92a7e2013-09-05 12:44:03 -0700467};
468
Joshua Litt51490e52013-11-18 17:07:55 -0800469class Trans16x16DCT
470 : public Trans16x16TestBase,
471 public ::testing::TestWithParam<dct_16x16_param_t> {
Jingning Han8f92a7e2013-09-05 12:44:03 -0700472 public:
473 virtual ~Trans16x16DCT() {}
474
475 virtual void SetUp() {
476 fwd_txfm_ = GET_PARAM(0);
477 inv_txfm_ = GET_PARAM(1);
478 tx_type_ = GET_PARAM(2);
Dmitry Kovalev1aa7fd52013-10-18 11:49:33 -0700479 pitch_ = 16;
Jingning Han37705a32013-09-09 17:07:55 -0700480 fwd_txfm_ref = fdct16x16_ref;
Jingning Han49b4a272014-05-29 12:50:54 -0700481 inv_txfm_ref = idct16x16_ref;
Jingning Han8f92a7e2013-09-05 12:44:03 -0700482 }
483 virtual void TearDown() { libvpx_test::ClearSystemState(); }
484
485 protected:
Jingning Han37705a32013-09-09 17:07:55 -0700486 void RunFwdTxfm(int16_t *in, int16_t *out, int stride) {
Jingning Han8f92a7e2013-09-05 12:44:03 -0700487 fwd_txfm_(in, out, stride);
488 }
Jingning Han37705a32013-09-09 17:07:55 -0700489 void RunInvTxfm(int16_t *out, uint8_t *dst, int stride) {
Dmitry Kovalev1aa7fd52013-10-18 11:49:33 -0700490 inv_txfm_(out, dst, stride);
Jingning Hancf768b22013-07-09 16:16:49 -0700491 }
492
Jingning Han8f92a7e2013-09-05 12:44:03 -0700493 fdct_t fwd_txfm_;
494 idct_t inv_txfm_;
Jingning Hancf768b22013-07-09 16:16:49 -0700495};
496
Jingning Han8f92a7e2013-09-05 12:44:03 -0700497TEST_P(Trans16x16DCT, AccuracyCheck) {
498 RunAccuracyCheck();
Jingning Hancf768b22013-07-09 16:16:49 -0700499}
500
Jingning Han37705a32013-09-09 17:07:55 -0700501TEST_P(Trans16x16DCT, CoeffCheck) {
502 RunCoeffCheck();
503}
504
505TEST_P(Trans16x16DCT, MemCheck) {
506 RunMemCheck();
Jingning Hancf768b22013-07-09 16:16:49 -0700507}
508
Jingning Han49b4a272014-05-29 12:50:54 -0700509TEST_P(Trans16x16DCT, QuantCheck) {
510 // Use maximally allowed quantization step sizes for DC and AC
511 // coefficients respectively.
512 RunQuantCheck(1336, 1828);
513}
514
Jingning Han8f92a7e2013-09-05 12:44:03 -0700515TEST_P(Trans16x16DCT, InvAccuracyCheck) {
516 RunInvAccuracyCheck();
Daniel Kangfed8a182012-08-02 17:03:14 -0700517}
Scott LaVarnwaya272ff22013-05-15 13:16:02 -0400518
Joshua Litt51490e52013-11-18 17:07:55 -0800519class Trans16x16HT
520 : public Trans16x16TestBase,
521 public ::testing::TestWithParam<ht_16x16_param_t> {
Jingning Han8f92a7e2013-09-05 12:44:03 -0700522 public:
523 virtual ~Trans16x16HT() {}
524
525 virtual void SetUp() {
526 fwd_txfm_ = GET_PARAM(0);
527 inv_txfm_ = GET_PARAM(1);
528 tx_type_ = GET_PARAM(2);
Jingning Han37705a32013-09-09 17:07:55 -0700529 pitch_ = 16;
530 fwd_txfm_ref = fht16x16_ref;
Jingning Han49b4a272014-05-29 12:50:54 -0700531 inv_txfm_ref = iht16x16_ref;
Jingning Han8f92a7e2013-09-05 12:44:03 -0700532 }
533 virtual void TearDown() { libvpx_test::ClearSystemState(); }
534
535 protected:
Jingning Han37705a32013-09-09 17:07:55 -0700536 void RunFwdTxfm(int16_t *in, int16_t *out, int stride) {
537 fwd_txfm_(in, out, stride, tx_type_);
Jingning Han8f92a7e2013-09-05 12:44:03 -0700538 }
Jingning Han37705a32013-09-09 17:07:55 -0700539 void RunInvTxfm(int16_t *out, uint8_t *dst, int stride) {
540 inv_txfm_(out, dst, stride, tx_type_);
Jingning Han8f92a7e2013-09-05 12:44:03 -0700541 }
542
Jingning Han8f92a7e2013-09-05 12:44:03 -0700543 fht_t fwd_txfm_;
544 iht_t inv_txfm_;
545};
546
547TEST_P(Trans16x16HT, AccuracyCheck) {
548 RunAccuracyCheck();
549}
550
Jingning Han37705a32013-09-09 17:07:55 -0700551TEST_P(Trans16x16HT, CoeffCheck) {
552 RunCoeffCheck();
553}
554
555TEST_P(Trans16x16HT, MemCheck) {
556 RunMemCheck();
Jingning Han8f92a7e2013-09-05 12:44:03 -0700557}
558
Jingning Han49b4a272014-05-29 12:50:54 -0700559TEST_P(Trans16x16HT, QuantCheck) {
560 // The encoder skips any non-DC intra prediction modes,
561 // when the quantization step size goes beyond 988.
562 RunQuantCheck(549, 988);
563}
564
Jingning Han8f92a7e2013-09-05 12:44:03 -0700565using std::tr1::make_tuple;
566
567INSTANTIATE_TEST_CASE_P(
568 C, Trans16x16DCT,
569 ::testing::Values(
Dmitry Kovalev02feb632013-10-23 10:57:12 -0700570 make_tuple(&vp9_fdct16x16_c, &vp9_idct16x16_256_add_c, 0)));
Jingning Han8f92a7e2013-09-05 12:44:03 -0700571INSTANTIATE_TEST_CASE_P(
572 C, Trans16x16HT,
573 ::testing::Values(
Dmitry Kovalev005fc692014-02-06 11:54:15 -0800574 make_tuple(&vp9_fht16x16_c, &vp9_iht16x16_256_add_c, 0),
575 make_tuple(&vp9_fht16x16_c, &vp9_iht16x16_256_add_c, 1),
576 make_tuple(&vp9_fht16x16_c, &vp9_iht16x16_256_add_c, 2),
577 make_tuple(&vp9_fht16x16_c, &vp9_iht16x16_256_add_c, 3)));
Jingning Han8f92a7e2013-09-05 12:44:03 -0700578
Jingning Han74a854f2014-05-22 11:36:00 -0700579#if HAVE_NEON_ASM
James Zernadbb8812014-02-25 23:11:49 -0800580INSTANTIATE_TEST_CASE_P(
581 NEON, Trans16x16DCT,
582 ::testing::Values(
583 make_tuple(&vp9_fdct16x16_c,
584 &vp9_idct16x16_256_add_neon, 0)));
585#endif
586
Jingning Han8f92a7e2013-09-05 12:44:03 -0700587#if HAVE_SSE2
588INSTANTIATE_TEST_CASE_P(
589 SSE2, Trans16x16DCT,
590 ::testing::Values(
Dmitry Kovalev02feb632013-10-23 10:57:12 -0700591 make_tuple(&vp9_fdct16x16_sse2,
Dmitry Kovalevb096c5a2013-10-07 14:31:10 -0700592 &vp9_idct16x16_256_add_sse2, 0)));
Jingning Han8f92a7e2013-09-05 12:44:03 -0700593INSTANTIATE_TEST_CASE_P(
594 SSE2, Trans16x16HT,
595 ::testing::Values(
Dmitry Kovalev005fc692014-02-06 11:54:15 -0800596 make_tuple(&vp9_fht16x16_sse2, &vp9_iht16x16_256_add_sse2, 0),
597 make_tuple(&vp9_fht16x16_sse2, &vp9_iht16x16_256_add_sse2, 1),
598 make_tuple(&vp9_fht16x16_sse2, &vp9_iht16x16_256_add_sse2, 2),
599 make_tuple(&vp9_fht16x16_sse2, &vp9_iht16x16_256_add_sse2, 3)));
Jingning Han8f92a7e2013-09-05 12:44:03 -0700600#endif
Jingning Hane4a758b2014-05-22 11:31:43 -0700601
602#if HAVE_SSSE3
603INSTANTIATE_TEST_CASE_P(
604 SSSE3, Trans16x16DCT,
605 ::testing::Values(
606 make_tuple(&vp9_fdct16x16_c, &vp9_idct16x16_256_add_ssse3, 0)));
607#endif
Daniel Kangfed8a182012-08-02 17:03:14 -0700608} // namespace