OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2014 The WebM project authors. All Rights Reserved. |
| 3 * |
| 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. |
| 9 */ |
| 10 |
| 11 #include <string.h> |
| 12 |
| 13 #include "third_party/googletest/src/include/gtest/gtest.h" |
| 14 #include "test/acm_random.h" |
| 15 #include "test/clear_system_state.h" |
| 16 #include "test/register_state_check.h" |
| 17 #include "test/util.h" |
| 18 |
| 19 #include "./vpx_config.h" |
| 20 #include "./vp8_rtcd.h" |
| 21 #include "vp8/common/blockd.h" |
| 22 #include "vp8/common/onyx.h" |
| 23 #include "vp8/encoder/block.h" |
| 24 #include "vp8/encoder/onyx_int.h" |
| 25 #include "vp8/encoder/quantize.h" |
| 26 #include "vpx/vpx_integer.h" |
| 27 #include "vpx_mem/vpx_mem.h" |
| 28 |
| 29 namespace { |
| 30 |
| 31 const int kNumBlocks = 25; |
| 32 const int kNumBlockEntries = 16; |
| 33 |
| 34 typedef void (*VP8Quantize)(BLOCK *b, BLOCKD *d); |
| 35 |
| 36 typedef std::tr1::tuple<VP8Quantize, VP8Quantize> VP8QuantizeParam; |
| 37 |
| 38 using libvpx_test::ACMRandom; |
| 39 using std::tr1::make_tuple; |
| 40 |
| 41 // Create and populate a VP8_COMP instance which has a complete set of |
| 42 // quantization inputs as well as a second MACROBLOCKD for output. |
| 43 class QuantizeTestBase { |
| 44 public: |
| 45 virtual ~QuantizeTestBase() { |
| 46 vp8_remove_compressor(&vp8_comp_); |
| 47 vp8_comp_ = NULL; |
| 48 vpx_free(macroblockd_dst_); |
| 49 macroblockd_dst_ = NULL; |
| 50 libvpx_test::ClearSystemState(); |
| 51 } |
| 52 |
| 53 protected: |
| 54 void SetupCompressor() { |
| 55 rnd_.Reset(ACMRandom::DeterministicSeed()); |
| 56 |
| 57 // The full configuration is necessary to generate the quantization tables. |
| 58 VP8_CONFIG *const vp8_config = |
| 59 reinterpret_cast<VP8_CONFIG *>(vpx_calloc(sizeof(*vp8_config), 1)); |
| 60 |
| 61 vp8_comp_ = vp8_create_compressor(vp8_config); |
| 62 |
| 63 // Set the tables based on a quantizer of 0. |
| 64 vp8_set_quantizer(vp8_comp_, 0); |
| 65 |
| 66 // Set up all the block/blockd pointers for the mb in vp8_comp_. |
| 67 vp8cx_frame_init_quantizer(vp8_comp_); |
| 68 |
| 69 // Copy macroblockd from the reference to get pre-set-up dequant values. |
| 70 macroblockd_dst_ = reinterpret_cast<MACROBLOCKD *>( |
| 71 vpx_memalign(32, sizeof(*macroblockd_dst_))); |
| 72 vpx_memcpy(macroblockd_dst_, &vp8_comp_->mb.e_mbd, |
| 73 sizeof(*macroblockd_dst_)); |
| 74 // Fix block pointers - currently they point to the blocks in the reference |
| 75 // structure. |
| 76 vp8_setup_block_dptrs(macroblockd_dst_); |
| 77 } |
| 78 |
| 79 void UpdateQuantizer(int q) { |
| 80 vp8_set_quantizer(vp8_comp_, q); |
| 81 |
| 82 vpx_memcpy(macroblockd_dst_, &vp8_comp_->mb.e_mbd, |
| 83 sizeof(*macroblockd_dst_)); |
| 84 vp8_setup_block_dptrs(macroblockd_dst_); |
| 85 } |
| 86 |
| 87 void FillCoeffConstant(int16_t c) { |
| 88 for (int i = 0; i < kNumBlocks * kNumBlockEntries; ++i) { |
| 89 vp8_comp_->mb.coeff[i] = c; |
| 90 } |
| 91 } |
| 92 |
| 93 void FillCoeffRandom() { |
| 94 for (int i = 0; i < kNumBlocks * kNumBlockEntries; ++i) { |
| 95 vp8_comp_->mb.coeff[i] = rnd_.Rand8(); |
| 96 } |
| 97 } |
| 98 |
| 99 void CheckOutput() { |
| 100 EXPECT_EQ(0, memcmp(vp8_comp_->mb.e_mbd.qcoeff, macroblockd_dst_->qcoeff, |
| 101 sizeof(*macroblockd_dst_->qcoeff) * kNumBlocks * |
| 102 kNumBlockEntries)) |
| 103 << "qcoeff mismatch"; |
| 104 EXPECT_EQ(0, memcmp(vp8_comp_->mb.e_mbd.dqcoeff, macroblockd_dst_->dqcoeff, |
| 105 sizeof(*macroblockd_dst_->dqcoeff) * kNumBlocks * |
| 106 kNumBlockEntries)) |
| 107 << "dqcoeff mismatch"; |
| 108 EXPECT_EQ(0, memcmp(vp8_comp_->mb.e_mbd.eobs, macroblockd_dst_->eobs, |
| 109 sizeof(*macroblockd_dst_->eobs) * kNumBlocks)) |
| 110 << "eobs mismatch"; |
| 111 } |
| 112 |
| 113 VP8_COMP *vp8_comp_; |
| 114 MACROBLOCKD *macroblockd_dst_; |
| 115 |
| 116 private: |
| 117 ACMRandom rnd_; |
| 118 }; |
| 119 |
| 120 class QuantizeTest : public QuantizeTestBase, |
| 121 public ::testing::TestWithParam<VP8QuantizeParam> { |
| 122 protected: |
| 123 virtual void SetUp() { |
| 124 SetupCompressor(); |
| 125 asm_quant_ = GET_PARAM(0); |
| 126 c_quant_ = GET_PARAM(1); |
| 127 } |
| 128 |
| 129 void RunComparison() { |
| 130 for (int i = 0; i < kNumBlocks; ++i) { |
| 131 ASM_REGISTER_STATE_CHECK( |
| 132 c_quant_(&vp8_comp_->mb.block[i], &vp8_comp_->mb.e_mbd.block[i])); |
| 133 ASM_REGISTER_STATE_CHECK( |
| 134 asm_quant_(&vp8_comp_->mb.block[i], ¯oblockd_dst_->block[i])); |
| 135 } |
| 136 |
| 137 CheckOutput(); |
| 138 } |
| 139 |
| 140 private: |
| 141 VP8Quantize asm_quant_; |
| 142 VP8Quantize c_quant_; |
| 143 }; |
| 144 |
| 145 TEST_P(QuantizeTest, TestZeroInput) { |
| 146 FillCoeffConstant(0); |
| 147 RunComparison(); |
| 148 } |
| 149 |
| 150 TEST_P(QuantizeTest, TestLargeNegativeInput) { |
| 151 FillCoeffConstant(0); |
| 152 // Generate a qcoeff which contains 512/-512 (0x0100/0xFE00) to catch issues |
| 153 // like BUG=883 where the constant being compared was incorrectly initialized. |
| 154 vp8_comp_->mb.coeff[0] = -8191; |
| 155 RunComparison(); |
| 156 } |
| 157 |
| 158 TEST_P(QuantizeTest, TestRandomInput) { |
| 159 FillCoeffRandom(); |
| 160 RunComparison(); |
| 161 } |
| 162 |
| 163 TEST_P(QuantizeTest, TestMultipleQ) { |
| 164 for (int q = 0; q < QINDEX_RANGE; ++q) { |
| 165 UpdateQuantizer(q); |
| 166 FillCoeffRandom(); |
| 167 RunComparison(); |
| 168 } |
| 169 } |
| 170 |
| 171 #if HAVE_SSE2 |
| 172 INSTANTIATE_TEST_CASE_P( |
| 173 SSE2, QuantizeTest, |
| 174 ::testing::Values( |
| 175 make_tuple(&vp8_fast_quantize_b_sse2, &vp8_fast_quantize_b_c), |
| 176 make_tuple(&vp8_regular_quantize_b_sse2, &vp8_regular_quantize_b_c))); |
| 177 #endif // HAVE_SSE2 |
| 178 |
| 179 #if HAVE_SSSE3 |
| 180 INSTANTIATE_TEST_CASE_P(SSSE3, QuantizeTest, |
| 181 ::testing::Values(make_tuple(&vp8_fast_quantize_b_ssse3, |
| 182 &vp8_fast_quantize_b_c))); |
| 183 #endif // HAVE_SSSE3 |
| 184 |
| 185 #if HAVE_SSE4_1 |
| 186 INSTANTIATE_TEST_CASE_P( |
| 187 SSE4_1, QuantizeTest, |
| 188 ::testing::Values(make_tuple(&vp8_regular_quantize_b_sse4_1, |
| 189 &vp8_regular_quantize_b_c))); |
| 190 #endif // HAVE_SSE4_1 |
| 191 |
| 192 #if HAVE_NEON |
| 193 INSTANTIATE_TEST_CASE_P(NEON, QuantizeTest, |
| 194 ::testing::Values(make_tuple(&vp8_fast_quantize_b_neon, |
| 195 &vp8_fast_quantize_b_c))); |
| 196 #endif // HAVE_NEON |
| 197 } // namespace |
OLD | NEW |