OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 | |
11 | 10 |
12 #include <math.h> | 11 #include <math.h> |
13 #include <stddef.h> | |
14 #include <stdio.h> | |
15 #include <stdlib.h> | 12 #include <stdlib.h> |
16 #include <string.h> | 13 #include <string.h> |
17 #include <sys/types.h> | |
18 | 14 |
| 15 #include "third_party/googletest/src/include/gtest/gtest.h" |
19 | 16 |
20 extern "C" { | 17 extern "C" { |
21 #include "vpx_rtcd.h" | 18 #include "vp9_rtcd.h" |
22 } | 19 } |
23 | 20 |
24 #include "test/acm_random.h" | 21 #include "acm_random.h" |
25 #include "third_party/googletest/src/include/gtest/gtest.h" | |
26 #include "vpx/vpx_integer.h" | 22 #include "vpx/vpx_integer.h" |
27 | 23 |
| 24 using libvpx_test::ACMRandom; |
28 | 25 |
29 namespace { | 26 namespace { |
30 | 27 |
31 const int cospi8sqrt2minus1 = 20091; | 28 TEST(Vp9FdctTest, SignBiasCheck) { |
32 const int sinpi8sqrt2 = 35468; | |
33 | |
34 void reference_idct4x4(const int16_t *input, int16_t *output) { | |
35 const int16_t *ip = input; | |
36 int16_t *op = output; | |
37 | |
38 for (int i = 0; i < 4; ++i) { | |
39 const int a1 = ip[0] + ip[8]; | |
40 const int b1 = ip[0] - ip[8]; | |
41 const int temp1 = (ip[4] * sinpi8sqrt2) >> 16; | |
42 const int temp2 = ip[12] + ((ip[12] * cospi8sqrt2minus1) >> 16); | |
43 const int c1 = temp1 - temp2; | |
44 const int temp3 = ip[4] + ((ip[4] * cospi8sqrt2minus1) >> 16); | |
45 const int temp4 = (ip[12] * sinpi8sqrt2) >> 16; | |
46 const int d1 = temp3 + temp4; | |
47 op[0] = a1 + d1; | |
48 op[12] = a1 - d1; | |
49 op[4] = b1 + c1; | |
50 op[8] = b1 - c1; | |
51 ++ip; | |
52 ++op; | |
53 } | |
54 ip = output; | |
55 op = output; | |
56 for (int i = 0; i < 4; ++i) { | |
57 const int a1 = ip[0] + ip[2]; | |
58 const int b1 = ip[0] - ip[2]; | |
59 const int temp1 = (ip[1] * sinpi8sqrt2) >> 16; | |
60 const int temp2 = ip[3] + ((ip[3] * cospi8sqrt2minus1) >> 16); | |
61 const int c1 = temp1 - temp2; | |
62 const int temp3 = ip[1] + ((ip[1] * cospi8sqrt2minus1) >> 16); | |
63 const int temp4 = (ip[3] * sinpi8sqrt2) >> 16; | |
64 const int d1 = temp3 + temp4; | |
65 op[0] = (a1 + d1 + 4) >> 3; | |
66 op[3] = (a1 - d1 + 4) >> 3; | |
67 op[1] = (b1 + c1 + 4) >> 3; | |
68 op[2] = (b1 - c1 + 4) >> 3; | |
69 ip += 4; | |
70 op += 4; | |
71 } | |
72 } | |
73 | |
74 using libvpx_test::ACMRandom; | |
75 | |
76 TEST(Vp8FdctTest, SignBiasCheck) { | |
77 ACMRandom rnd(ACMRandom::DeterministicSeed()); | 29 ACMRandom rnd(ACMRandom::DeterministicSeed()); |
78 int16_t test_input_block[16]; | 30 int16_t test_input_block[16]; |
79 int16_t test_output_block[16]; | 31 int16_t test_output_block[16]; |
80 const int pitch = 8; | 32 const int pitch = 8; |
81 int count_sign_block[16][2]; | 33 int count_sign_block[16][2]; |
82 const int count_test_block = 1000000; | 34 const int count_test_block = 1000000; |
83 | 35 |
84 memset(count_sign_block, 0, sizeof(count_sign_block)); | 36 memset(count_sign_block, 0, sizeof(count_sign_block)); |
85 | 37 |
86 for (int i = 0; i < count_test_block; ++i) { | 38 for (int i = 0; i < count_test_block; ++i) { |
87 // Initialize a test block with input range [-255, 255]. | 39 // Initialize a test block with input range [-255, 255]. |
88 for (int j = 0; j < 16; ++j) | 40 for (int j = 0; j < 16; ++j) |
89 test_input_block[j] = rnd.Rand8() - rnd.Rand8(); | 41 test_input_block[j] = rnd.Rand8() - rnd.Rand8(); |
90 | 42 |
91 vp8_short_fdct4x4_c(test_input_block, test_output_block, pitch); | 43 // TODO(Yaowu): this should be converted to a parameterized test |
| 44 // to test optimized versions of this function. |
| 45 vp9_short_fdct4x4_c(test_input_block, test_output_block, pitch); |
92 | 46 |
93 for (int j = 0; j < 16; ++j) { | 47 for (int j = 0; j < 16; ++j) { |
94 if (test_output_block[j] < 0) | 48 if (test_output_block[j] < 0) |
95 ++count_sign_block[j][0]; | 49 ++count_sign_block[j][0]; |
96 else if (test_output_block[j] > 0) | 50 else if (test_output_block[j] > 0) |
97 ++count_sign_block[j][1]; | 51 ++count_sign_block[j][1]; |
98 } | 52 } |
99 } | 53 } |
100 | 54 |
101 bool bias_acceptable = true; | 55 for (int j = 0; j < 16; ++j) { |
102 for (int j = 0; j < 16; ++j) | 56 const bool bias_acceptable = (abs(count_sign_block[j][0] - |
103 bias_acceptable = bias_acceptable && | 57 count_sign_block[j][1]) < 10000); |
104 (abs(count_sign_block[j][0] - count_sign_block[j][1]) < 10000); | 58 EXPECT_TRUE(bias_acceptable) |
105 | 59 << "Error: 4x4 FDCT has a sign bias > 1%" |
106 EXPECT_EQ(true, bias_acceptable) | 60 << " for input range [-255, 255] at index " << j; |
107 << "Error: 4x4 FDCT has a sign bias > 1% for input range [-255, 255]"; | 61 } |
108 | 62 |
109 memset(count_sign_block, 0, sizeof(count_sign_block)); | 63 memset(count_sign_block, 0, sizeof(count_sign_block)); |
110 | 64 |
111 for (int i = 0; i < count_test_block; ++i) { | 65 for (int i = 0; i < count_test_block; ++i) { |
112 // Initialize a test block with input range [-15, 15]. | 66 // Initialize a test block with input range [-15, 15]. |
113 for (int j = 0; j < 16; ++j) | 67 for (int j = 0; j < 16; ++j) |
114 test_input_block[j] = (rnd.Rand8() >> 4) - (rnd.Rand8() >> 4); | 68 test_input_block[j] = (rnd.Rand8() >> 4) - (rnd.Rand8() >> 4); |
115 | 69 |
116 vp8_short_fdct4x4_c(test_input_block, test_output_block, pitch); | 70 // TODO(Yaowu): this should be converted to a parameterized test |
| 71 // to test optimized versions of this function. |
| 72 vp9_short_fdct4x4_c(test_input_block, test_output_block, pitch); |
117 | 73 |
118 for (int j = 0; j < 16; ++j) { | 74 for (int j = 0; j < 16; ++j) { |
119 if (test_output_block[j] < 0) | 75 if (test_output_block[j] < 0) |
120 ++count_sign_block[j][0]; | 76 ++count_sign_block[j][0]; |
121 else if (test_output_block[j] > 0) | 77 else if (test_output_block[j] > 0) |
122 ++count_sign_block[j][1]; | 78 ++count_sign_block[j][1]; |
123 } | 79 } |
124 } | 80 } |
125 | 81 |
126 bias_acceptable = true; | 82 for (int j = 0; j < 16; ++j) { |
127 for (int j = 0; j < 16; ++j) | 83 const bool bias_acceptable = (abs(count_sign_block[j][0] - |
128 bias_acceptable = bias_acceptable && | 84 count_sign_block[j][1]) < 100000); |
129 (abs(count_sign_block[j][0] - count_sign_block[j][1]) < 100000); | 85 EXPECT_TRUE(bias_acceptable) |
130 | 86 << "Error: 4x4 FDCT has a sign bias > 10%" |
131 EXPECT_EQ(true, bias_acceptable) | 87 << " for input range [-15, 15] at index " << j; |
132 << "Error: 4x4 FDCT has a sign bias > 10% for input range [-15, 15]"; | 88 } |
133 }; | 89 }; |
134 | 90 |
135 TEST(Vp8FdctTest, RoundTripErrorCheck) { | 91 TEST(Vp9FdctTest, RoundTripErrorCheck) { |
136 ACMRandom rnd(ACMRandom::DeterministicSeed()); | 92 ACMRandom rnd(ACMRandom::DeterministicSeed()); |
137 int max_error = 0; | 93 int max_error = 0; |
138 double total_error = 0; | 94 double total_error = 0; |
139 const int count_test_block = 1000000; | 95 const int count_test_block = 1000000; |
140 for (int i = 0; i < count_test_block; ++i) { | 96 for (int i = 0; i < count_test_block; ++i) { |
141 int16_t test_input_block[16]; | 97 int16_t test_input_block[16]; |
142 int16_t test_temp_block[16]; | 98 int16_t test_temp_block[16]; |
143 int16_t test_output_block[16]; | 99 int16_t test_output_block[16]; |
144 | 100 |
145 // Initialize a test block with input range [-255, 255]. | 101 // Initialize a test block with input range [-255, 255]. |
146 for (int j = 0; j < 16; ++j) | 102 for (int j = 0; j < 16; ++j) |
147 test_input_block[j] = rnd.Rand8() - rnd.Rand8(); | 103 test_input_block[j] = rnd.Rand8() - rnd.Rand8(); |
148 | 104 |
| 105 // TODO(Yaowu): this should be converted to a parameterized test |
| 106 // to test optimized versions of this function. |
149 const int pitch = 8; | 107 const int pitch = 8; |
150 vp8_short_fdct4x4_c(test_input_block, test_temp_block, pitch); | 108 vp9_short_fdct4x4_c(test_input_block, test_temp_block, pitch); |
151 reference_idct4x4(test_temp_block, test_output_block); | 109 |
| 110 for (int j = 0; j < 16; ++j) { |
| 111 if(test_temp_block[j] > 0) { |
| 112 test_temp_block[j] += 2; |
| 113 test_temp_block[j] /= 4; |
| 114 test_temp_block[j] *= 4; |
| 115 } else { |
| 116 test_temp_block[j] -= 2; |
| 117 test_temp_block[j] /= 4; |
| 118 test_temp_block[j] *= 4; |
| 119 } |
| 120 } |
| 121 |
| 122 // Because the bitstream is not frozen yet, use the idct in the codebase. |
| 123 vp9_short_idct4x4llm_c(test_temp_block, test_output_block, pitch); |
152 | 124 |
153 for (int j = 0; j < 16; ++j) { | 125 for (int j = 0; j < 16; ++j) { |
154 const int diff = test_input_block[j] - test_output_block[j]; | 126 const int diff = test_input_block[j] - test_output_block[j]; |
155 const int error = diff * diff; | 127 const int error = diff * diff; |
156 if (max_error < error) | 128 if (max_error < error) |
157 max_error = error; | 129 max_error = error; |
158 total_error += error; | 130 total_error += error; |
159 } | 131 } |
160 } | 132 } |
161 | 133 EXPECT_GE(1, max_error) |
162 EXPECT_GE(1, max_error ) | 134 << "Error: FDCT/IDCT has an individual roundtrip error > 1"; |
163 << "Error: FDCT/IDCT has an individual roundtrip error > 1"; | |
164 | 135 |
165 EXPECT_GE(count_test_block, total_error) | 136 EXPECT_GE(count_test_block, total_error) |
166 << "Error: FDCT/IDCT has average roundtrip error > 1 per block"; | 137 << "Error: FDCT/IDCT has average roundtrip error > 1 per block"; |
167 }; | 138 }; |
168 | 139 |
169 } // namespace | 140 } // namespace |
OLD | NEW |