| 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 | 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 extern "C" { | 17 extern "C" { |
| 18 #include "vp9_rtcd.h" | 18 #include "vp9_rtcd.h" |
| 19 } | 19 } |
| 20 | 20 |
| 21 #include "acm_random.h" | 21 #include "acm_random.h" |
| 22 #include "vpx/vpx_integer.h" | 22 #include "vpx/vpx_integer.h" |
| 23 | 23 |
| 24 using libvpx_test::ACMRandom; | 24 using libvpx_test::ACMRandom; |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 void fdct4x4(int16_t *in, int16_t *out, uint8_t *dst, int stride, int tx_type) { |
| 28 vp9_short_fdct4x4_c(in, out, stride); |
| 29 } |
| 30 void idct4x4_add(int16_t *in, int16_t *out, uint8_t *dst, |
| 31 int stride, int tx_type) { |
| 32 vp9_short_idct4x4_add_c(out, dst, stride >> 1); |
| 33 } |
| 34 void fht4x4(int16_t *in, int16_t *out, uint8_t *dst, int stride, int tx_type) { |
| 35 vp9_short_fht4x4_c(in, out, stride >> 1, tx_type); |
| 36 } |
| 37 void iht4x4_add(int16_t *in, int16_t *out, uint8_t *dst, |
| 38 int stride, int tx_type) { |
| 39 vp9_short_iht4x4_add_c(out, dst, stride >> 1, tx_type); |
| 40 } |
| 27 | 41 |
| 28 TEST(Vp9Fdct4x4Test, SignBiasCheck) { | 42 class FwdTrans4x4Test : public ::testing::TestWithParam<int> { |
| 43 public: |
| 44 FwdTrans4x4Test() {SetUpTestTxfm();} |
| 45 ~FwdTrans4x4Test() {} |
| 46 |
| 47 void SetUpTestTxfm() { |
| 48 tx_type = GetParam(); |
| 49 if (tx_type == 0) { |
| 50 fwd_txfm = fdct4x4; |
| 51 inv_txfm = idct4x4_add; |
| 52 } else { |
| 53 fwd_txfm = fht4x4; |
| 54 inv_txfm = iht4x4_add; |
| 55 } |
| 56 } |
| 57 |
| 58 protected: |
| 59 void RunFwdTxfm(int16_t *in, int16_t *out, uint8_t *dst, |
| 60 int stride, int tx_type) { |
| 61 (*fwd_txfm)(in, out, dst, stride, tx_type); |
| 62 } |
| 63 |
| 64 void RunInvTxfm(int16_t *in, int16_t *out, uint8_t *dst, |
| 65 int stride, int tx_type) { |
| 66 (*inv_txfm)(in, out, dst, stride, tx_type); |
| 67 } |
| 68 |
| 69 int tx_type; |
| 70 void (*fwd_txfm)(int16_t *in, int16_t *out, uint8_t *dst, |
| 71 int stride, int tx_type); |
| 72 void (*inv_txfm)(int16_t *in, int16_t *out, uint8_t *dst, |
| 73 int stride, int tx_type); |
| 74 }; |
| 75 |
| 76 TEST_P(FwdTrans4x4Test, SignBiasCheck) { |
| 29 ACMRandom rnd(ACMRandom::DeterministicSeed()); | 77 ACMRandom rnd(ACMRandom::DeterministicSeed()); |
| 30 int16_t test_input_block[16]; | 78 int16_t test_input_block[16]; |
| 31 int16_t test_output_block[16]; | 79 int16_t test_output_block[16]; |
| 32 const int pitch = 8; | 80 const int pitch = 8; |
| 33 int count_sign_block[16][2]; | 81 int count_sign_block[16][2]; |
| 34 const int count_test_block = 1000000; | 82 const int count_test_block = 1000000; |
| 35 | 83 |
| 36 memset(count_sign_block, 0, sizeof(count_sign_block)); | 84 memset(count_sign_block, 0, sizeof(count_sign_block)); |
| 37 | |
| 38 for (int i = 0; i < count_test_block; ++i) { | 85 for (int i = 0; i < count_test_block; ++i) { |
| 39 // Initialize a test block with input range [-255, 255]. | 86 // Initialize a test block with input range [-255, 255]. |
| 40 for (int j = 0; j < 16; ++j) | 87 for (int j = 0; j < 16; ++j) |
| 41 test_input_block[j] = rnd.Rand8() - rnd.Rand8(); | 88 test_input_block[j] = rnd.Rand8() - rnd.Rand8(); |
| 42 | 89 |
| 43 // TODO(Yaowu): this should be converted to a parameterized test | 90 RunFwdTxfm(test_input_block, test_output_block, NULL, pitch, tx_type); |
| 44 // to test optimized versions of this function. | |
| 45 vp9_short_fdct4x4_c(test_input_block, test_output_block, pitch); | |
| 46 | 91 |
| 47 for (int j = 0; j < 16; ++j) { | 92 for (int j = 0; j < 16; ++j) { |
| 48 if (test_output_block[j] < 0) | 93 if (test_output_block[j] < 0) |
| 49 ++count_sign_block[j][0]; | 94 ++count_sign_block[j][0]; |
| 50 else if (test_output_block[j] > 0) | 95 else if (test_output_block[j] > 0) |
| 51 ++count_sign_block[j][1]; | 96 ++count_sign_block[j][1]; |
| 52 } | 97 } |
| 53 } | 98 } |
| 54 | 99 |
| 55 for (int j = 0; j < 16; ++j) { | 100 for (int j = 0; j < 16; ++j) { |
| 56 const bool bias_acceptable = (abs(count_sign_block[j][0] - | 101 const bool bias_acceptable = (abs(count_sign_block[j][0] - |
| 57 count_sign_block[j][1]) < 10000); | 102 count_sign_block[j][1]) < 10000); |
| 58 EXPECT_TRUE(bias_acceptable) | 103 EXPECT_TRUE(bias_acceptable) |
| 59 << "Error: 4x4 FDCT has a sign bias > 1%" | 104 << "Error: 4x4 FDCT/FHT has a sign bias > 1%" |
| 60 << " for input range [-255, 255] at index " << j; | 105 << " for input range [-255, 255] at index " << j |
| 106 << " tx_type " << tx_type; |
| 61 } | 107 } |
| 62 | 108 |
| 63 memset(count_sign_block, 0, sizeof(count_sign_block)); | 109 memset(count_sign_block, 0, sizeof(count_sign_block)); |
| 64 | |
| 65 for (int i = 0; i < count_test_block; ++i) { | 110 for (int i = 0; i < count_test_block; ++i) { |
| 66 // Initialize a test block with input range [-15, 15]. | 111 // Initialize a test block with input range [-15, 15]. |
| 67 for (int j = 0; j < 16; ++j) | 112 for (int j = 0; j < 16; ++j) |
| 68 test_input_block[j] = (rnd.Rand8() >> 4) - (rnd.Rand8() >> 4); | 113 test_input_block[j] = (rnd.Rand8() >> 4) - (rnd.Rand8() >> 4); |
| 69 | 114 |
| 70 // TODO(Yaowu): this should be converted to a parameterized test | 115 RunFwdTxfm(test_input_block, test_output_block, NULL, pitch, tx_type); |
| 71 // to test optimized versions of this function. | |
| 72 vp9_short_fdct4x4_c(test_input_block, test_output_block, pitch); | |
| 73 | 116 |
| 74 for (int j = 0; j < 16; ++j) { | 117 for (int j = 0; j < 16; ++j) { |
| 75 if (test_output_block[j] < 0) | 118 if (test_output_block[j] < 0) |
| 76 ++count_sign_block[j][0]; | 119 ++count_sign_block[j][0]; |
| 77 else if (test_output_block[j] > 0) | 120 else if (test_output_block[j] > 0) |
| 78 ++count_sign_block[j][1]; | 121 ++count_sign_block[j][1]; |
| 79 } | 122 } |
| 80 } | 123 } |
| 81 | 124 |
| 82 for (int j = 0; j < 16; ++j) { | 125 for (int j = 0; j < 16; ++j) { |
| 83 const bool bias_acceptable = (abs(count_sign_block[j][0] - | 126 const bool bias_acceptable = (abs(count_sign_block[j][0] - |
| 84 count_sign_block[j][1]) < 100000); | 127 count_sign_block[j][1]) < 100000); |
| 85 EXPECT_TRUE(bias_acceptable) | 128 EXPECT_TRUE(bias_acceptable) |
| 86 << "Error: 4x4 FDCT has a sign bias > 10%" | 129 << "Error: 4x4 FDCT/FHT has a sign bias > 10%" |
| 87 << " for input range [-15, 15] at index " << j; | 130 << " for input range [-15, 15] at index " << j; |
| 88 } | 131 } |
| 89 }; | 132 } |
| 90 | 133 |
| 91 TEST(Vp9Fdct4x4Test, RoundTripErrorCheck) { | 134 TEST_P(FwdTrans4x4Test, RoundTripErrorCheck) { |
| 92 ACMRandom rnd(ACMRandom::DeterministicSeed()); | 135 ACMRandom rnd(ACMRandom::DeterministicSeed()); |
| 136 |
| 93 int max_error = 0; | 137 int max_error = 0; |
| 94 double total_error = 0; | 138 double total_error = 0; |
| 95 const int count_test_block = 1000000; | 139 const int count_test_block = 1000000; |
| 96 for (int i = 0; i < count_test_block; ++i) { | 140 for (int i = 0; i < count_test_block; ++i) { |
| 97 int16_t test_input_block[16]; | 141 int16_t test_input_block[16]; |
| 98 int16_t test_temp_block[16]; | 142 int16_t test_temp_block[16]; |
| 99 uint8_t dst[16], src[16]; | 143 uint8_t dst[16], src[16]; |
| 100 | 144 |
| 101 for (int j = 0; j < 16; ++j) { | 145 for (int j = 0; j < 16; ++j) { |
| 102 src[j] = rnd.Rand8(); | 146 src[j] = rnd.Rand8(); |
| 103 dst[j] = rnd.Rand8(); | 147 dst[j] = rnd.Rand8(); |
| 104 } | 148 } |
| 105 // Initialize a test block with input range [-255, 255]. | 149 // Initialize a test block with input range [-255, 255]. |
| 106 for (int j = 0; j < 16; ++j) | 150 for (int j = 0; j < 16; ++j) |
| 107 test_input_block[j] = src[j] - dst[j]; | 151 test_input_block[j] = src[j] - dst[j]; |
| 108 | 152 |
| 109 // TODO(Yaowu): this should be converted to a parameterized test | |
| 110 // to test optimized versions of this function. | |
| 111 const int pitch = 8; | 153 const int pitch = 8; |
| 112 vp9_short_fdct4x4_c(test_input_block, test_temp_block, pitch); | 154 RunFwdTxfm(test_input_block, test_temp_block, dst, pitch, tx_type); |
| 113 | 155 |
| 114 for (int j = 0; j < 16; ++j) { | 156 for (int j = 0; j < 16; ++j) { |
| 115 if(test_temp_block[j] > 0) { | 157 if(test_temp_block[j] > 0) { |
| 116 test_temp_block[j] += 2; | 158 test_temp_block[j] += 2; |
| 117 test_temp_block[j] /= 4; | 159 test_temp_block[j] /= 4; |
| 118 test_temp_block[j] *= 4; | 160 test_temp_block[j] *= 4; |
| 119 } else { | 161 } else { |
| 120 test_temp_block[j] -= 2; | 162 test_temp_block[j] -= 2; |
| 121 test_temp_block[j] /= 4; | 163 test_temp_block[j] /= 4; |
| 122 test_temp_block[j] *= 4; | 164 test_temp_block[j] *= 4; |
| 123 } | 165 } |
| 124 } | 166 } |
| 125 | 167 |
| 126 // Because the bitstream is not frozen yet, use the idct in the codebase. | 168 // inverse transform and reconstruct the pixel block |
| 127 vp9_short_idct4x4_add_c(test_temp_block, dst, 4); | 169 RunInvTxfm(test_input_block, test_temp_block, dst, pitch, tx_type); |
| 128 | 170 |
| 129 for (int j = 0; j < 16; ++j) { | 171 for (int j = 0; j < 16; ++j) { |
| 130 const int diff = dst[j] - src[j]; | 172 const int diff = dst[j] - src[j]; |
| 131 const int error = diff * diff; | 173 const int error = diff * diff; |
| 132 if (max_error < error) | 174 if (max_error < error) |
| 133 max_error = error; | 175 max_error = error; |
| 134 total_error += error; | 176 total_error += error; |
| 135 } | 177 } |
| 136 } | 178 } |
| 137 EXPECT_GE(1, max_error) | 179 EXPECT_GE(1, max_error) |
| 138 << "Error: FDCT/IDCT has an individual roundtrip error > 1"; | 180 << "Error: FDCT/IDCT or FHT/IHT has an individual roundtrip error > 1"; |
| 139 | 181 |
| 140 EXPECT_GE(count_test_block, total_error) | 182 EXPECT_GE(count_test_block, total_error) |
| 141 << "Error: FDCT/IDCT has average roundtrip error > 1 per block"; | 183 << "Error: FDCT/IDCT or FHT/IHT has average " |
| 142 }; | 184 "roundtrip error > 1 per block"; |
| 185 } |
| 143 | 186 |
| 187 INSTANTIATE_TEST_CASE_P(VP9, FwdTrans4x4Test, ::testing::Range(0, 4)); |
| 144 } // namespace | 188 } // namespace |
| OLD | NEW |