2 * Copyright (c) 2014 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.
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"
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"
31 const int kNumBlocks = 25;
32 const int kNumBlockEntries = 16;
34 typedef void (*VP8Quantize)(BLOCK *b, BLOCKD *d);
36 typedef std::tr1::tuple<VP8Quantize, VP8Quantize> VP8QuantizeParam;
38 using libvpx_test::ACMRandom;
39 using std::tr1::make_tuple;
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 {
45 virtual ~QuantizeTestBase() {
46 vp8_remove_compressor(&vp8_comp_);
48 vpx_free(macroblockd_dst_);
49 macroblockd_dst_ = NULL;
50 libvpx_test::ClearSystemState();
54 void SetupCompressor() {
55 rnd_.Reset(ACMRandom::DeterministicSeed());
57 // The full configuration is necessary to generate the quantization tables.
58 VP8_CONFIG vp8_config;
59 vpx_memset(&vp8_config, 0, sizeof(vp8_config));
61 vp8_comp_ = vp8_create_compressor(&vp8_config);
63 // Set the tables based on a quantizer of 0.
64 vp8_set_quantizer(vp8_comp_, 0);
66 // Set up all the block/blockd pointers for the mb in vp8_comp_.
67 vp8cx_frame_init_quantizer(vp8_comp_);
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 memcpy(macroblockd_dst_, &vp8_comp_->mb.e_mbd, sizeof(*macroblockd_dst_));
73 // Fix block pointers - currently they point to the blocks in the reference
75 vp8_setup_block_dptrs(macroblockd_dst_);
78 void UpdateQuantizer(int q) {
79 vp8_set_quantizer(vp8_comp_, q);
81 memcpy(macroblockd_dst_, &vp8_comp_->mb.e_mbd, sizeof(*macroblockd_dst_));
82 vp8_setup_block_dptrs(macroblockd_dst_);
85 void FillCoeffConstant(int16_t c) {
86 for (int i = 0; i < kNumBlocks * kNumBlockEntries; ++i) {
87 vp8_comp_->mb.coeff[i] = c;
91 void FillCoeffRandom() {
92 for (int i = 0; i < kNumBlocks * kNumBlockEntries; ++i) {
93 vp8_comp_->mb.coeff[i] = rnd_.Rand8();
98 EXPECT_EQ(0, memcmp(vp8_comp_->mb.e_mbd.qcoeff, macroblockd_dst_->qcoeff,
99 sizeof(*macroblockd_dst_->qcoeff) * kNumBlocks *
101 << "qcoeff mismatch";
102 EXPECT_EQ(0, memcmp(vp8_comp_->mb.e_mbd.dqcoeff, macroblockd_dst_->dqcoeff,
103 sizeof(*macroblockd_dst_->dqcoeff) * kNumBlocks *
105 << "dqcoeff mismatch";
106 EXPECT_EQ(0, memcmp(vp8_comp_->mb.e_mbd.eobs, macroblockd_dst_->eobs,
107 sizeof(*macroblockd_dst_->eobs) * kNumBlocks))
112 MACROBLOCKD *macroblockd_dst_;
118 class QuantizeTest : public QuantizeTestBase,
119 public ::testing::TestWithParam<VP8QuantizeParam> {
121 virtual void SetUp() {
123 asm_quant_ = GET_PARAM(0);
124 c_quant_ = GET_PARAM(1);
127 void RunComparison() {
128 for (int i = 0; i < kNumBlocks; ++i) {
129 ASM_REGISTER_STATE_CHECK(
130 c_quant_(&vp8_comp_->mb.block[i], &vp8_comp_->mb.e_mbd.block[i]));
131 ASM_REGISTER_STATE_CHECK(
132 asm_quant_(&vp8_comp_->mb.block[i], ¯oblockd_dst_->block[i]));
139 VP8Quantize asm_quant_;
140 VP8Quantize c_quant_;
143 TEST_P(QuantizeTest, TestZeroInput) {
144 FillCoeffConstant(0);
148 TEST_P(QuantizeTest, TestLargeNegativeInput) {
149 FillCoeffConstant(0);
150 // Generate a qcoeff which contains 512/-512 (0x0100/0xFE00) to catch issues
151 // like BUG=883 where the constant being compared was incorrectly initialized.
152 vp8_comp_->mb.coeff[0] = -8191;
156 TEST_P(QuantizeTest, TestRandomInput) {
161 TEST_P(QuantizeTest, TestMultipleQ) {
162 for (int q = 0; q < QINDEX_RANGE; ++q) {
170 INSTANTIATE_TEST_CASE_P(
173 make_tuple(&vp8_fast_quantize_b_sse2, &vp8_fast_quantize_b_c),
174 make_tuple(&vp8_regular_quantize_b_sse2, &vp8_regular_quantize_b_c)));
178 INSTANTIATE_TEST_CASE_P(SSSE3, QuantizeTest,
179 ::testing::Values(make_tuple(&vp8_fast_quantize_b_ssse3,
180 &vp8_fast_quantize_b_c)));
184 INSTANTIATE_TEST_CASE_P(
185 SSE4_1, QuantizeTest,
186 ::testing::Values(make_tuple(&vp8_regular_quantize_b_sse4_1,
187 &vp8_regular_quantize_b_c)));
188 #endif // HAVE_SSE4_1
191 INSTANTIATE_TEST_CASE_P(NEON, QuantizeTest,
192 ::testing::Values(make_tuple(&vp8_fast_quantize_b_neon,
193 &vp8_fast_quantize_b_c)));