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 "vpx_ports/mem.h"
20 void vp9_short_idct8x8_add_c(short *input
, uint8_t *output
, int pitch
);
23 #include "acm_random.h"
24 #include "vpx/vpx_integer.h"
26 using libvpx_test::ACMRandom
;
29 void fdct8x8(int16_t *in
, int16_t *out
, uint8_t* /*dst*/,
30 int stride
, int /*tx_type*/) {
31 vp9_short_fdct8x8_c(in
, out
, stride
);
33 void idct8x8_add(int16_t* /*in*/, int16_t *out
, uint8_t *dst
,
34 int stride
, int /*tx_type*/) {
35 vp9_short_idct8x8_add_c(out
, dst
, stride
>> 1);
37 void fht8x8(int16_t *in
, int16_t *out
, uint8_t* /*dst*/,
38 int stride
, int tx_type
) {
39 // TODO(jingning): need to refactor this to test both _c and _sse2 functions,
40 // when we have all inverse dct functions done sse2.
42 vp9_short_fht8x8_sse2(in
, out
, stride
>> 1, tx_type
);
44 vp9_short_fht8x8_c(in
, out
, stride
>> 1, tx_type
);
47 void iht8x8_add(int16_t* /*in*/, int16_t *out
, uint8_t *dst
,
48 int stride
, int tx_type
) {
49 vp9_short_iht8x8_add_c(out
, dst
, stride
>> 1, tx_type
);
52 class FwdTrans8x8Test
: public ::testing::TestWithParam
<int> {
54 virtual ~FwdTrans8x8Test() {}
55 virtual void SetUp() {
56 tx_type_
= GetParam();
59 inv_txfm
= idct8x8_add
;
62 inv_txfm
= iht8x8_add
;
67 void RunFwdTxfm(int16_t *in
, int16_t *out
, uint8_t *dst
,
68 int stride
, int tx_type
) {
69 (*fwd_txfm
)(in
, out
, dst
, stride
, tx_type
);
71 void RunInvTxfm(int16_t *in
, int16_t *out
, uint8_t *dst
,
72 int stride
, int tx_type
) {
73 (*inv_txfm
)(in
, out
, dst
, stride
, tx_type
);
77 void (*fwd_txfm
)(int16_t*, int16_t*, uint8_t*, int, int);
78 void (*inv_txfm
)(int16_t*, int16_t*, uint8_t*, int, int);
81 TEST_P(FwdTrans8x8Test
, SignBiasCheck
) {
82 ACMRandom
rnd(ACMRandom::DeterministicSeed());
83 DECLARE_ALIGNED_ARRAY(16, int16_t, test_input_block
, 64);
84 DECLARE_ALIGNED_ARRAY(16, int16_t, test_output_block
, 64);
86 int count_sign_block
[64][2];
87 const int count_test_block
= 100000;
89 memset(count_sign_block
, 0, sizeof(count_sign_block
));
91 for (int i
= 0; i
< count_test_block
; ++i
) {
92 // Initialize a test block with input range [-255, 255].
93 for (int j
= 0; j
< 64; ++j
)
94 test_input_block
[j
] = rnd
.Rand8() - rnd
.Rand8();
96 RunFwdTxfm(test_input_block
, test_output_block
, NULL
, pitch
, tx_type_
);
98 for (int j
= 0; j
< 64; ++j
) {
99 if (test_output_block
[j
] < 0)
100 ++count_sign_block
[j
][0];
101 else if (test_output_block
[j
] > 0)
102 ++count_sign_block
[j
][1];
106 for (int j
= 0; j
< 64; ++j
) {
107 const int diff
= abs(count_sign_block
[j
][0] - count_sign_block
[j
][1]);
108 const int max_diff
= 1125;
109 EXPECT_LT(diff
, max_diff
)
110 << "Error: 8x8 FDCT/FHT has a sign bias > "
111 << 1. * max_diff
/ count_test_block
* 100 << "%"
112 << " for input range [-255, 255] at index " << j
113 << " count0: " << count_sign_block
[j
][0]
114 << " count1: " << count_sign_block
[j
][1]
115 << " diff: " << diff
;
118 memset(count_sign_block
, 0, sizeof(count_sign_block
));
120 for (int i
= 0; i
< count_test_block
; ++i
) {
121 // Initialize a test block with input range [-15, 15].
122 for (int j
= 0; j
< 64; ++j
)
123 test_input_block
[j
] = (rnd
.Rand8() >> 4) - (rnd
.Rand8() >> 4);
125 RunFwdTxfm(test_input_block
, test_output_block
, NULL
, pitch
, tx_type_
);
127 for (int j
= 0; j
< 64; ++j
) {
128 if (test_output_block
[j
] < 0)
129 ++count_sign_block
[j
][0];
130 else if (test_output_block
[j
] > 0)
131 ++count_sign_block
[j
][1];
135 for (int j
= 0; j
< 64; ++j
) {
136 const int diff
= abs(count_sign_block
[j
][0] - count_sign_block
[j
][1]);
137 const int max_diff
= 10000;
138 EXPECT_LT(diff
, max_diff
)
139 << "Error: 4x4 FDCT/FHT has a sign bias > "
140 << 1. * max_diff
/ count_test_block
* 100 << "%"
141 << " for input range [-15, 15] at index " << j
142 << " count0: " << count_sign_block
[j
][0]
143 << " count1: " << count_sign_block
[j
][1]
144 << " diff: " << diff
;
148 TEST_P(FwdTrans8x8Test
, RoundTripErrorCheck
) {
149 ACMRandom
rnd(ACMRandom::DeterministicSeed());
151 double total_error
= 0;
152 const int count_test_block
= 100000;
153 for (int i
= 0; i
< count_test_block
; ++i
) {
154 DECLARE_ALIGNED_ARRAY(16, int16_t, test_input_block
, 64);
155 DECLARE_ALIGNED_ARRAY(16, int16_t, test_temp_block
, 64);
156 DECLARE_ALIGNED_ARRAY(16, uint8_t, dst
, 64);
157 DECLARE_ALIGNED_ARRAY(16, uint8_t, src
, 64);
159 for (int j
= 0; j
< 64; ++j
) {
160 src
[j
] = rnd
.Rand8();
161 dst
[j
] = rnd
.Rand8();
163 // Initialize a test block with input range [-255, 255].
164 for (int j
= 0; j
< 64; ++j
)
165 test_input_block
[j
] = src
[j
] - dst
[j
];
167 const int pitch
= 16;
168 RunFwdTxfm(test_input_block
, test_temp_block
, dst
, pitch
, tx_type_
);
169 for (int j
= 0; j
< 64; ++j
){
170 if(test_temp_block
[j
] > 0) {
171 test_temp_block
[j
] += 2;
172 test_temp_block
[j
] /= 4;
173 test_temp_block
[j
] *= 4;
175 test_temp_block
[j
] -= 2;
176 test_temp_block
[j
] /= 4;
177 test_temp_block
[j
] *= 4;
180 RunInvTxfm(test_input_block
, test_temp_block
, dst
, pitch
, tx_type_
);
182 for (int j
= 0; j
< 64; ++j
) {
183 const int diff
= dst
[j
] - src
[j
];
184 const int error
= diff
* diff
;
185 if (max_error
< error
)
187 total_error
+= error
;
191 EXPECT_GE(1, max_error
)
192 << "Error: 8x8 FDCT/IDCT or FHT/IHT has an individual roundtrip error > 1";
194 EXPECT_GE(count_test_block
/5, total_error
)
195 << "Error: 8x8 FDCT/IDCT or FHT/IHT has average roundtrip "
196 "error > 1/5 per block";
199 TEST_P(FwdTrans8x8Test
, ExtremalCheck
) {
200 ACMRandom
rnd(ACMRandom::DeterministicSeed());
202 double total_error
= 0;
203 const int count_test_block
= 100000;
204 for (int i
= 0; i
< count_test_block
; ++i
) {
205 DECLARE_ALIGNED_ARRAY(16, int16_t, test_input_block
, 64);
206 DECLARE_ALIGNED_ARRAY(16, int16_t, test_temp_block
, 64);
207 DECLARE_ALIGNED_ARRAY(16, uint8_t, dst
, 64);
208 DECLARE_ALIGNED_ARRAY(16, uint8_t, src
, 64);
210 for (int j
= 0; j
< 64; ++j
) {
211 src
[j
] = rnd
.Rand8() % 2 ? 255 : 0;
212 dst
[j
] = src
[j
] > 0 ? 0 : 255;
214 // Initialize a test block with input range [-255, 255].
215 for (int j
= 0; j
< 64; ++j
)
216 test_input_block
[j
] = src
[j
] - dst
[j
];
218 const int pitch
= 16;
219 RunFwdTxfm(test_input_block
, test_temp_block
, dst
, pitch
, tx_type_
);
220 RunInvTxfm(test_input_block
, test_temp_block
, dst
, pitch
, tx_type_
);
222 for (int j
= 0; j
< 64; ++j
) {
223 const int diff
= dst
[j
] - src
[j
];
224 const int error
= diff
* diff
;
225 if (max_error
< error
)
227 total_error
+= error
;
230 EXPECT_GE(1, max_error
)
231 << "Error: Extremal 8x8 FDCT/IDCT or FHT/IHT has an"
232 << " individual roundtrip error > 1";
234 EXPECT_GE(count_test_block
/5, total_error
)
235 << "Error: Extremal 8x8 FDCT/IDCT or FHT/IHT has average"
236 << " roundtrip error > 1/5 per block";
240 INSTANTIATE_TEST_CASE_P(VP9
, FwdTrans8x8Test
, ::testing::Range(0, 4));