Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(969)

Side by Side Diff: source/libvpx/test/vp10_inv_txfm_test.cc

Issue 1339513003: libvpx: Pull from upstream (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/libvpx.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « source/libvpx/test/video_source.h ('k') | source/libvpx/third_party/libwebm/README.libvpx » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013 The WebM project authors. All Rights Reserved. 2 * Copyright (c) 2013 The WebM project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include <math.h> 11 #include <math.h>
12 #include <stdlib.h> 12 #include <stdlib.h>
13 #include <string.h> 13 #include <string.h>
14 14
15 #include "third_party/googletest/src/include/gtest/gtest.h" 15 #include "third_party/googletest/src/include/gtest/gtest.h"
16 16
17 #include "./vp9_rtcd.h" 17 #include "./vp10_rtcd.h"
18 #include "./vpx_dsp_rtcd.h" 18 #include "./vpx_dsp_rtcd.h"
19 #include "test/acm_random.h" 19 #include "test/acm_random.h"
20 #include "test/clear_system_state.h" 20 #include "test/clear_system_state.h"
21 #include "test/register_state_check.h" 21 #include "test/register_state_check.h"
22 #include "test/util.h" 22 #include "test/util.h"
23 #include "vp9/common/vp9_blockd.h" 23 #include "vp10/common/blockd.h"
24 #include "vp9/common/vp9_scan.h" 24 #include "vp10/common/scan.h"
25 #include "vpx/vpx_integer.h" 25 #include "vpx/vpx_integer.h"
26 #include "vp10/common/vp10_inv_txfm.h"
26 27
27 using libvpx_test::ACMRandom; 28 using libvpx_test::ACMRandom;
28 29
29 namespace { 30 namespace {
31 const double PI = 3.141592653589793238462643383279502884;
32 const double kInvSqrt2 = 0.707106781186547524400844362104;
33
34 void reference_idct_1d(const double *in, double *out, int size) {
35 for (int n = 0; n < size; ++n) {
36 out[n] = 0;
37 for (int k = 0; k < size; ++k) {
38 if (k == 0)
39 out[n] += kInvSqrt2 * in[k] * cos(PI * (2 * n + 1) * k / (2 * size));
40 else
41 out[n] += in[k] * cos(PI * (2 * n + 1) * k / (2 * size));
42 }
43 }
44 }
45
46 typedef void (*IdctFuncRef)(const double *in, double *out, int size);
47 typedef void (*IdctFunc)(const tran_low_t *in, tran_low_t *out);
48
49 class TransTestBase {
50 public:
51 virtual ~TransTestBase() {}
52
53 protected:
54 void RunInvAccuracyCheck() {
55 tran_low_t *input = new tran_low_t[txfm_size_];
56 tran_low_t *output = new tran_low_t[txfm_size_];
57 double *ref_input = new double[txfm_size_];
58 double *ref_output = new double[txfm_size_];
59
60 ACMRandom rnd(ACMRandom::DeterministicSeed());
61 const int count_test_block = 5000;
62 for (int ti = 0; ti < count_test_block; ++ti) {
63 for (int ni = 0; ni < txfm_size_; ++ni) {
64 input[ni] = rnd.Rand8() - rnd.Rand8();
65 ref_input[ni] = static_cast<double>(input[ni]);
66 }
67
68 fwd_txfm_(input, output);
69 fwd_txfm_ref_(ref_input, ref_output, txfm_size_);
70
71 for (int ni = 0; ni < txfm_size_; ++ni) {
72 EXPECT_LE(
73 abs(output[ni] - static_cast<tran_low_t>(round(ref_output[ni]))),
74 max_error_);
75 }
76 }
77
78 delete[] input;
79 delete[] output;
80 delete[] ref_input;
81 delete[] ref_output;
82 }
83
84 double max_error_;
85 int txfm_size_;
86 IdctFunc fwd_txfm_;
87 IdctFuncRef fwd_txfm_ref_;
88 };
89
90 typedef std::tr1::tuple<IdctFunc, IdctFuncRef, int, int> IdctParam;
91 class Vp10InvTxfm
92 : public TransTestBase,
93 public ::testing::TestWithParam<IdctParam> {
94 public:
95 virtual void SetUp() {
96 fwd_txfm_ = GET_PARAM(0);
97 fwd_txfm_ref_ = GET_PARAM(1);
98 txfm_size_ = GET_PARAM(2);
99 max_error_ = GET_PARAM(3);
100 }
101 virtual void TearDown() {}
102 };
103
104 TEST_P(Vp10InvTxfm, RunInvAccuracyCheck) {
105 RunInvAccuracyCheck();
106 }
107
108 INSTANTIATE_TEST_CASE_P(
109 C, Vp10InvTxfm,
110 ::testing::Values(
111 IdctParam(&vp10_idct4_c, &reference_idct_1d, 4, 1),
112 IdctParam(&vp10_idct8_c, &reference_idct_1d, 8, 2),
113 IdctParam(&vp10_idct16_c, &reference_idct_1d, 16, 4),
114 IdctParam(&vp10_idct32_c, &reference_idct_1d, 32, 6))
115 );
116
30 typedef void (*FwdTxfmFunc)(const int16_t *in, tran_low_t *out, int stride); 117 typedef void (*FwdTxfmFunc)(const int16_t *in, tran_low_t *out, int stride);
31 typedef void (*InvTxfmFunc)(const tran_low_t *in, uint8_t *out, int stride); 118 typedef void (*InvTxfmFunc)(const tran_low_t *in, uint8_t *out, int stride);
32 typedef std::tr1::tuple<FwdTxfmFunc, 119 typedef std::tr1::tuple<FwdTxfmFunc,
33 InvTxfmFunc, 120 InvTxfmFunc,
34 InvTxfmFunc, 121 InvTxfmFunc,
35 TX_SIZE, int> PartialInvTxfmParam; 122 TX_SIZE, int> PartialInvTxfmParam;
36 const int kMaxNumCoeffs = 1024; 123 const int kMaxNumCoeffs = 1024;
37 class PartialIDctTest : public ::testing::TestWithParam<PartialInvTxfmParam> { 124 class Vp10PartialIDctTest
125 : public ::testing::TestWithParam<PartialInvTxfmParam> {
38 public: 126 public:
39 virtual ~PartialIDctTest() {} 127 virtual ~Vp10PartialIDctTest() {}
40 virtual void SetUp() { 128 virtual void SetUp() {
41 ftxfm_ = GET_PARAM(0); 129 ftxfm_ = GET_PARAM(0);
42 full_itxfm_ = GET_PARAM(1); 130 full_itxfm_ = GET_PARAM(1);
43 partial_itxfm_ = GET_PARAM(2); 131 partial_itxfm_ = GET_PARAM(2);
44 tx_size_ = GET_PARAM(3); 132 tx_size_ = GET_PARAM(3);
45 last_nonzero_ = GET_PARAM(4); 133 last_nonzero_ = GET_PARAM(4);
46 } 134 }
47 135
48 virtual void TearDown() { libvpx_test::ClearSystemState(); } 136 virtual void TearDown() { libvpx_test::ClearSystemState(); }
49 137
50 protected: 138 protected:
51 int last_nonzero_; 139 int last_nonzero_;
52 TX_SIZE tx_size_; 140 TX_SIZE tx_size_;
53 FwdTxfmFunc ftxfm_; 141 FwdTxfmFunc ftxfm_;
54 InvTxfmFunc full_itxfm_; 142 InvTxfmFunc full_itxfm_;
55 InvTxfmFunc partial_itxfm_; 143 InvTxfmFunc partial_itxfm_;
56 }; 144 };
57 145
58 TEST_P(PartialIDctTest, RunQuantCheck) { 146 TEST_P(Vp10PartialIDctTest, RunQuantCheck) {
59 ACMRandom rnd(ACMRandom::DeterministicSeed()); 147 ACMRandom rnd(ACMRandom::DeterministicSeed());
60 int size; 148 int size;
61 switch (tx_size_) { 149 switch (tx_size_) {
62 case TX_4X4: 150 case TX_4X4:
63 size = 4; 151 size = 4;
64 break; 152 break;
65 case TX_8X8: 153 case TX_8X8:
66 size = 8; 154 size = 8;
67 break; 155 break;
68 case TX_16X16: 156 case TX_16X16:
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 for (int j = 0; j < block_size; ++j) { 196 for (int j = 0; j < block_size; ++j) {
109 input_extreme_block[j] = rnd.Rand8() % 2 ? 255 : -255; 197 input_extreme_block[j] = rnd.Rand8() % 2 ? 255 : -255;
110 } 198 }
111 } 199 }
112 200
113 ftxfm_(input_extreme_block, output_ref_block, size); 201 ftxfm_(input_extreme_block, output_ref_block, size);
114 202
115 // quantization with maximum allowed step sizes 203 // quantization with maximum allowed step sizes
116 test_coef_block1[0] = (output_ref_block[0] / 1336) * 1336; 204 test_coef_block1[0] = (output_ref_block[0] / 1336) * 1336;
117 for (int j = 1; j < last_nonzero_; ++j) 205 for (int j = 1; j < last_nonzero_; ++j)
118 test_coef_block1[vp9_default_scan_orders[tx_size_].scan[j]] 206 test_coef_block1[vp10_default_scan_orders[tx_size_].scan[j]]
119 = (output_ref_block[j] / 1828) * 1828; 207 = (output_ref_block[j] / 1828) * 1828;
120 } 208 }
121 209
122 ASM_REGISTER_STATE_CHECK(full_itxfm_(test_coef_block1, dst1, size)); 210 ASM_REGISTER_STATE_CHECK(full_itxfm_(test_coef_block1, dst1, size));
123 ASM_REGISTER_STATE_CHECK(partial_itxfm_(test_coef_block1, dst2, size)); 211 ASM_REGISTER_STATE_CHECK(partial_itxfm_(test_coef_block1, dst2, size));
124 212
125 for (int j = 0; j < block_size; ++j) { 213 for (int j = 0; j < block_size; ++j) {
126 const int diff = dst1[j] - dst2[j]; 214 const int diff = dst1[j] - dst2[j];
127 const int error = diff * diff; 215 const int error = diff * diff;
128 if (max_error < error) 216 if (max_error < error)
129 max_error = error; 217 max_error = error;
130 } 218 }
131 } 219 }
132 220
133 EXPECT_EQ(0, max_error) 221 EXPECT_EQ(0, max_error)
134 << "Error: partial inverse transform produces different results"; 222 << "Error: partial inverse transform produces different results";
135 } 223 }
136 224
137 TEST_P(PartialIDctTest, ResultsMatch) { 225 TEST_P(Vp10PartialIDctTest, ResultsMatch) {
138 ACMRandom rnd(ACMRandom::DeterministicSeed()); 226 ACMRandom rnd(ACMRandom::DeterministicSeed());
139 int size; 227 int size;
140 switch (tx_size_) { 228 switch (tx_size_) {
141 case TX_4X4: 229 case TX_4X4:
142 size = 4; 230 size = 4;
143 break; 231 break;
144 case TX_8X8: 232 case TX_8X8:
145 size = 8; 233 size = 8;
146 break; 234 break;
147 case TX_16X16: 235 case TX_16X16:
(...skipping 22 matching lines...) Expand all
170 memset(test_coef_block2, 0, sizeof(*test_coef_block2) * block_size); 258 memset(test_coef_block2, 0, sizeof(*test_coef_block2) * block_size);
171 int max_energy_leftover = max_coeff * max_coeff; 259 int max_energy_leftover = max_coeff * max_coeff;
172 for (int j = 0; j < last_nonzero_; ++j) { 260 for (int j = 0; j < last_nonzero_; ++j) {
173 int16_t coef = static_cast<int16_t>(sqrt(1.0 * max_energy_leftover) * 261 int16_t coef = static_cast<int16_t>(sqrt(1.0 * max_energy_leftover) *
174 (rnd.Rand16() - 32768) / 65536); 262 (rnd.Rand16() - 32768) / 65536);
175 max_energy_leftover -= coef * coef; 263 max_energy_leftover -= coef * coef;
176 if (max_energy_leftover < 0) { 264 if (max_energy_leftover < 0) {
177 max_energy_leftover = 0; 265 max_energy_leftover = 0;
178 coef = 0; 266 coef = 0;
179 } 267 }
180 test_coef_block1[vp9_default_scan_orders[tx_size_].scan[j]] = coef; 268 test_coef_block1[vp10_default_scan_orders[tx_size_].scan[j]] = coef;
181 } 269 }
182 270
183 memcpy(test_coef_block2, test_coef_block1, 271 memcpy(test_coef_block2, test_coef_block1,
184 sizeof(*test_coef_block2) * block_size); 272 sizeof(*test_coef_block2) * block_size);
185 273
186 ASM_REGISTER_STATE_CHECK(full_itxfm_(test_coef_block1, dst1, size)); 274 ASM_REGISTER_STATE_CHECK(full_itxfm_(test_coef_block1, dst1, size));
187 ASM_REGISTER_STATE_CHECK(partial_itxfm_(test_coef_block2, dst2, size)); 275 ASM_REGISTER_STATE_CHECK(partial_itxfm_(test_coef_block2, dst2, size));
188 276
189 for (int j = 0; j < block_size; ++j) { 277 for (int j = 0; j < block_size; ++j) {
190 const int diff = dst1[j] - dst2[j]; 278 const int diff = dst1[j] - dst2[j];
191 const int error = diff * diff; 279 const int error = diff * diff;
192 if (max_error < error) 280 if (max_error < error)
193 max_error = error; 281 max_error = error;
194 } 282 }
195 } 283 }
196 284
197 EXPECT_EQ(0, max_error) 285 EXPECT_EQ(0, max_error)
198 << "Error: partial inverse transform produces different results"; 286 << "Error: partial inverse transform produces different results";
199 } 287 }
200 using std::tr1::make_tuple; 288 using std::tr1::make_tuple;
201 289
202 INSTANTIATE_TEST_CASE_P( 290 INSTANTIATE_TEST_CASE_P(
203 C, PartialIDctTest, 291 C, Vp10PartialIDctTest,
204 ::testing::Values( 292 ::testing::Values(
205 make_tuple(&vpx_fdct32x32_c, 293 make_tuple(&vpx_fdct32x32_c,
206 &vpx_idct32x32_1024_add_c, 294 &vp10_idct32x32_1024_add_c,
207 &vpx_idct32x32_34_add_c, 295 &vp10_idct32x32_34_add_c,
208 TX_32X32, 34), 296 TX_32X32, 34),
209 make_tuple(&vpx_fdct32x32_c, 297 make_tuple(&vpx_fdct32x32_c,
210 &vpx_idct32x32_1024_add_c, 298 &vp10_idct32x32_1024_add_c,
211 &vpx_idct32x32_1_add_c, 299 &vp10_idct32x32_1_add_c,
212 TX_32X32, 1), 300 TX_32X32, 1),
213 make_tuple(&vpx_fdct16x16_c, 301 make_tuple(&vpx_fdct16x16_c,
214 &vpx_idct16x16_256_add_c, 302 &vp10_idct16x16_256_add_c,
215 &vpx_idct16x16_10_add_c, 303 &vp10_idct16x16_10_add_c,
216 TX_16X16, 10), 304 TX_16X16, 10),
217 make_tuple(&vpx_fdct16x16_c, 305 make_tuple(&vpx_fdct16x16_c,
218 &vpx_idct16x16_256_add_c, 306 &vp10_idct16x16_256_add_c,
219 &vpx_idct16x16_1_add_c, 307 &vp10_idct16x16_1_add_c,
220 TX_16X16, 1), 308 TX_16X16, 1),
221 make_tuple(&vpx_fdct8x8_c, 309 make_tuple(&vpx_fdct8x8_c,
222 &vpx_idct8x8_64_add_c, 310 &vp10_idct8x8_64_add_c,
223 &vpx_idct8x8_12_add_c, 311 &vp10_idct8x8_12_add_c,
224 TX_8X8, 12), 312 TX_8X8, 12),
225 make_tuple(&vpx_fdct8x8_c, 313 make_tuple(&vpx_fdct8x8_c,
226 &vpx_idct8x8_64_add_c, 314 &vp10_idct8x8_64_add_c,
227 &vpx_idct8x8_1_add_c, 315 &vp10_idct8x8_1_add_c,
228 TX_8X8, 1), 316 TX_8X8, 1),
229 make_tuple(&vpx_fdct4x4_c, 317 make_tuple(&vpx_fdct4x4_c,
230 &vpx_idct4x4_16_add_c, 318 &vp10_idct4x4_16_add_c,
231 &vpx_idct4x4_1_add_c, 319 &vp10_idct4x4_1_add_c,
232 TX_4X4, 1))); 320 TX_4X4, 1)));
233
234 #if HAVE_NEON && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE
235 INSTANTIATE_TEST_CASE_P(
236 NEON, PartialIDctTest,
237 ::testing::Values(
238 make_tuple(&vpx_fdct32x32_c,
239 &vpx_idct32x32_1024_add_c,
240 &vpx_idct32x32_1_add_neon,
241 TX_32X32, 1),
242 make_tuple(&vpx_fdct16x16_c,
243 &vpx_idct16x16_256_add_c,
244 &vpx_idct16x16_10_add_neon,
245 TX_16X16, 10),
246 make_tuple(&vpx_fdct16x16_c,
247 &vpx_idct16x16_256_add_c,
248 &vpx_idct16x16_1_add_neon,
249 TX_16X16, 1),
250 make_tuple(&vpx_fdct8x8_c,
251 &vpx_idct8x8_64_add_c,
252 &vpx_idct8x8_12_add_neon,
253 TX_8X8, 12),
254 make_tuple(&vpx_fdct8x8_c,
255 &vpx_idct8x8_64_add_c,
256 &vpx_idct8x8_1_add_neon,
257 TX_8X8, 1),
258 make_tuple(&vpx_fdct4x4_c,
259 &vpx_idct4x4_16_add_c,
260 &vpx_idct4x4_1_add_neon,
261 TX_4X4, 1)));
262 #endif // HAVE_NEON && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE
263
264 #if HAVE_SSE2 && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE
265 INSTANTIATE_TEST_CASE_P(
266 SSE2, PartialIDctTest,
267 ::testing::Values(
268 make_tuple(&vpx_fdct32x32_c,
269 &vpx_idct32x32_1024_add_c,
270 &vpx_idct32x32_34_add_sse2,
271 TX_32X32, 34),
272 make_tuple(&vpx_fdct32x32_c,
273 &vpx_idct32x32_1024_add_c,
274 &vpx_idct32x32_1_add_sse2,
275 TX_32X32, 1),
276 make_tuple(&vpx_fdct16x16_c,
277 &vpx_idct16x16_256_add_c,
278 &vpx_idct16x16_10_add_sse2,
279 TX_16X16, 10),
280 make_tuple(&vpx_fdct16x16_c,
281 &vpx_idct16x16_256_add_c,
282 &vpx_idct16x16_1_add_sse2,
283 TX_16X16, 1),
284 make_tuple(&vpx_fdct8x8_c,
285 &vpx_idct8x8_64_add_c,
286 &vpx_idct8x8_12_add_sse2,
287 TX_8X8, 12),
288 make_tuple(&vpx_fdct8x8_c,
289 &vpx_idct8x8_64_add_c,
290 &vpx_idct8x8_1_add_sse2,
291 TX_8X8, 1),
292 make_tuple(&vpx_fdct4x4_c,
293 &vpx_idct4x4_16_add_c,
294 &vpx_idct4x4_1_add_sse2,
295 TX_4X4, 1)));
296 #endif
297
298 #if HAVE_SSSE3 && CONFIG_USE_X86INC && ARCH_X86_64 && \
299 !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE
300 INSTANTIATE_TEST_CASE_P(
301 SSSE3_64, PartialIDctTest,
302 ::testing::Values(
303 make_tuple(&vpx_fdct8x8_c,
304 &vpx_idct8x8_64_add_c,
305 &vpx_idct8x8_12_add_ssse3,
306 TX_8X8, 12)));
307 #endif
308
309 #if HAVE_MSA && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE
310 INSTANTIATE_TEST_CASE_P(
311 MSA, PartialIDctTest,
312 ::testing::Values(
313 make_tuple(&vpx_fdct32x32_c,
314 &vpx_idct32x32_1024_add_c,
315 &vpx_idct32x32_34_add_msa,
316 TX_32X32, 34),
317 make_tuple(&vpx_fdct32x32_c,
318 &vpx_idct32x32_1024_add_c,
319 &vpx_idct32x32_1_add_msa,
320 TX_32X32, 1),
321 make_tuple(&vpx_fdct16x16_c,
322 &vpx_idct16x16_256_add_c,
323 &vpx_idct16x16_10_add_msa,
324 TX_16X16, 10),
325 make_tuple(&vpx_fdct16x16_c,
326 &vpx_idct16x16_256_add_c,
327 &vpx_idct16x16_1_add_msa,
328 TX_16X16, 1),
329 make_tuple(&vpx_fdct8x8_c,
330 &vpx_idct8x8_64_add_c,
331 &vpx_idct8x8_12_add_msa,
332 TX_8X8, 10),
333 make_tuple(&vpx_fdct8x8_c,
334 &vpx_idct8x8_64_add_c,
335 &vpx_idct8x8_1_add_msa,
336 TX_8X8, 1),
337 make_tuple(&vpx_fdct4x4_c,
338 &vpx_idct4x4_16_add_c,
339 &vpx_idct4x4_1_add_msa,
340 TX_4X4, 1)));
341 #endif // HAVE_MSA && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE
342
343 } // namespace 321 } // namespace
OLDNEW
« no previous file with comments | « source/libvpx/test/video_source.h ('k') | source/libvpx/third_party/libwebm/README.libvpx » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698