2 * Copyright (c) 2012 The WebM project authors. All Rights Reserved.
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.
15 #include "third_party/googletest/src/include/gtest/gtest.h"
16 #include "test/acm_random.h"
17 #include "test/clear_system_state.h"
18 #include "test/register_state_check.h"
19 #include "test/util.h"
21 #include "./vp9_rtcd.h"
22 #include "vp9/common/vp9_entropy.h"
23 #include "vpx/vpx_integer.h"
26 void vp9_idct4x4_16_add_c(const int16_t *input, uint8_t *output, int pitch);
29 using libvpx_test::ACMRandom;
32 const int kNumCoeffs = 16;
33 typedef void (*fdct_t)(const int16_t *in, int16_t *out, int stride);
34 typedef void (*idct_t)(const int16_t *in, uint8_t *out, int stride);
35 typedef void (*fht_t) (const int16_t *in, int16_t *out, int stride,
37 typedef void (*iht_t) (const int16_t *in, uint8_t *out, int stride,
40 typedef std::tr1::tuple<fdct_t, idct_t, int> dct_4x4_param_t;
41 typedef std::tr1::tuple<fht_t, iht_t, int> ht_4x4_param_t;
43 void fdct4x4_ref(const int16_t *in, int16_t *out, int stride, int tx_type) {
44 vp9_fdct4x4_c(in, out, stride);
47 void fht4x4_ref(const int16_t *in, int16_t *out, int stride, int tx_type) {
48 vp9_fht4x4_c(in, out, stride, tx_type);
51 class Trans4x4TestBase {
53 virtual ~Trans4x4TestBase() {}
56 virtual void RunFwdTxfm(const int16_t *in, int16_t *out, int stride) = 0;
58 virtual void RunInvTxfm(const int16_t *out, uint8_t *dst, int stride) = 0;
60 void RunAccuracyCheck() {
61 ACMRandom rnd(ACMRandom::DeterministicSeed());
62 uint32_t max_error = 0;
63 int64_t total_error = 0;
64 const int count_test_block = 10000;
65 for (int i = 0; i < count_test_block; ++i) {
66 DECLARE_ALIGNED_ARRAY(16, int16_t, test_input_block, kNumCoeffs);
67 DECLARE_ALIGNED_ARRAY(16, int16_t, test_temp_block, kNumCoeffs);
68 DECLARE_ALIGNED_ARRAY(16, uint8_t, dst, kNumCoeffs);
69 DECLARE_ALIGNED_ARRAY(16, uint8_t, src, kNumCoeffs);
71 // Initialize a test block with input range [-255, 255].
72 for (int j = 0; j < kNumCoeffs; ++j) {
75 test_input_block[j] = src[j] - dst[j];
78 REGISTER_STATE_CHECK(RunFwdTxfm(test_input_block,
79 test_temp_block, pitch_));
80 REGISTER_STATE_CHECK(RunInvTxfm(test_temp_block, dst, pitch_));
82 for (int j = 0; j < kNumCoeffs; ++j) {
83 const uint32_t diff = dst[j] - src[j];
84 const uint32_t error = diff * diff;
85 if (max_error < error)
91 EXPECT_GE(1u, max_error)
92 << "Error: 4x4 FHT/IHT has an individual round trip error > 1";
94 EXPECT_GE(count_test_block , total_error)
95 << "Error: 4x4 FHT/IHT has average round trip error > 1 per block";
98 void RunCoeffCheck() {
99 ACMRandom rnd(ACMRandom::DeterministicSeed());
100 const int count_test_block = 5000;
101 DECLARE_ALIGNED_ARRAY(16, int16_t, input_block, kNumCoeffs);
102 DECLARE_ALIGNED_ARRAY(16, int16_t, output_ref_block, kNumCoeffs);
103 DECLARE_ALIGNED_ARRAY(16, int16_t, output_block, kNumCoeffs);
105 for (int i = 0; i < count_test_block; ++i) {
106 // Initialize a test block with input range [-255, 255].
107 for (int j = 0; j < kNumCoeffs; ++j)
108 input_block[j] = rnd.Rand8() - rnd.Rand8();
110 fwd_txfm_ref(input_block, output_ref_block, pitch_, tx_type_);
111 REGISTER_STATE_CHECK(RunFwdTxfm(input_block, output_block, pitch_));
113 // The minimum quant value is 4.
114 for (int j = 0; j < kNumCoeffs; ++j)
115 EXPECT_EQ(output_block[j], output_ref_block[j]);
120 ACMRandom rnd(ACMRandom::DeterministicSeed());
121 const int count_test_block = 5000;
122 DECLARE_ALIGNED_ARRAY(16, int16_t, input_block, kNumCoeffs);
123 DECLARE_ALIGNED_ARRAY(16, int16_t, input_extreme_block, kNumCoeffs);
124 DECLARE_ALIGNED_ARRAY(16, int16_t, output_ref_block, kNumCoeffs);
125 DECLARE_ALIGNED_ARRAY(16, int16_t, output_block, kNumCoeffs);
127 for (int i = 0; i < count_test_block; ++i) {
128 // Initialize a test block with input range [-255, 255].
129 for (int j = 0; j < kNumCoeffs; ++j) {
130 input_block[j] = rnd.Rand8() - rnd.Rand8();
131 input_extreme_block[j] = rnd.Rand8() % 2 ? 255 : -255;
134 for (int j = 0; j < kNumCoeffs; ++j)
135 input_extreme_block[j] = 255;
137 for (int j = 0; j < kNumCoeffs; ++j)
138 input_extreme_block[j] = -255;
140 fwd_txfm_ref(input_extreme_block, output_ref_block, pitch_, tx_type_);
141 REGISTER_STATE_CHECK(RunFwdTxfm(input_extreme_block,
142 output_block, pitch_));
144 // The minimum quant value is 4.
145 for (int j = 0; j < kNumCoeffs; ++j) {
146 EXPECT_EQ(output_block[j], output_ref_block[j]);
147 EXPECT_GE(4 * DCT_MAX_VALUE, abs(output_block[j]))
148 << "Error: 16x16 FDCT has coefficient larger than 4*DCT_MAX_VALUE";
153 void RunInvAccuracyCheck() {
154 ACMRandom rnd(ACMRandom::DeterministicSeed());
155 const int count_test_block = 1000;
156 DECLARE_ALIGNED_ARRAY(16, int16_t, in, kNumCoeffs);
157 DECLARE_ALIGNED_ARRAY(16, int16_t, coeff, kNumCoeffs);
158 DECLARE_ALIGNED_ARRAY(16, uint8_t, dst, kNumCoeffs);
159 DECLARE_ALIGNED_ARRAY(16, uint8_t, src, kNumCoeffs);
161 for (int i = 0; i < count_test_block; ++i) {
162 // Initialize a test block with input range [-255, 255].
163 for (int j = 0; j < kNumCoeffs; ++j) {
164 src[j] = rnd.Rand8();
165 dst[j] = rnd.Rand8();
166 in[j] = src[j] - dst[j];
169 fwd_txfm_ref(in, coeff, pitch_, tx_type_);
171 REGISTER_STATE_CHECK(RunInvTxfm(coeff, dst, pitch_));
173 for (int j = 0; j < kNumCoeffs; ++j) {
174 const uint32_t diff = dst[j] - src[j];
175 const uint32_t error = diff * diff;
177 << "Error: 16x16 IDCT has error " << error
178 << " at index " << j;
189 : public Trans4x4TestBase,
190 public ::testing::TestWithParam<dct_4x4_param_t> {
192 virtual ~Trans4x4DCT() {}
194 virtual void SetUp() {
195 fwd_txfm_ = GET_PARAM(0);
196 inv_txfm_ = GET_PARAM(1);
197 tx_type_ = GET_PARAM(2);
199 fwd_txfm_ref = fdct4x4_ref;
201 virtual void TearDown() { libvpx_test::ClearSystemState(); }
204 void RunFwdTxfm(const int16_t *in, int16_t *out, int stride) {
205 fwd_txfm_(in, out, stride);
207 void RunInvTxfm(const int16_t *out, uint8_t *dst, int stride) {
208 inv_txfm_(out, dst, stride);
215 TEST_P(Trans4x4DCT, AccuracyCheck) {
219 TEST_P(Trans4x4DCT, CoeffCheck) {
223 TEST_P(Trans4x4DCT, MemCheck) {
227 TEST_P(Trans4x4DCT, InvAccuracyCheck) {
228 RunInvAccuracyCheck();
232 : public Trans4x4TestBase,
233 public ::testing::TestWithParam<ht_4x4_param_t> {
235 virtual ~Trans4x4HT() {}
237 virtual void SetUp() {
238 fwd_txfm_ = GET_PARAM(0);
239 inv_txfm_ = GET_PARAM(1);
240 tx_type_ = GET_PARAM(2);
242 fwd_txfm_ref = fht4x4_ref;
244 virtual void TearDown() { libvpx_test::ClearSystemState(); }
247 void RunFwdTxfm(const int16_t *in, int16_t *out, int stride) {
248 fwd_txfm_(in, out, stride, tx_type_);
251 void RunInvTxfm(const int16_t *out, uint8_t *dst, int stride) {
252 inv_txfm_(out, dst, stride, tx_type_);
259 TEST_P(Trans4x4HT, AccuracyCheck) {
263 TEST_P(Trans4x4HT, CoeffCheck) {
267 TEST_P(Trans4x4HT, MemCheck) {
271 TEST_P(Trans4x4HT, InvAccuracyCheck) {
272 RunInvAccuracyCheck();
275 using std::tr1::make_tuple;
277 INSTANTIATE_TEST_CASE_P(
280 make_tuple(&vp9_fdct4x4_c, &vp9_idct4x4_16_add_c, 0)));
281 INSTANTIATE_TEST_CASE_P(
284 make_tuple(&vp9_fht4x4_c, &vp9_iht4x4_16_add_c, 0),
285 make_tuple(&vp9_fht4x4_c, &vp9_iht4x4_16_add_c, 1),
286 make_tuple(&vp9_fht4x4_c, &vp9_iht4x4_16_add_c, 2),
287 make_tuple(&vp9_fht4x4_c, &vp9_iht4x4_16_add_c, 3)));
290 INSTANTIATE_TEST_CASE_P(
293 make_tuple(&vp9_fdct4x4_sse2,
294 &vp9_idct4x4_16_add_sse2, 0)));
295 INSTANTIATE_TEST_CASE_P(
298 make_tuple(&vp9_fht4x4_sse2, &vp9_iht4x4_16_add_sse2, 0),
299 make_tuple(&vp9_fht4x4_sse2, &vp9_iht4x4_16_add_sse2, 1),
300 make_tuple(&vp9_fht4x4_sse2, &vp9_iht4x4_16_add_sse2, 2),
301 make_tuple(&vp9_fht4x4_sse2, &vp9_iht4x4_16_add_sse2, 3)));